diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-08-16 13:11:54 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-08-16 13:11:54 -0400 |
commit | 2ada6779c5d3fcc31568ba263f8a0cc9bb8318c1 (patch) | |
tree | 7744d0ff44bd14e6deb910da2c2343885ecd3b55 /src/backend/access/transam | |
parent | 1bb69245ab234634013c543927e6fa76009622fa (diff) | |
download | postgresql-2ada6779c5d3fcc31568ba263f8a0cc9bb8318c1.tar.gz postgresql-2ada6779c5d3fcc31568ba263f8a0cc9bb8318c1.zip |
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/access/transam')
-rw-r--r-- | src/backend/access/transam/twophase.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 281268120ef..54176ee9df9 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1356,10 +1356,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit) * after we send the SI messages. See AtEOXact_Inval() */ if (hdr->initfileinval) - RelationCacheInitFileInvalidate(true); + RelationCacheInitFilePreInvalidate(); SendSharedInvalidMessages(invalmsgs, hdr->ninvalmsgs); if (hdr->initfileinval) - RelationCacheInitFileInvalidate(false); + RelationCacheInitFilePostInvalidate(); /* And now do the callbacks */ if (isCommit) |