Call FlushDistTableCache() before stats collection.

pull/1751/head
Hadi Moshayedi 2017-10-31 21:22:11 -04:00 committed by Hadi Moshayedi
parent c18c6625d9
commit 34f3ec0961
3 changed files with 41 additions and 7 deletions

View File

@ -318,6 +318,7 @@ CitusMaintenanceDaemonMain(Datum main_arg)
} }
else if (CheckCitusVersion(DEBUG1) && CitusHasBeenLoaded()) else if (CheckCitusVersion(DEBUG1) && CitusHasBeenLoaded())
{ {
FlushDistTableCache();
WarnIfSyncDNS(); WarnIfSyncDNS();
statsCollectionSuccess = CollectBasicUsageStatistics(); statsCollectionSuccess = CollectBasicUsageStatistics();
} }

View File

@ -177,6 +177,7 @@ static void RegisterWorkerNodeCacheCallbacks(void);
static void RegisterLocalGroupIdCacheCallbacks(void); static void RegisterLocalGroupIdCacheCallbacks(void);
static uint32 WorkerNodeHashCode(const void *key, Size keySize); static uint32 WorkerNodeHashCode(const void *key, Size keySize);
static void ResetDistTableCacheEntry(DistTableCacheEntry *cacheEntry); static void ResetDistTableCacheEntry(DistTableCacheEntry *cacheEntry);
static void CreateDistTableCache(void);
static void InvalidateDistRelationCacheCallback(Datum argument, Oid relationId); static void InvalidateDistRelationCacheCallback(Datum argument, Oid relationId);
static void InvalidateNodeRelationCacheCallback(Datum argument, Oid relationId); static void InvalidateNodeRelationCacheCallback(Datum argument, Oid relationId);
static void InvalidateLocalGroupIdRelationCacheCallback(Datum argument, Oid relationId); static void InvalidateLocalGroupIdRelationCacheCallback(Datum argument, Oid relationId);
@ -2345,13 +2346,7 @@ InitializeDistTableCache(void)
DistShardScanKey[0].sk_attno = Anum_pg_dist_shard_logicalrelid; DistShardScanKey[0].sk_attno = Anum_pg_dist_shard_logicalrelid;
/* initialize the per-table hash table */ /* initialize the per-table hash table */
MemSet(&info, 0, sizeof(info)); CreateDistTableCache();
info.keysize = sizeof(Oid);
info.entrysize = sizeof(DistTableCacheEntry);
info.hash = tag_hash;
DistTableCacheHash =
hash_create("Distributed Relation Cache", 32, &info,
HASH_ELEM | HASH_FUNCTION);
/* initialize the per-shard hash table */ /* initialize the per-shard hash table */
MemSet(&info, 0, sizeof(info)); MemSet(&info, 0, sizeof(info));
@ -2731,6 +2726,43 @@ InvalidateDistRelationCacheCallback(Datum argument, Oid relationId)
} }
/*
* FlushDistTableCache flushes the entire distributed relation cache, frees
* all entries, and recreates the cache.
*/
void
FlushDistTableCache(void)
{
DistTableCacheEntry *cacheEntry = NULL;
HASH_SEQ_STATUS status;
hash_seq_init(&status, DistTableCacheHash);
while ((cacheEntry = (DistTableCacheEntry *) hash_seq_search(&status)) != NULL)
{
ResetDistTableCacheEntry(cacheEntry);
}
hash_destroy(DistTableCacheHash);
CreateDistTableCache();
}
/* CreateDistTableCache initializes the per-table hash table */
static void
CreateDistTableCache(void)
{
HASHCTL info;
MemSet(&info, 0, sizeof(info));
info.keysize = sizeof(Oid);
info.entrysize = sizeof(DistTableCacheEntry);
info.hash = tag_hash;
DistTableCacheHash =
hash_create("Distributed Relation Cache", 32, &info,
HASH_ELEM | HASH_FUNCTION);
}
/* /*
* InvalidateMetadataSystemCache resets all the cached OIDs and the extensionLoaded flag, * InvalidateMetadataSystemCache resets all the cached OIDs and the extensionLoaded flag,
* and invalidates the worker node and local group ID caches. * and invalidates the worker node and local group ID caches.

View File

@ -86,6 +86,7 @@ extern List * DistTableOidList(void);
extern List * ShardPlacementList(uint64 shardId); extern List * ShardPlacementList(uint64 shardId);
extern void CitusInvalidateRelcacheByRelid(Oid relationId); extern void CitusInvalidateRelcacheByRelid(Oid relationId);
extern void CitusInvalidateRelcacheByShardId(int64 shardId); extern void CitusInvalidateRelcacheByShardId(int64 shardId);
extern void FlushDistTableCache(void);
extern void InvalidateMetadataSystemCache(void); extern void InvalidateMetadataSystemCache(void);
extern Datum DistNodeMetadata(void); extern Datum DistNodeMetadata(void);