]> granicus.if.org Git - postgresql/commitdiff
Fix timing of Startup CLOG and MultiXact during Hot Standby
authorSimon Riggs <simon@2ndQuadrant.com>
Wed, 2 Nov 2011 08:03:21 +0000 (08:03 +0000)
committerSimon Riggs <simon@2ndQuadrant.com>
Wed, 2 Nov 2011 08:03:21 +0000 (08:03 +0000)
Patch by me, bug report by Chris Redekop, analysis by Florian Pflug

src/backend/access/transam/clog.c
src/backend/access/transam/multixact.c
src/backend/access/transam/xlog.c
src/include/access/clog.h

index cb3f91a76b09e57c208a8f01c436a992e71b652e..e594a55c399a251ad0e6f73c73b22095fd27fb25 100644 (file)
@@ -490,6 +490,25 @@ StartupCLOG(void)
         */
        ClogCtl->shared->latest_page_number = pageno;
 
+       LWLockRelease(CLogControlLock);
+}
+
+/*
+ * This must be called ONCE at the end of startup/recovery.
+ */
+void
+TrimCLOG(void)
+{
+       TransactionId xid = ShmemVariableCache->nextXid;
+       int                     pageno = TransactionIdToPage(xid);
+
+       LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
+
+       /*
+        * Re-Initialize our idea of the latest page number.
+        */
+       ClogCtl->shared->latest_page_number = pageno;
+
        /*
         * Zero out the remainder of the current clog page.  Under normal
         * circumstances it should be zeroes already, but it seems at least
index 3f3bdc03353a819b5242664f0d9a638a23241ff2..1cb3dfab3750fce93519d947fcc4babf3fbd2393 100644 (file)
@@ -1568,7 +1568,7 @@ StartupMultiXact(void)
 
        /*
         * Zero out the remainder of the current members page.  See notes in
-        * StartupCLOG() for motivation.
+        * TrimCLOG() for motivation.
         */
        entryno = MXOffsetToMemberEntry(offset);
        if (entryno != 0)
index 6c18db4050fd3744324b9479f059cbfb9ffdd7d3..906292690d6658d3b55cf38450cfbb8f8b2639ad 100644 (file)
@@ -6067,10 +6067,12 @@ StartupXLOG(void)
                                oldestActiveXID = checkPoint.oldestActiveXid;
                        Assert(TransactionIdIsValid(oldestActiveXID));
 
-                       /* Startup commit log and related stuff */
+                       /*
+                        * Startup commit log and subtrans only. Other SLRUs are not
+                        * maintained during recovery and need not be started yet.
+                        */
                        StartupCLOG();
                        StartupSUBTRANS(oldestActiveXID);
-                       StartupMultiXact();
 
                        /*
                         * If we're beginning at a shutdown checkpoint, we know that
@@ -6530,16 +6532,21 @@ StartupXLOG(void)
        TransactionIdRetreat(ShmemVariableCache->latestCompletedXid);
 
        /*
-        * Start up the commit log and related stuff, too. In hot standby mode we
-        * did this already before WAL replay.
+        * Start up the commit log and subtrans, if not already done for
+        * hot standby.
         */
        if (standbyState == STANDBY_DISABLED)
        {
                StartupCLOG();
                StartupSUBTRANS(oldestActiveXID);
-               StartupMultiXact();
        }
 
+       /*
+        * Perform end of recovery actions for any SLRUs that need it.
+        */
+       StartupMultiXact();
+       TrimCLOG();
+
        /* Reload shared-memory state for prepared transactions */
        RecoverPreparedTransactions();
 
index a1f4c9dc6a95bf00351a6f056a1d1e2ed8378d2f..873732e80ef96c73dc9252a3b21b7d6a44fb04c3 100644 (file)
@@ -40,6 +40,7 @@ extern Size CLOGShmemSize(void);
 extern void CLOGShmemInit(void);
 extern void BootStrapCLOG(void);
 extern void StartupCLOG(void);
+extern void TrimCLOG(void);
 extern void ShutdownCLOG(void);
 extern void CheckPointCLOG(void);
 extern void ExtendCLOG(TransactionId newestXact);