diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-08-16 13:12:17 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-08-16 13:12:17 -0400 |
commit | bcc9b17bbf92d1d94581d5536770b9689a767c37 (patch) | |
tree | f20b430f92543db42c45cf352cb88803bbdc6102 /src/backend/utils/cache/inval.c | |
parent | 3c96f5c647852d1c77f9854cf1f78dfb01af8631 (diff) |
Fix race condition in relcache init file invalidation.
The previous code tried to synchronize by unlinking the init file twice,
but that doesn't actually work: it leaves a window wherein a third process
could read the already-stale init file but miss the SI messages that would
tell it the data is stale. The result would be bizarre failures in catalog
accesses, typically "could not read block 0 in file ..." later during
startup.
Instead, hold RelCacheInitLock across both the unlink and the sending of
the SI messages. This is more straightforward, and might even be a bit
faster since only one unlink call is needed.
This has been wrong since it was put in (in 2002!), so back-patch to all
supported releases.
Diffstat (limited to 'src/backend/utils/cache/inval.c')
-rw-r--r-- | src/backend/utils/cache/inval.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/utils/cache/inval.c b/src/backend/utils/cache/inval.c index 5fac924207d..29b9c19f0e1 100644 --- a/src/backend/utils/cache/inval.c +++ b/src/backend/utils/cache/inval.c @@ -840,10 +840,10 @@ inval_twophase_postcommit(TransactionId xid, uint16 info, SendSharedInvalidMessages(msg, 1); break; case TWOPHASE_INFO_FILE_BEFORE: - RelationCacheInitFileInvalidate(true); + RelationCacheInitFilePreInvalidate(); break; case TWOPHASE_INFO_FILE_AFTER: - RelationCacheInitFileInvalidate(false); + RelationCacheInitFilePostInvalidate(); break; default: Assert(false); @@ -890,7 +890,7 @@ AtEOXact_Inval(bool isCommit) * unless we committed. */ if (transInvalInfo->RelcacheInitFileInval) - RelationCacheInitFileInvalidate(true); + RelationCacheInitFilePreInvalidate(); AppendInvalidationMessages(&transInvalInfo->PriorCmdInvalidMsgs, &transInvalInfo->CurrentCmdInvalidMsgs); @@ -899,7 +899,7 @@ AtEOXact_Inval(bool isCommit) SendSharedInvalidMessages); if (transInvalInfo->RelcacheInitFileInval) - RelationCacheInitFileInvalidate(false); + RelationCacheInitFilePostInvalidate(); } else if (transInvalInfo != NULL) { |