diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-11-13 19:47:44 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-11-13 20:02:09 +0200 |
commit | 8fc23a9ed0a040d039431ef79b1bf166395ed180 (patch) | |
tree | 8e9b0b6fba1a54727dc186c831b0f615224f3fe4 /src/include/storage/bufmgr.h | |
parent | 955b4ba7f6948359efcef1c47035d382f937e9f3 (diff) |
Fix race condition between hot standby and restoring a full-page image.
There was a window in RestoreBackupBlock where a page would be zeroed out,
but not yet locked. If a backend pinned and locked the page in that window,
it saw the zeroed page instead of the old page or new page contents, which
could lead to missing rows in a result set, or errors.
To fix, replace RBM_ZERO with RBM_ZERO_AND_LOCK, which atomically pins,
zeroes, and locks the page, if it's not in the buffer cache already.
In stable branches, the old RBM_ZERO constant is renamed to RBM_DO_NOT_USE,
to avoid breaking any 3rd party extensions that might use RBM_ZERO. More
importantly, this avoids renumbering the other enum values, which would
cause even bigger confusion in extensions that use ReadBufferExtended, but
haven't been recompiled.
Backpatch to all supported versions; this has been racy since hot standby
was introduced.
Diffstat (limited to 'src/include/storage/bufmgr.h')
-rw-r--r-- | src/include/storage/bufmgr.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index 89447d0b3d4..921e4edde2a 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -36,11 +36,16 @@ typedef enum BufferAccessStrategyType typedef enum { RBM_NORMAL, /* Normal read */ - RBM_ZERO, /* Don't read from disk, caller will - * initialize */ + RBM_DO_NOT_USE, /* This used to be RBM_ZERO. Only kept for + * binary compatibility with 3rd party + * extensions. */ RBM_ZERO_ON_ERROR, /* Read, but return an all-zeros page on error */ - RBM_NORMAL_NO_LOG /* Don't log page as invalid during WAL + RBM_NORMAL_NO_LOG, /* Don't log page as invalid during WAL * replay; otherwise same as RBM_NORMAL */ + RBM_ZERO_AND_LOCK, /* Don't read from disk, caller will + * initialize. Also locks the page. */ + RBM_ZERO_AND_CLEANUP_LOCK /* Like RBM_ZERO_AND_LOCK, but locks the page + * in "cleanup" mode */ } ReadBufferMode; /* in globals.c ... this duplicates miscadmin.h */ |