From 8431e296ea4cfc8dd30053f89b6970ef16ddbc61 Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Thu, 13 May 2010 11:15:38 +0000 Subject: Cleanup initialization of Hot Standby. Clarify working with reanalysis of requirements and documentation on LogStandbySnapshot(). Fixes two minor bugs reported by Tom Lane that would lead to an incorrect snapshot after transaction wraparound. Also fix two other problems discovered that would give incorrect snapshots in certain cases. ProcArrayApplyRecoveryInfo() substantially rewritten. Some minor refactoring of xact_redo_apply() and ExpireTreeKnownAssignedTransactionIds(). --- src/backend/access/transam/xlog.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/backend/access/transam/xlog.c') diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index a39d455a7f0..3253bdad57c 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.409 2010/05/03 11:17:52 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.410 2010/05/13 11:15:38 sriggs Exp $ * *------------------------------------------------------------------------- */ @@ -5995,6 +5995,7 @@ StartupXLOG(void) if (wasShutdown) { RunningTransactionsData running; + TransactionId latestCompletedXid; /* * Construct a RunningTransactions snapshot representing a shut @@ -6006,6 +6007,9 @@ StartupXLOG(void) running.subxid_overflow = false; running.nextXid = checkPoint.nextXid; running.oldestRunningXid = oldestActiveXID; + latestCompletedXid = checkPoint.nextXid; + TransactionIdRetreat(latestCompletedXid); + running.latestCompletedXid = latestCompletedXid; running.xids = xids; ProcArrayApplyRecoveryInfo(&running); @@ -6154,8 +6158,9 @@ StartupXLOG(void) xlogctl->recoveryLastXTime = recoveryLastXTime; SpinLockRelease(&xlogctl->info_lck); - /* In Hot Standby mode, keep track of XIDs we've seen */ - if (InHotStandby && TransactionIdIsValid(record->xl_xid)) + /* If we are attempting to enter Hot Standby mode, process XIDs we see */ + if (standbyState >= STANDBY_INITIALIZED && + TransactionIdIsValid(record->xl_xid)) RecordKnownAssignedTransactionIds(record->xl_xid); RmgrTable[record->xl_rmid].rm_redo(EndRecPtr, record); @@ -7803,6 +7808,7 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record) TransactionId *xids; int nxids; TransactionId oldestActiveXID; + TransactionId latestCompletedXid; RunningTransactionsData running; oldestActiveXID = PrescanPreparedTransactions(&xids, &nxids); @@ -7817,6 +7823,9 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record) running.subxid_overflow = false; running.nextXid = checkPoint.nextXid; running.oldestRunningXid = oldestActiveXID; + latestCompletedXid = checkPoint.nextXid; + TransactionIdRetreat(latestCompletedXid); + running.latestCompletedXid = latestCompletedXid; running.xids = xids; ProcArrayApplyRecoveryInfo(&running); -- cgit v1.2.3