Merge pull request #1427 from citusdata/fix_version_checks

Fix version checks
pull/1429/head
Marco Slot 2017-05-24 19:04:26 +02:00 committed by GitHub
commit 1910a93b9a
5 changed files with 56 additions and 15 deletions

View File

@ -1419,11 +1419,9 @@ ErrorIfUnstableCreateOrAlterExtensionStmt(Node *parsetree)
{
/*
* No version was specified, so PostgreSQL will use the default_version
* from the citus.control file. In case a new default is available, we
* will force a compatibility check of the latest available version.
* from the citus.control file.
*/
citusVersionKnownCompatible = false;
CheckCitusVersion(ERROR);
CheckAvailableVersion(ERROR);
}
}

View File

@ -106,7 +106,7 @@ static Oid workerHashFunctionId = InvalidOid;
/* Citus extension version variables */
bool EnableVersionChecks = true; /* version checks are enabled */
bool citusVersionKnownCompatible = false;
static bool citusVersionKnownCompatible = false;
/* Hash table for informations about each partition */
static HTAB *DistTableCacheHash = NULL;
@ -143,7 +143,6 @@ static bool HasUniformHashDistribution(ShardInterval **shardIntervalArray,
static bool HasUninitializedShardInterval(ShardInterval **sortedShardIntervalArray,
int shardCount);
static bool CheckInstalledVersion(int elevel);
static bool CheckAvailableVersion(int elevel);
static char * AvailableExtensionVersion(void);
static char * InstalledExtensionVersion(void);
static bool HasOverlappingShardInterval(ShardInterval **shardIntervalArray,
@ -512,6 +511,11 @@ LookupDistTableCacheEntry(Oid relationId)
return NULL;
}
if (DistTableCacheHash == NULL)
{
InitializeDistTableCache();
}
/*
* If the version is not known to be compatible, perform thorough check,
* unless such checks are disabled.
@ -539,11 +543,6 @@ LookupDistTableCacheEntry(Oid relationId)
}
}
if (DistTableCacheHash == NULL)
{
InitializeDistTableCache();
}
cacheEntry = hash_search(DistTableCacheHash, hashKey, HASH_ENTER, &foundInCache);
/* return valid matches */
@ -1181,13 +1180,15 @@ CheckCitusVersion(int elevel)
* this function logs an error with the specified elevel and returns false,
* otherwise it returns true.
*/
static bool
bool
CheckAvailableVersion(int elevel)
{
char *availableVersion = NULL;
Assert(CitusHasBeenLoaded());
Assert(EnableVersionChecks);
if (!EnableVersionChecks)
{
return true;
}
availableVersion = AvailableExtensionVersion();

View File

@ -18,7 +18,6 @@
#include "utils/hsearch.h"
extern bool EnableVersionChecks;
extern bool citusVersionKnownCompatible;
/*
* Representation of a table's metadata that is frequently used for
@ -80,6 +79,7 @@ extern void CitusInvalidateRelcacheByShardId(int64 shardId);
extern bool CitusHasBeenLoaded(void);
extern bool CheckCitusVersion(int elevel);
extern bool CheckAvailableVersion(int elevel);
bool MajorVersionsCompatible(char *leftVersion, char *rightVersion);
/* access WorkerNodeHash */

View File

@ -169,7 +169,31 @@ SET citus.enable_version_checks TO 'true';
DROP FUNCTION citus_table_size(regclass);
SET citus.enable_version_checks TO 'false';
ALTER EXTENSION citus UPDATE TO '6.2-2';
-- Test updating to the latest version without specifying the version number
ALTER EXTENSION citus UPDATE;
-- re-create in newest version
DROP EXTENSION citus;
\c
CREATE EXTENSION citus;
-- test cache invalidation in workers
\c - - - :worker_1_port
-- this will initialize the cache
\d
List of relations
Schema | Name | Type | Owner
--------+------+------+-------
(0 rows)
DROP EXTENSION citus;
SET citus.enable_version_checks TO 'false';
CREATE EXTENSION citus VERSION '5.2-4';
SET citus.enable_version_checks TO 'true';
-- during ALTER EXTENSION, we should invalidate the cache
ALTER EXTENSION citus UPDATE;
-- if cache is invalidated succesfull, this \d should work without any problem
\d
List of relations
Schema | Name | Type | Owner
--------+------+------+-------
(0 rows)

View File

@ -153,7 +153,25 @@ DROP FUNCTION citus_table_size(regclass);
SET citus.enable_version_checks TO 'false';
ALTER EXTENSION citus UPDATE TO '6.2-2';
-- Test updating to the latest version without specifying the version number
ALTER EXTENSION citus UPDATE;
-- re-create in newest version
DROP EXTENSION citus;
\c
CREATE EXTENSION citus;
-- test cache invalidation in workers
\c - - - :worker_1_port
-- this will initialize the cache
\d
DROP EXTENSION citus;
SET citus.enable_version_checks TO 'false';
CREATE EXTENSION citus VERSION '5.2-4';
SET citus.enable_version_checks TO 'true';
-- during ALTER EXTENSION, we should invalidate the cache
ALTER EXTENSION citus UPDATE;
-- if cache is invalidated succesfull, this \d should work without any problem
\d