mirror of https://github.com/citusdata/citus.git
Accept invalidation messages before accessing the metadata cache
This commit is crucial to prevent stale metadata reads from the cache. Without this commit, some of the operations may use stale metadata which could end up with various bugs such as crashes, inconsistent/lost data etc. As an example, consider that a COPY operation is blocked on shard metadata lock. Another concurrent session updates the metadata and invalidates the cache. However, since Citus doesn't accept invalidations, COPY continues with the stale metadata once it acquires the lock. With this commit, we make sure that invalidation messages are accepted just before accessing the metadata cache and preventing any operation to use stale metadata.pull/1406/head
parent
94151c9aef
commit
88ddde79f2
|
@ -385,7 +385,15 @@ LookupShardCacheEntry(int64 shardId)
|
|||
|
||||
recheck = true;
|
||||
}
|
||||
else if (!shardEntry->tableEntry->isValid)
|
||||
else
|
||||
{
|
||||
/*
|
||||
* We might have some concurrent metadata changes. In order to get the changes,
|
||||
* we first need to accept the cache invalidation messages.
|
||||
*/
|
||||
AcceptInvalidationMessages();
|
||||
|
||||
if (!shardEntry->tableEntry->isValid)
|
||||
{
|
||||
/*
|
||||
* The cache entry might not be valid right now. Reload cache entry
|
||||
|
@ -394,6 +402,7 @@ LookupShardCacheEntry(int64 shardId)
|
|||
LookupDistTableCacheEntry(shardEntry->tableEntry->relationId);
|
||||
recheck = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If we (re-)loaded the table cache, re-search the shard cache - the
|
||||
|
@ -472,6 +481,12 @@ LookupDistTableCacheEntry(Oid relationId)
|
|||
/* return valid matches */
|
||||
if (foundInCache)
|
||||
{
|
||||
/*
|
||||
* We might have some concurrent metadata changes. In order to get the changes,
|
||||
* we first need to accept the cache invalidation messages.
|
||||
*/
|
||||
AcceptInvalidationMessages();
|
||||
|
||||
if (cacheEntry->isValid)
|
||||
{
|
||||
return cacheEntry;
|
||||
|
@ -1927,6 +1942,12 @@ InitializeDistTableCache(void)
|
|||
HTAB *
|
||||
GetWorkerNodeHash(void)
|
||||
{
|
||||
/*
|
||||
* We might have some concurrent metadata changes. In order to get the changes,
|
||||
* we first need to accept the cache invalidation messages.
|
||||
*/
|
||||
AcceptInvalidationMessages();
|
||||
|
||||
if (!workerNodeHashValid)
|
||||
{
|
||||
InitializeWorkerNodeCache();
|
||||
|
|
Loading…
Reference in New Issue