Return early in CitusHasBeenLoaded when creating a different ex… (#3178)

Return early in CitusHasBeenLoaded when creating a different extension
pull/3162/head
Marco Slot 2019-11-18 22:10:43 +01:00 committed by GitHub
commit 18843af688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 42 deletions

View File

@ -270,6 +270,12 @@ master_drop_sequences(PG_FUNCTION_ARGS)
bool isNull = false; bool isNull = false;
StringInfo dropSeqCommand = makeStringInfo(); StringInfo dropSeqCommand = makeStringInfo();
if (!CitusHasBeenLoaded())
{
/* ignore calls during CREATE EXTENSION citus */
PG_RETURN_VOID();
}
CheckCitusVersion(ERROR); CheckCitusVersion(ERROR);
/* /*

View File

@ -202,6 +202,7 @@ static char * InstalledExtensionVersion(void);
static bool HasOverlappingShardInterval(ShardInterval **shardIntervalArray, static bool HasOverlappingShardInterval(ShardInterval **shardIntervalArray,
int shardIntervalArrayLength, int shardIntervalArrayLength,
FmgrInfo *shardIntervalSortCompareFunction); FmgrInfo *shardIntervalSortCompareFunction);
static bool CitusHasBeenLoadedInternal(void);
static void InitializeCaches(void); static void InitializeCaches(void);
static void InitializeDistCache(void); static void InitializeDistCache(void);
static void InitializeDistObjectCache(void); static void InitializeDistObjectCache(void);
@ -1528,41 +1529,27 @@ HasOverlappingShardInterval(ShardInterval **shardIntervalArray,
bool bool
CitusHasBeenLoaded(void) CitusHasBeenLoaded(void)
{ {
/* recheck presence until citus has been loaded */
if (!MetadataCache.extensionLoaded || creating_extension) if (!MetadataCache.extensionLoaded || creating_extension)
{ {
bool extensionPresent = false; /*
bool extensionScriptExecuted = true; * Refresh if we have not determined whether the extension has been
* loaded yet, or in case of ALTER EXTENSION since we want to treat
* Citus as "not loaded" during ALTER EXTENSION citus.
*/
bool extensionLoaded = CitusHasBeenLoadedInternal();
Oid extensionOid = get_extension_oid("citus", true); if (extensionLoaded && !MetadataCache.extensionLoaded)
if (extensionOid != InvalidOid)
{ {
extensionPresent = true; /*
} * Loaded Citus for the first time in this session, or first time after
* CREATE/ALTER EXTENSION citus. Do some initialisation.
if (extensionPresent) */
{
/* check if Citus extension objects are still being created */
if (creating_extension && CurrentExtensionObject == extensionOid)
{
extensionScriptExecuted = false;
}
/* /*
* Whenever the extension exists, even when currently creating it, * Make sure the maintenance daemon is running if it was not already.
* we need the infrastructure to run citus in this database to be
* ready.
*/ */
StartupCitusBackend(); StartupCitusBackend();
}
/* we disable extension features during pg_upgrade */
MetadataCache.extensionLoaded = extensionPresent &&
extensionScriptExecuted &&
!IsBinaryUpgrade;
if (MetadataCache.extensionLoaded)
{
/* /*
* InvalidateDistRelationCacheCallback resets state such as extensionLoaded * InvalidateDistRelationCacheCallback resets state such as extensionLoaded
* when it notices changes to pg_dist_partition (which usually indicate * when it notices changes to pg_dist_partition (which usually indicate
@ -1576,26 +1563,58 @@ CitusHasBeenLoaded(void)
*/ */
DistPartitionRelationId(); DistPartitionRelationId();
/* /*
* This needs to be initialized so we can receive foreign relation graph * This needs to be initialized so we can receive foreign relation graph
* invalidation messages in InvalidateForeignRelationGraphCacheCallback(). * invalidation messages in InvalidateForeignRelationGraphCacheCallback().
* See the comments of InvalidateForeignKeyGraph for more context. * See the comments of InvalidateForeignKeyGraph for more context.
*/ */
DistColocationRelationId(); DistColocationRelationId();
/*
* We also reset citusVersionKnownCompatible, so it will be re-read in
* case of extension update.
*/
citusVersionKnownCompatible = false;
} }
MetadataCache.extensionLoaded = extensionLoaded;
} }
return MetadataCache.extensionLoaded; return MetadataCache.extensionLoaded;
} }
/*
* CitusHasBeenLoadedInternal returns true if the citus extension has been created
* in the current database and the extension script has been executed. Otherwise,
* it returns false.
*/
static bool
CitusHasBeenLoadedInternal(void)
{
Oid citusExtensionOid = InvalidOid;
if (IsBinaryUpgrade)
{
/* never use Citus logic during pg_upgrade */
return false;
}
citusExtensionOid = get_extension_oid("citus", true);
if (citusExtensionOid == InvalidOid)
{
/* Citus extension does not exist yet */
return false;
}
if (creating_extension && CurrentExtensionObject == citusExtensionOid)
{
/*
* We do not use Citus hooks during CREATE/ALTER EXTENSION citus
* since the objects used by the C code might be not be there yet.
*/
return false;
}
/* citus extension exists and has been created */
return true;
}
/* /*
* CheckCitusVersion checks whether there is a version mismatch between the * CheckCitusVersion checks whether there is a version mismatch between the
* available version and the loaded version or between the installed version * available version and the loaded version or between the installed version

View File

@ -29,11 +29,11 @@ step detector-dump-wait-edges:
waiting_transaction_numblocking_transaction_numblocking_transaction_waiting waiting_transaction_numblocking_transaction_numblocking_transaction_waiting
290 289 f 289 288 f
transactionnumberwaitingtransactionnumbers transactionnumberwaitingtransactionnumbers
289 288
290 289 289 288
step s1-abort: step s1-abort:
ABORT; ABORT;
@ -77,14 +77,14 @@ step detector-dump-wait-edges:
waiting_transaction_numblocking_transaction_numblocking_transaction_waiting waiting_transaction_numblocking_transaction_numblocking_transaction_waiting
294 293 f 293 292 f
295 293 f 294 292 f
295 294 t 294 293 t
transactionnumberwaitingtransactionnumbers transactionnumberwaitingtransactionnumbers
293 292
294 293 293 292
295 293,294 294 292,293
step s1-abort: step s1-abort:
ABORT; ABORT;