Skip to content

Commit c64086b

Browse files
committed
Reorder actions in ProcArrayApplyRecoveryInfo()
Since 5a1dfde, 2PC filenames use FullTransactionId. Thus, it needs to convert TransactionId to FullTransactionId in StandbyTransactionIdIsPrepared() using TransamVariables->nextXid. However, ProcArrayApplyRecoveryInfo() first releases locks with usage StandbyTransactionIdIsPrepared(), then advances TransamVariables->nextXid. This sequence of actions could cause errors. This commit makes ProcArrayApplyRecoveryInfo() advance TransamVariables->nextXid before releasing locks. Reported-by: Thomas Munro, Michael Paquier Discussion: https://postgr.es/m/CA%2BhUKGLj_ve1_pNAnxwYU9rDcv7GOhsYXJt7jMKSA%3D5-6ss-Cw%40mail.gmail.com Discussion: https://postgr.es/m/Zadp9f4E1MYvMJqe%40paquier.xyz
1 parent 6db4598 commit c64086b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/backend/storage/ipc/procarray.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ void
10531053
ProcArrayApplyRecoveryInfo(RunningTransactions running)
10541054
{
10551055
TransactionId *xids;
1056+
TransactionId xid;
10561057
int nxids;
10571058
int i;
10581059

@@ -1066,6 +1067,16 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
10661067
*/
10671068
ExpireOldKnownAssignedTransactionIds(running->oldestRunningXid);
10681069

1070+
/*
1071+
* Adjust TransamVariables->nextXid before StandbyReleaseOldLocks(),
1072+
* because we will need it up to date for accessing two-phase transactions
1073+
* in StandbyReleaseOldLocks().
1074+
*/
1075+
xid = running->nextXid;
1076+
TransactionIdRetreat(xid);
1077+
AdvanceNextFullTransactionIdPastXid(xid);
1078+
Assert(FullTransactionIdIsValid(TransamVariables->nextXid));
1079+
10691080
/*
10701081
* Remove stale locks, if any.
10711082
*/
@@ -1275,11 +1286,6 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
12751286

12761287
LWLockRelease(ProcArrayLock);
12771288

1278-
/* TransamVariables->nextXid must be beyond any observed xid. */
1279-
AdvanceNextFullTransactionIdPastXid(latestObservedXid);
1280-
1281-
Assert(FullTransactionIdIsValid(TransamVariables->nextXid));
1282-
12831289
KnownAssignedXidsDisplay(DEBUG3);
12841290
if (standbyState == STANDBY_SNAPSHOT_READY)
12851291
elog(DEBUG1, "recovery snapshots are now enabled");

0 commit comments

Comments
 (0)