From 7687162dc5c0b9ca7be5dec331d10a5b66e2e94c Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Mon, 5 Oct 2009 12:02:59 +0100 Subject: [PATCH] Apply changes from Heikki's 0003-Advance-ShmemVariableCache-nextXid-before-marking-xi.patch. --- src/backend/access/transam/xact.c | 56 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d5a95c63c8..055d3fe359 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -4520,6 +4520,20 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid, max_xid = TransactionIdLatest(xid, xlrec->nsubxacts, sub_xids); + /* Make sure nextXid is beyond any XID mentioned in the record */ + /* We don't expect anyone else to modify nextXid, hence we + * don't need to hold a lock while checking this. We still acquire + * the lock to modify it, though. + */ + if (TransactionIdFollowsOrEquals(max_xid, + ShmemVariableCache->nextXid)) + { + LWLockAcquire(XidGenLock, LW_EXCLUSIVE); + ShmemVariableCache->nextXid = max_xid; + TransactionIdAdvance(ShmemVariableCache->nextXid); + LWLockRelease(XidGenLock); + } + /* * Mark the transaction committed in pg_clog. */ @@ -4612,20 +4626,6 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid, RelationReleaseRecoveryLockTree(xid, xlrec->nsubxacts, sub_xids); } - /* Make sure nextXid is beyond any XID mentioned in the record */ - /* We don't expect anyone else to modify nextXid, hence we - * don't need to hold a lock while checking this. We still acquire - * the lock to modify it, though. - */ - if (TransactionIdFollowsOrEquals(max_xid, - ShmemVariableCache->nextXid)) - { - LWLockAcquire(XidGenLock, LW_EXCLUSIVE); - ShmemVariableCache->nextXid = max_xid; - TransactionIdAdvance(ShmemVariableCache->nextXid); - LWLockRelease(XidGenLock); - } - /* Make sure files supposed to be dropped are dropped */ for (i = 0; i < xlrec->nrels; i++) { @@ -4663,6 +4663,20 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid) sub_xids = (TransactionId *) &(xlrec->xnodes[xlrec->nrels]); max_xid = TransactionIdLatest(xid, xlrec->nsubxacts, sub_xids); + /* Make sure nextXid is beyond any XID mentioned in the record */ + /* We don't expect anyone else to modify nextXid, hence we + * don't need to hold a lock while checking this. We still acquire + * the lock to modify it, though. + */ + if (TransactionIdFollowsOrEquals(max_xid, + ShmemVariableCache->nextXid)) + { + LWLockAcquire(XidGenLock, LW_EXCLUSIVE); + ShmemVariableCache->nextXid = max_xid; + TransactionIdAdvance(ShmemVariableCache->nextXid); + LWLockRelease(XidGenLock); + } + /* Mark the transaction aborted in pg_clog, no need for async stuff */ TransactionIdAbortTree(xid, xlrec->nsubxacts, sub_xids); @@ -4693,20 +4707,6 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid) RelationReleaseRecoveryLockTree(xid, xlrec->nsubxacts, sub_xids); } - /* Make sure nextXid is beyond any XID mentioned in the record */ - /* We don't expect anyone else to modify nextXid, hence we - * don't need to hold a lock while checking this. We still acquire - * the lock to modify it, though. - */ - if (TransactionIdFollowsOrEquals(max_xid, - ShmemVariableCache->nextXid)) - { - LWLockAcquire(XidGenLock, LW_EXCLUSIVE); - ShmemVariableCache->nextXid = max_xid; - TransactionIdAdvance(ShmemVariableCache->nextXid); - LWLockRelease(XidGenLock); - } - /* Make sure files supposed to be dropped are dropped */ for (i = 0; i < xlrec->nrels; i++) { -- 2.39.5