diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-08-23 23:06:38 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-08-23 23:06:38 +0000 |
commit | 7326e78c4249393359edce09f555aaa049be2a80 (patch) | |
tree | d1fc53198588ee98884524a28b13105a6b296952 /src/backend/access/transam | |
parent | 29ec29ffac53b50870a55b88f96b462835e9042a (diff) | |
download | postgresql-7326e78c4249393359edce09f555aaa049be2a80.tar.gz |
Ensure that all TransactionId comparisons are encapsulated in macros
(TransactionIdPrecedes, TransactionIdFollows, etc). First step on the
way to transaction ID wrap solution ...
Diffstat (limited to 'src/backend/access/transam')
-rw-r--r-- | src/backend/access/transam/transam.c | 17 | ||||
-rw-r--r-- | src/backend/access/transam/varsup.c | 8 | ||||
-rw-r--r-- | src/backend/access/transam/xid.c | 10 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 22 | ||||
-rw-r--r-- | src/backend/access/transam/xlogutils.c | 4 |
5 files changed, 33 insertions, 28 deletions
diff --git a/src/backend/access/transam/transam.c b/src/backend/access/transam/transam.c index 910042fb62..65718b4cae 100644 --- a/src/backend/access/transam/transam.c +++ b/src/backend/access/transam/transam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.45 2001/07/12 04:11:13 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.46 2001/08/23 23:06:37 tgl Exp $ * * NOTES * This file contains the high level access-method interface to the @@ -44,7 +44,7 @@ Relation LogRelation = (Relation) NULL; * Single-item cache for results of TransactionLogTest. * ---------------- */ -static TransactionId cachedTestXid = NullTransactionId; +static TransactionId cachedTestXid = InvalidTransactionId; static XidStatus cachedTestXidStatus; /* ---------------- @@ -333,18 +333,19 @@ InitializeTransactionLog(void) /* * if we have a virgin database, we initialize the log relation by - * committing the AmiTransactionId and we initialize the + * committing the BootstrapTransactionId and we initialize the * variable relation by setting the next available transaction id to - * FirstTransactionId. OID initialization happens as a side + * FirstNormalTransactionId. OID initialization happens as a side * effect of bootstrapping in varsup.c. */ SpinAcquire(OidGenLockId); - if (!TransactionIdDidCommit(AmiTransactionId)) + if (!TransactionIdDidCommit(BootstrapTransactionId)) { - TransactionLogUpdate(AmiTransactionId, XID_COMMIT); + TransactionLogUpdate(BootstrapTransactionId, XID_COMMIT); Assert(!IsUnderPostmaster && - ShmemVariableCache->nextXid <= FirstTransactionId); - ShmemVariableCache->nextXid = FirstTransactionId; + TransactionIdEquals(ShmemVariableCache->nextXid, + FirstNormalTransactionId)); + ShmemVariableCache->nextXid = FirstNormalTransactionId; } else if (RecoveryCheckingEnabled()) { diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index a1144a2a79..86d38c148f 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -6,7 +6,7 @@ * Copyright (c) 2000, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.43 2001/08/10 18:57:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.44 2001/08/23 23:06:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,7 @@ GetNewTransactionId(TransactionId *xid) */ if (AMI_OVERRIDE) { - *xid = AmiTransactionId; + *xid = BootstrapTransactionId; return; } @@ -49,7 +49,7 @@ GetNewTransactionId(TransactionId *xid) *xid = ShmemVariableCache->nextXid; - (ShmemVariableCache->nextXid)++; + TransactionIdAdvance(ShmemVariableCache->nextXid); /* * Must set MyProc->xid before releasing XidGenLock. This ensures that @@ -89,7 +89,7 @@ ReadNewTransactionId(TransactionId *xid) */ if (AMI_OVERRIDE) { - *xid = AmiTransactionId; + *xid = BootstrapTransactionId; return; } diff --git a/src/backend/access/transam/xid.c b/src/backend/access/transam/xid.c index 9ec40bb2a9..689fc33cea 100644 --- a/src/backend/access/transam/xid.c +++ b/src/backend/access/transam/xid.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: xid.c,v 1.31 2001/07/12 04:11:13 tgl Exp $ + * $Id: xid.c,v 1.32 2001/08/23 23:06:37 tgl Exp $ * * OLD COMMENTS * XXX WARNING @@ -23,11 +23,8 @@ #include "access/xact.h" -/* - * TransactionId is typedef'd as uint32, so... - */ -#define PG_GETARG_TRANSACTIONID(n) PG_GETARG_UINT32(n) -#define PG_RETURN_TRANSACTIONID(x) PG_RETURN_UINT32(x) +#define PG_GETARG_TRANSACTIONID(n) DatumGetTransactionId(PG_GETARG_DATUM(n)) +#define PG_RETURN_TRANSACTIONID(x) return TransactionIdGetDatum(x) Datum @@ -42,7 +39,6 @@ Datum xidout(PG_FUNCTION_ARGS) { TransactionId transactionId = PG_GETARG_TRANSACTIONID(0); - /* maximum 32 bit unsigned integer representation takes 10 chars */ char *representation = palloc(11); diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index abede0edd3..9389f15996 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.73 2001/08/10 18:57:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.74 2001/08/23 23:06:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2349,7 +2349,7 @@ BootStrapXLOG(void) checkPoint.redo.xrecoff = SizeOfXLogPHD; checkPoint.undo = checkPoint.redo; checkPoint.ThisStartUpID = 0; - checkPoint.nextXid = FirstTransactionId; + checkPoint.nextXid = FirstNormalTransactionId; checkPoint.nextOid = BootstrapObjectIdData; checkPoint.time = time(NULL); @@ -2508,7 +2508,7 @@ StartupXLOG(void) wasShutdown ? "TRUE" : "FALSE"); elog(LOG, "next transaction id: %u; next oid: %u", checkPoint.nextXid, checkPoint.nextOid); - if (checkPoint.nextXid < FirstTransactionId) + if (!TransactionIdIsNormal(checkPoint.nextXid)) elog(STOP, "invalid next transaction id"); ShmemVariableCache->nextXid = checkPoint.nextXid; @@ -2550,8 +2550,10 @@ StartupXLOG(void) if (XLByteLT(checkPoint.redo, RecPtr)) record = ReadRecord(&(checkPoint.redo), STOP, buffer); else -/* read past CheckPoint record */ + { + /* read past CheckPoint record */ record = ReadRecord(NULL, LOG, buffer); + } if (record != NULL) { @@ -2560,8 +2562,13 @@ StartupXLOG(void) ReadRecPtr.xlogid, ReadRecPtr.xrecoff); do { - if (record->xl_xid >= ShmemVariableCache->nextXid) - ShmemVariableCache->nextXid = record->xl_xid + 1; + /* nextXid must be beyond record's xid */ + if (TransactionIdFollowsOrEquals(record->xl_xid, + ShmemVariableCache->nextXid)) + { + ShmemVariableCache->nextXid = record->xl_xid; + TransactionIdAdvance(ShmemVariableCache->nextXid); + } if (XLOG_DEBUG) { char buf[8192]; @@ -3101,7 +3108,8 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record) memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint)); /* In an ONLINE checkpoint, treat the counters like NEXTOID */ - if (ShmemVariableCache->nextXid < checkPoint.nextXid) + if (TransactionIdPrecedes(ShmemVariableCache->nextXid, + checkPoint.nextXid)) ShmemVariableCache->nextXid = checkPoint.nextXid; if (ShmemVariableCache->nextOid < checkPoint.nextOid) { diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 39bd86d8a7..9e9aa79466 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.16 2001/06/29 21:08:24 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.17 2001/08/23 23:06:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -76,7 +76,7 @@ XLogIsOwnerOfTuple(RelFileNode hnode, ItemPointer iptr, htup = (HeapTupleHeader) PageGetItem(page, lp); Assert(PageGetSUI(page) == ThisStartUpID); - if (htup->t_xmin != xid || htup->t_cmin != cid) + if (!TransactionIdEquals(htup->t_xmin, xid) || htup->t_cmin != cid) { UnlockAndReleaseBuffer(buffer); return (-1); |