Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7de9b64

Browse files
committed
Fix race condition in COMMIT PREPARED causing orphaned 2PC files
COMMIT PREPARED removes on-disk 2PC files near its end, but the statechecked if a file is on-disk or not gets read from shared memory whilenot holding the two-phase state lock.Because of that, there was a small window where a second backend doing aPREPARE TRANSACTION could reuse the GlobalTransaction put back into the2PC free list by the COMMIT PREPARED, overwriting the "ondisk" flag readafterwards by the COMMIT PREPARED to decide if its on-disk two-phasestate file should be removed, preventing the file deletion.This commit fixes this issue so as the "ondisk" flag in theGlobalTransaction is read while holding the two-phase state lock, notfrom shared memory after its entry has been added to the free list.Orphaned two-phase state files flushed to disk after a checkpoint arediscarded at the beginning of recovery. However, a truncation ofpg_xact/ would make the startup process issue a FATAL when it cannotread the SLRU page holding the state of the transaction whose 2PC filewas orphaned, which is a necessary step to decide if the 2PC file shouldbe removed or not. Removing manually the file would be necessary inthis case.Issue introduced byeffe7d9, so backpatch all the way down.Mea culpa.Author: wuchengwenDiscussion:https://postgr.es/m/tencent_A7F059B5136A359625C7B2E4A386B3C3F007@qq.comBackpatch-through: 12
1 parente183d72 commit7de9b64

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

‎src/backend/access/transam/twophase.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
14831483
GlobalTransactiongxact;
14841484
PGPROC*proc;
14851485
TransactionIdxid;
1486+
boolondisk;
14861487
char*buf;
14871488
char*bufptr;
14881489
TwoPhaseFileHeader*hdr;
@@ -1635,6 +1636,12 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
16351636

16361637
PredicateLockTwoPhaseFinish(xid,isCommit);
16371638

1639+
/*
1640+
* Read this value while holding the two-phase lock, as the on-disk 2PC
1641+
* file is physically removed after the lock is released.
1642+
*/
1643+
ondisk=gxact->ondisk;
1644+
16381645
/* Clear shared memory state */
16391646
RemoveGXact(gxact);
16401647

@@ -1650,7 +1657,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
16501657
/*
16511658
* And now we can clean up any files we may have left.
16521659
*/
1653-
if (gxact->ondisk)
1660+
if (ondisk)
16541661
RemoveTwoPhaseFile(xid, true);
16551662

16561663
MyLockedGxact=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp