Extend commit, subtrans and commit_ts logs appropriately when new xids are
authorPavan Deolasee <[email protected]>
Mon, 15 Feb 2016 10:47:11 +0000 (16:17 +0530)
committerPavan Deolasee <[email protected]>
Mon, 15 Feb 2016 18:30:08 +0000 (00:00 +0530)
received from the GTM.

After our recent work on cluster monitor, GTM will now send back
latestCompletedXid and RecentGlobalXmin which we record in a shared memory
area. But if the node has not asked for XIDs for some time, the SLRU
maintaining these logs may fall much behind. So we must keep these log files
upto date with the XIDs generated by the GTM

This should also fix the spotting of the following log message as reported
by Mason Sharp

LOG: could not truncate directory "pg_subtrans": apparent wraparound

src/backend/access/transam/varsup.c
src/backend/postmaster/clustermon.c
src/backend/storage/ipc/procarray.c
src/include/access/transam.h

index 1e601a68ca28eee05a9c24ae098c15a413bd9578..56844d70019ed51bcf6a1fb219477a69c8dee5cc 100644 (file)
@@ -777,3 +777,15 @@ GetNewObjectId(void)
 
        return result;
 }
+
+#ifdef XCP
+void
+ExtendLogs(TransactionId xid)
+{
+       LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
+       ExtendCLOG(xid);
+       ExtendCommitTs(xid);
+       ExtendSUBTRANS(xid);
+       LWLockRelease(XidGenLock);
+}
+#endif
index 2ff09787edb600e6846b58827830b8a8d06ef8ef..e2dda4f7f3b130e9565efdc821bdb30b4cb05d01 100644 (file)
@@ -378,6 +378,14 @@ ClusterMonitorGetGlobalXmin(void)
 void
 ClusterMonitorSetGlobalXmin(GlobalTransactionId xmin)
 {
+       /*
+        * First extend the commit logs. Even though we may not have actually
+        * started any transactions in the new range, we must still extend the logs
+        * so that later operations which rely on the RecentGlobalXmin to truncate
+        * the logs work correctly.
+        */
+       ExtendLogs(xmin);
+
        LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
 
        /*
index 216891485b26024587f95b1370ba105543994933..84b6a87d0d5786749a1797cccad1cb5a447b2083 100644 (file)
@@ -4408,6 +4408,13 @@ SetLatestCompletedXid(TransactionId latestCompletedXid)
 
        if (!TransactionIdIsValid(latestCompletedXid))
                return;
+       /*
+        * First extend the commit logs. Even though we may not have actually
+        * started any transactions in the new range, we must still extend the logs
+        * so that later operations which may try to query them based on the new
+        * value of latestCompletedXid do not throw errors
+        */
+       ExtendLogs(latestCompletedXid);
 
        LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
 
index dbd371cf3ef36947c48794c817054b342f70ac7e..9d150e14f1fa12497ec118a1d66e301f60aae55d 100644 (file)
@@ -188,6 +188,7 @@ extern TransactionId GetNewTransactionId(bool isSubXact);
 #ifdef XCP
 extern bool TransactionIdIsCurrentGlobalTransactionId(TransactionId xid);
 extern TransactionId GetNextTransactionId(void);
+extern void ExtendLogs(TransactionId xid);
 #endif
 extern TransactionId ReadNewTransactionId(void);
 extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,