summaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-03-24 14:50:06 -0400
committerRobert Haas <rhaas@postgresql.org>2022-03-24 14:50:06 -0400
commit57f618310f837101ba13757baf95bae37e3766ac (patch)
treeb91663c0aa630dbfcb0b1227e0cf65c7459c93ae /src/backend/access/transam/xact.c
parent5f4615b9def5c7a4218c7e17f318e4b2eb2b1747 (diff)
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/access/transam/xact.c')
-rw-r--r--src/backend/access/transam/xact.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 25a3a4f97e6..ccd99c38c27 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -1247,8 +1247,9 @@ RecordTransactionCommit(void)
* This makes checkpoint's determination of which xacts are delayChkpt
* a bit fuzzy, but it doesn't matter.
*/
+ Assert((MyPgXact->delayChkpt & DELAY_CHKPT_START) == 0);
START_CRIT_SECTION();
- MyPgXact->delayChkpt = true;
+ MyPgXact->delayChkpt |= DELAY_CHKPT_START;
SetCurrentTransactionStopTimestamp();
@@ -1349,7 +1350,7 @@ RecordTransactionCommit(void)
*/
if (markXidCommitted)
{
- MyPgXact->delayChkpt = false;
+ MyPgXact->delayChkpt &= ~DELAY_CHKPT_START;
END_CRIT_SECTION();
}