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

Commit07f32fc

Browse files
committed
Fix race condition in snapshot caching when 2PC is used.
When preparing a transaction xactCompletionCount needs to beincremented, even though the transaction has not committedyet. Otherwise the snapshot used within the transaction otherwise canget reused outside of the prepared transaction. As GetSnapshotData()does not include the current xid when building a snapshot, reuse wouldnot be correct.Somewhat surprisingly the regression tests only rarely show incorrectresults without the fix. The reason for that is that often thesnapshot's xmax will be >= the backend xid, yielding a snapshot thatis correct, despite the bug.I'm working on a reliable test for the bug, but it seems worth seeingwhether this fixes all the BF failures while I do.Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/E1k7tGP-0005V0-5k@gemulon.postgresql.org
1 parent7344782 commit07f32fc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

‎src/backend/storage/ipc/procarray.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,15 @@ ProcArrayClearTransaction(PGPROC *proc)
860860
Assert(!(proc->vacuumFlags&PROC_VACUUM_STATE_MASK));
861861
Assert(!proc->delayChkpt);
862862

863+
/*
864+
* Need to increment completion count even though transaction hasn't
865+
* really committed yet. The reason for that is that GetSnapshotData()
866+
* omits the xid of the current transaction, thus without the increment we
867+
* otherwise could end up reusing the snapshot later. Which would be bad,
868+
* because it might not count the prepared transaction as running.
869+
*/
870+
ShmemVariableCache->xactCompletionCount++;
871+
863872
/* Clear the subtransaction-XID cache too */
864873
Assert(ProcGlobal->subxidStates[pgxactoff].count==proc->subxidStatus.count&&
865874
ProcGlobal->subxidStates[pgxactoff].overflowed==proc->subxidStatus.overflowed);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp