diff options
author | Robert Haas <rhaas@postgresql.org> | 2022-03-24 14:36:06 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2022-03-24 14:36:06 -0400 |
commit | 1ce14b6b2fe4af9ac7d7f90eb46c77b2e6deb2de (patch) | |
tree | ee1c6741a5ccfdf14c781b541d022ca08984a920 /src/backend/storage/buffer/bufmgr.c | |
parent | c0f99bb520da577f34cf7c10e1ea4aab727f08c7 (diff) | |
download | postgresql-1ce14b6b2fe4af9ac7d7f90eb46c77b2e6deb2de.tar.gz postgresql-1ce14b6b2fe4af9ac7d7f90eb46c77b2e6deb2de.zip |
Fix possible recovery trouble if TRUNCATE overlaps a checkpoint.
If TRUNCATE causes some buffers to be invalidated and thus the
checkpoint does not flush them, TRUNCATE must also ensure that the
corresponding files are truncated on disk. Otherwise, a replay
from the checkpoint might find that the buffers exist but have
the wrong contents, which may cause replay to fail.
Report by Teja Mupparti. Patch by Kyotaro Horiguchi, per a design
suggestion from Heikki Linnakangas, with some changes to the
comments by me. Review of this and a prior patch that approached
the issue differently by Heikki Linnakangas, Andres Freund, Álvaro
Herrera, Masahiko Sawada, and Tom Lane.
Discussion: http://postgr.es/m/BYAPR06MB6373BF50B469CA393C614257ABF00@BYAPR06MB6373.namprd06.prod.outlook.com
Diffstat (limited to 'src/backend/storage/buffer/bufmgr.c')
-rw-r--r-- | src/backend/storage/buffer/bufmgr.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 597afedef70..033ef46811f 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -3647,7 +3647,9 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std) * essential that CreateCheckpoint waits for virtual transactions * rather than full transactionids. */ - MyProc->delayChkpt = delayChkpt = true; + Assert((MyProc->delayChkpt & DELAY_CHKPT_START) == 0); + MyProc->delayChkpt |= DELAY_CHKPT_START; + delayChkpt = true; lsn = XLogSaveBufferForHint(buffer, buffer_std); } @@ -3680,7 +3682,7 @@ MarkBufferDirtyHint(Buffer buffer, bool buffer_std) UnlockBufHdr(bufHdr, buf_state); if (delayChkpt) - MyProc->delayChkpt = false; + MyProc->delayChkpt &= ~DELAY_CHKPT_START; if (dirtied) { |