Add many new Asserts in code and fix simple bug that slipped through

without them, related to previous commit. Report by Bruce Momjian.
This commit is contained in:
Simon Riggs 2010-05-14 07:11:49 +00:00
parent 88fba7089e
commit fd34374b17
3 changed files with 25 additions and 8 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.410 2010/05/13 11:15:38 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.411 2010/05/14 07:11:48 sriggs Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -6009,6 +6009,7 @@ StartupXLOG(void)
running.oldestRunningXid = oldestActiveXID; running.oldestRunningXid = oldestActiveXID;
latestCompletedXid = checkPoint.nextXid; latestCompletedXid = checkPoint.nextXid;
TransactionIdRetreat(latestCompletedXid); TransactionIdRetreat(latestCompletedXid);
Assert(TransactionIdIsNormal(latestCompletedXid));
running.latestCompletedXid = latestCompletedXid; running.latestCompletedXid = latestCompletedXid;
running.xids = xids; running.xids = xids;
@ -7825,6 +7826,7 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
running.oldestRunningXid = oldestActiveXID; running.oldestRunningXid = oldestActiveXID;
latestCompletedXid = checkPoint.nextXid; latestCompletedXid = checkPoint.nextXid;
TransactionIdRetreat(latestCompletedXid); TransactionIdRetreat(latestCompletedXid);
Assert(TransactionIdIsNormal(latestCompletedXid));
running.latestCompletedXid = latestCompletedXid; running.latestCompletedXid = latestCompletedXid;
running.xids = xids; running.xids = xids;

View File

@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.69 2010/05/13 11:15:38 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.70 2010/05/14 07:11:49 sriggs Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -470,11 +470,13 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
int i; int i;
Assert(standbyState >= STANDBY_INITIALIZED); Assert(standbyState >= STANDBY_INITIALIZED);
Assert(TransactionIdIsValid(running->nextXid));
Assert(TransactionIdIsValid(running->oldestRunningXid));
Assert(TransactionIdIsNormal(running->latestCompletedXid));
/* /*
* Remove stale transactions, if any. * Remove stale transactions, if any.
*/ */
Assert(TransactionIdIsValid(running->oldestRunningXid));
ExpireOldKnownAssignedTransactionIds(running->oldestRunningXid); ExpireOldKnownAssignedTransactionIds(running->oldestRunningXid);
StandbyReleaseOldLocks(running->oldestRunningXid); StandbyReleaseOldLocks(running->oldestRunningXid);
@ -679,6 +681,9 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
if (TransactionIdFollows(nextXid, ShmemVariableCache->nextXid)) if (TransactionIdFollows(nextXid, ShmemVariableCache->nextXid))
ShmemVariableCache->nextXid = nextXid; ShmemVariableCache->nextXid = nextXid;
Assert(TransactionIdIsNormal(ShmemVariableCache->latestCompletedXid));
Assert(TransactionIdIsValid(ShmemVariableCache->nextXid));
LWLockRelease(ProcArrayLock); LWLockRelease(ProcArrayLock);
elog(trace_recovery(DEBUG2), "running transaction data initialized"); elog(trace_recovery(DEBUG2), "running transaction data initialized");
@ -1502,6 +1507,10 @@ GetRunningTransactionData(void)
LWLockRelease(XidGenLock); LWLockRelease(XidGenLock);
LWLockRelease(ProcArrayLock); LWLockRelease(ProcArrayLock);
Assert(TransactionIdIsValid(CurrentRunningXacts->nextXid));
Assert(TransactionIdIsValid(CurrentRunningXacts->oldestRunningXid));
Assert(TransactionIdIsNormal(CurrentRunningXacts->latestCompletedXid));
return CurrentRunningXacts; return CurrentRunningXacts;
} }
@ -2317,6 +2326,8 @@ void
RecordKnownAssignedTransactionIds(TransactionId xid) RecordKnownAssignedTransactionIds(TransactionId xid)
{ {
Assert(standbyState >= STANDBY_INITIALIZED); Assert(standbyState >= STANDBY_INITIALIZED);
Assert(TransactionIdIsValid(latestObservedXid));
Assert(TransactionIdIsValid(xid));
elog(trace_recovery(DEBUG4), "record known xact %u latestObservedXid %u", elog(trace_recovery(DEBUG4), "record known xact %u latestObservedXid %u",
xid, latestObservedXid); xid, latestObservedXid);

View File

@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/ipc/standby.c,v 1.22 2010/05/13 11:15:38 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/storage/ipc/standby.c,v 1.23 2010/05/14 07:11:49 sriggs Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -717,6 +717,7 @@ standby_redo(XLogRecPtr lsn, XLogRecord *record)
running.xcnt = xlrec->xcnt; running.xcnt = xlrec->xcnt;
running.subxid_overflow = xlrec->subxid_overflow; running.subxid_overflow = xlrec->subxid_overflow;
running.nextXid = xlrec->nextXid; running.nextXid = xlrec->nextXid;
running.latestCompletedXid = xlrec->latestCompletedXid;
running.oldestRunningXid = xlrec->oldestRunningXid; running.oldestRunningXid = xlrec->oldestRunningXid;
running.xids = xlrec->xids; running.xids = xlrec->xids;
@ -731,8 +732,9 @@ standby_desc_running_xacts(StringInfo buf, xl_running_xacts *xlrec)
{ {
int i; int i;
appendStringInfo(buf, " nextXid %u oldestRunningXid %u", appendStringInfo(buf, " nextXid %u latestCompletedXid %u oldestRunningXid %u",
xlrec->nextXid, xlrec->nextXid,
xlrec->latestCompletedXid,
xlrec->oldestRunningXid); xlrec->oldestRunningXid);
if (xlrec->xcnt > 0) if (xlrec->xcnt > 0)
{ {
@ -880,6 +882,7 @@ LogCurrentRunningXacts(RunningTransactions CurrRunningXacts)
xlrec.subxid_overflow = CurrRunningXacts->subxid_overflow; xlrec.subxid_overflow = CurrRunningXacts->subxid_overflow;
xlrec.nextXid = CurrRunningXacts->nextXid; xlrec.nextXid = CurrRunningXacts->nextXid;
xlrec.oldestRunningXid = CurrRunningXacts->oldestRunningXid; xlrec.oldestRunningXid = CurrRunningXacts->oldestRunningXid;
xlrec.latestCompletedXid = CurrRunningXacts->latestCompletedXid;
/* Header */ /* Header */
rdata[0].data = (char *) (&xlrec); rdata[0].data = (char *) (&xlrec);
@ -902,19 +905,20 @@ LogCurrentRunningXacts(RunningTransactions CurrRunningXacts)
if (CurrRunningXacts->subxid_overflow) if (CurrRunningXacts->subxid_overflow)
elog(trace_recovery(DEBUG2), elog(trace_recovery(DEBUG2),
"snapshot of %u running transactions overflowed (lsn %X/%X oldest xid %u next xid %u)", "snapshot of %u running transactions overflowed (lsn %X/%X oldest xid %u latest complete %u next xid %u)",
CurrRunningXacts->xcnt, CurrRunningXacts->xcnt,
recptr.xlogid, recptr.xrecoff, recptr.xlogid, recptr.xrecoff,
CurrRunningXacts->oldestRunningXid, CurrRunningXacts->oldestRunningXid,
CurrRunningXacts->latestCompletedXid,
CurrRunningXacts->nextXid); CurrRunningXacts->nextXid);
else else
elog(trace_recovery(DEBUG2), elog(trace_recovery(DEBUG2),
"snapshot of %u running transaction ids (lsn %X/%X oldest xid %u next xid %u)", "snapshot of %u running transaction ids (lsn %X/%X oldest xid %u latest complete %u next xid %u)",
CurrRunningXacts->xcnt, CurrRunningXacts->xcnt,
recptr.xlogid, recptr.xrecoff, recptr.xlogid, recptr.xrecoff,
CurrRunningXacts->oldestRunningXid, CurrRunningXacts->oldestRunningXid,
CurrRunningXacts->latestCompletedXid,
CurrRunningXacts->nextXid); CurrRunningXacts->nextXid);
} }
/* /*