From f4b99de06377420c63011251e56843e6c9d792e8 Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Tue, 8 Dec 2015 14:35:21 +0530 Subject: [PATCH] Acquire the right lock for updating latestCompletedXid. Also make sure that the latestCompletedXid is updated on the nodes irrespective of whather report-xmin returns success or failure --- src/backend/postmaster/clustermon.c | 1 + src/backend/storage/ipc/procarray.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/postmaster/clustermon.c b/src/backend/postmaster/clustermon.c index d79aae8e1e..3cb7947354 100644 --- a/src/backend/postmaster/clustermon.c +++ b/src/backend/postmaster/clustermon.c @@ -239,6 +239,7 @@ ClusterMonitorInit(void) } else { + SetLatestCompletedXid(latestCompletedXid); ClusterMonitorSetReportedGlobalXmin(oldestXmin); elog(DEBUG2, "Updating global_xmin to %d", newOldestXmin); if (GlobalTransactionIdIsValid(newOldestXmin)) diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 420f27d17d..f91bf32324 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -4375,7 +4375,7 @@ SetLatestCompletedXid(TransactionId latestCompletedXid) if (!TransactionIdIsValid(latestCompletedXid)) return; - LWLockAcquire(XidGenLock, LW_EXCLUSIVE); + LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE); if (TransactionIdPrecedes(latestCompletedXid, ShmemVariableCache->latestCompletedXid)) @@ -4390,6 +4390,9 @@ SetLatestCompletedXid(TransactionId latestCompletedXid) volatile PGXACT *pgxact = &allPgXact[pgprocno]; TransactionId pxid = pgxact->xid; + if (!TransactionIdIsValid(pxid)) + continue; + if (TransactionIdPrecedesOrEquals(pxid, latestCompletedXid)) elog(PANIC, "Cannot set latestCompletedXid to %d while another " "process is running with an older xid %d", -- 2.39.5