Acquire the right lock for updating latestCompletedXid.
authorPavan Deolasee <[email protected]>
Tue, 8 Dec 2015 09:05:21 +0000 (14:35 +0530)
committerPavan Deolasee <[email protected]>
Tue, 8 Dec 2015 09:05:21 +0000 (14:35 +0530)
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
src/backend/storage/ipc/procarray.c

index d79aae8e1e203f5a6db0c004bb53f5d7f75dc511..3cb794735474e937defc80589b06d1bebd64dc02 100644 (file)
@@ -239,6 +239,7 @@ ClusterMonitorInit(void)
                }
                else
                {
+                       SetLatestCompletedXid(latestCompletedXid);
                        ClusterMonitorSetReportedGlobalXmin(oldestXmin);
                        elog(DEBUG2, "Updating global_xmin to %d", newOldestXmin);
                        if (GlobalTransactionIdIsValid(newOldestXmin))
index 420f27d17da077c075836b9d233080fb72552b48..f91bf323242ea525d14beb4be476f5569b799212 100644 (file)
@@ -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",