summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2011-11-02 08:03:21 +0000
committerSimon Riggs <simon@2ndQuadrant.com>2011-11-02 08:03:21 +0000
commit2f55c535e1f026929cf20855b3790d3632062d42 (patch)
tree80069348e7b2a454c08c8fc4ffad7aed84db901d /src
parent7f797d27fe0be5200ad5fd5af6cefcee30c8e24a (diff)
Fix timing of Startup CLOG and MultiXact during Hot Standby
Patch by me, bug report by Chris Redekop, analysis by Florian Pflug
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/clog.c19
-rw-r--r--src/backend/access/transam/multixact.c2
-rw-r--r--src/backend/access/transam/xlog.c17
-rw-r--r--src/include/access/clog.h1
4 files changed, 33 insertions, 6 deletions
diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c
index cb3f91a76b0..e594a55c399 100644
--- a/src/backend/access/transam/clog.c
+++ b/src/backend/access/transam/clog.c
@@ -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
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index 3f3bdc03353..1cb3dfab375 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -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)
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 6c18db4050f..906292690d6 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -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();
diff --git a/src/include/access/clog.h b/src/include/access/clog.h
index a1f4c9dc6a9..873732e80ef 100644
--- a/src/include/access/clog.h
+++ b/src/include/access/clog.h
@@ -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);