From 7326e78c4249393359edce09f555aaa049be2a80 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 23 Aug 2001 23:06:38 +0000 Subject: [PATCH] Ensure that all TransactionId comparisons are encapsulated in macros (TransactionIdPrecedes, TransactionIdFollows, etc). First step on the way to transaction ID wrap solution ... --- src/backend/access/common/heaptuple.c | 14 ++++----- src/backend/access/heap/heapam.c | 16 ++++++----- src/backend/access/nbtree/nbtinsert.c | 8 +++--- src/backend/access/transam/transam.c | 17 +++++------ src/backend/access/transam/varsup.c | 8 +++--- src/backend/access/transam/xid.c | 10 ++----- src/backend/access/transam/xlog.c | 22 +++++++++----- src/backend/access/transam/xlogutils.c | 4 +-- src/backend/commands/trigger.c | 8 ++++-- src/backend/postmaster/pgstat.c | 22 +++++++------- src/backend/storage/ipc/sinval.c | 12 ++++---- src/backend/storage/lmgr/lock.c | 4 +-- src/backend/utils/time/tqual.c | 14 ++++----- src/include/access/transam.h | 40 +++++++++++++++----------- src/include/c.h | 6 ++-- src/include/postgres.h | 30 ++++++++++++++++++- src/include/utils/tqual.h | 4 +-- 17 files changed, 139 insertions(+), 100 deletions(-) diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c index faaf33c509..ef6cedd92d 100644 --- a/src/backend/access/common/heaptuple.c +++ b/src/backend/access/common/heaptuple.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.72 2001/06/12 05:55:49 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.73 2001/08/23 23:06:37 tgl Exp $ * * NOTES * The old interface functions have been converted to macros @@ -441,20 +441,16 @@ heap_getsysattr(HeapTuple tup, int attnum, bool *isnull) result = ObjectIdGetDatum(tup->t_data->t_oid); break; case MinTransactionIdAttributeNumber: - /* XXX should have a TransactionIdGetDatum macro */ - result = (Datum) (tup->t_data->t_xmin); + result = TransactionIdGetDatum(tup->t_data->t_xmin); break; case MinCommandIdAttributeNumber: - /* XXX should have a CommandIdGetDatum macro */ - result = (Datum) (tup->t_data->t_cmin); + result = CommandIdGetDatum(tup->t_data->t_cmin); break; case MaxTransactionIdAttributeNumber: - /* XXX should have a TransactionIdGetDatum macro */ - result = (Datum) (tup->t_data->t_xmax); + result = TransactionIdGetDatum(tup->t_data->t_xmax); break; case MaxCommandIdAttributeNumber: - /* XXX should have a CommandIdGetDatum macro */ - result = (Datum) (tup->t_data->t_cmax); + result = CommandIdGetDatum(tup->t_data->t_cmax); break; case TableOidAttributeNumber: result = ObjectIdGetDatum(tup->t_tableOid); diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 56f3572153..c64a19faa6 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.124 2001/08/10 18:57:32 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.125 2001/08/23 23:06:37 tgl Exp $ * * * INTERFACE ROUTINES @@ -1206,7 +1206,7 @@ l1: * update then some other xaction could update this tuple before * we got to this point. */ - if (tp.t_data->t_xmax != xwait) + if (!TransactionIdEquals(tp.t_data->t_xmax, xwait)) goto l1; if (!(tp.t_data->t_infomask & HEAP_XMAX_COMMITTED)) { @@ -1398,7 +1398,7 @@ l2: * update then some other xaction could update this tuple before * we got to this point. */ - if (oldtup.t_data->t_xmax != xwait) + if (!TransactionIdEquals(oldtup.t_data->t_xmax, xwait)) goto l2; if (!(oldtup.t_data->t_infomask & HEAP_XMAX_COMMITTED)) { @@ -1694,7 +1694,7 @@ l3: * update then some other xaction could update this tuple before * we got to this point. */ - if (tuple->t_data->t_xmax != xwait) + if (!TransactionIdEquals(tuple->t_data->t_xmax, xwait)) goto l3; if (!(tuple->t_data->t_infomask & HEAP_XMAX_COMMITTED)) { @@ -2123,7 +2123,8 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record) htup->t_hoff = xlhdr.t_hoff; htup->t_xmin = record->xl_xid; htup->t_cmin = FirstCommandId; - htup->t_xmax = htup->t_cmax = 0; + htup->t_xmax = InvalidTransactionId; + htup->t_cmax = FirstCommandId; htup->t_infomask = HEAP_XMAX_INVALID | xlhdr.mask; offnum = PageAddItem(page, (Item) htup, newlen, offnum, @@ -2310,7 +2311,8 @@ newsame:; { htup->t_xmin = record->xl_xid; htup->t_cmin = FirstCommandId; - htup->t_xmax = htup->t_cmax = 0; + htup->t_xmax = InvalidTransactionId; + htup->t_cmax = FirstCommandId; htup->t_infomask = HEAP_XMAX_INVALID | xlhdr.mask; } @@ -2366,7 +2368,7 @@ _heap_unlock_tuple(void *data) htup = (HeapTupleHeader) PageGetItem(page, lp); - if (htup->t_xmax != GetCurrentTransactionId() || + if (!TransactionIdEquals(htup->t_xmax, GetCurrentTransactionId()) || htup->t_cmax != GetCurrentCommandId()) elog(STOP, "_heap_unlock_tuple: invalid xmax/cmax in rollback"); htup->t_infomask &= ~HEAP_XMAX_UNLOGGED; diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index c91c568ed2..a3102163dc 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.84 2001/07/15 22:48:16 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.85 2001/08/23 23:06:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -149,8 +149,8 @@ top: /* * _bt_check_unique() -- Check for violation of unique index constraint * - * Returns NullTransactionId if there is no conflict, else an xact ID we - * must wait for to see if it commits a conflicting tuple. If an actual + * Returns InvalidTransactionId if there is no conflict, else an xact ID + * we must wait for to see if it commits a conflicting tuple. If an actual * conflict is detected, no return --- just elog(). */ static TransactionId @@ -275,7 +275,7 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel, if (nbuf != InvalidBuffer) _bt_relbuf(rel, nbuf); - return NullTransactionId; + return InvalidTransactionId; } /*---------- 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); diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 1cdbe79122..de98b33346 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.95 2001/08/10 18:57:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.96 2001/08/23 23:06:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2078,7 +2078,8 @@ DeferredTriggerSaveEvent(ResultRelInfo *relinfo, int event, * foreign referenced key value that's changing now has been * updated once before in this transaction. */ - if (oldtup->t_data->t_xmin != GetCurrentTransactionId()) + if (!TransactionIdEquals(oldtup->t_data->t_xmin, + GetCurrentTransactionId())) prev_event = NULL; else prev_event = @@ -2212,7 +2213,8 @@ DeferredTriggerSaveEvent(ResultRelInfo *relinfo, int event, * possibly referenced key value has changed in this * transaction. */ - if (oldtup->t_data->t_xmin != GetCurrentTransactionId()) + if (!TransactionIdEquals(oldtup->t_data->t_xmin, + GetCurrentTransactionId())) break; /* diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index bac549a926..298e3470d9 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -16,7 +16,7 @@ * * Copyright (c) 2001, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.6 2001/08/05 02:06:50 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.7 2001/08/23 23:06:37 tgl Exp $ * ---------- */ #include "postgres.h" @@ -500,10 +500,10 @@ pgstat_vacuum_tabstat(void) * If not done for this transaction, read the statistics collector * stats file into some hash tables. */ - if (pgStatDBHashXact != GetCurrentTransactionId()) + if (!TransactionIdEquals(pgStatDBHashXact, GetCurrentTransactionId())) { pgstat_read_statsfile(&pgStatDBHash, MyDatabaseId, - &pgStatBeTable, &pgStatNumBackends); + &pgStatBeTable, &pgStatNumBackends); pgStatDBHashXact = GetCurrentTransactionId(); } @@ -916,10 +916,10 @@ pgstat_fetch_stat_dbentry(Oid dbid) * stats file into some hash tables. Be careful with the read_statsfile() * call below! */ - if (pgStatDBHashXact != GetCurrentTransactionId()) + if (!TransactionIdEquals(pgStatDBHashXact, GetCurrentTransactionId())) { pgstat_read_statsfile(&pgStatDBHash, MyDatabaseId, - &pgStatBeTable, &pgStatNumBackends); + &pgStatBeTable, &pgStatNumBackends); pgStatDBHashXact = GetCurrentTransactionId(); } @@ -956,10 +956,10 @@ pgstat_fetch_stat_tabentry(Oid relid) * stats file into some hash tables. Be careful with the read_statsfile() * call below! */ - if (pgStatDBHashXact != GetCurrentTransactionId()) + if (!TransactionIdEquals(pgStatDBHashXact, GetCurrentTransactionId())) { pgstat_read_statsfile(&pgStatDBHash, MyDatabaseId, - &pgStatBeTable, &pgStatNumBackends); + &pgStatBeTable, &pgStatNumBackends); pgStatDBHashXact = GetCurrentTransactionId(); } @@ -997,10 +997,10 @@ pgstat_fetch_stat_tabentry(Oid relid) PgStat_StatBeEntry * pgstat_fetch_stat_beentry(int beid) { - if (pgStatDBHashXact != GetCurrentTransactionId()) + if (!TransactionIdEquals(pgStatDBHashXact, GetCurrentTransactionId())) { pgstat_read_statsfile(&pgStatDBHash, MyDatabaseId, - &pgStatBeTable, &pgStatNumBackends); + &pgStatBeTable, &pgStatNumBackends); pgStatDBHashXact = GetCurrentTransactionId(); } @@ -1021,10 +1021,10 @@ pgstat_fetch_stat_beentry(int beid) int pgstat_fetch_stat_numbackends(void) { - if (pgStatDBHashXact != GetCurrentTransactionId()) + if (!TransactionIdEquals(pgStatDBHashXact, GetCurrentTransactionId())) { pgstat_read_statsfile(&pgStatDBHash, MyDatabaseId, - &pgStatBeTable, &pgStatNumBackends); + &pgStatBeTable, &pgStatNumBackends); pgStatDBHashXact = GetCurrentTransactionId(); } diff --git a/src/backend/storage/ipc/sinval.c b/src/backend/storage/ipc/sinval.c index a93e91237f..de05c4a84a 100644 --- a/src/backend/storage/ipc/sinval.c +++ b/src/backend/storage/ipc/sinval.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.37 2001/07/16 22:43:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.38 2001/08/23 23:06:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -241,12 +241,12 @@ GetXmaxRecent(TransactionId *XmaxRecent) /* Fetch xid just once - see GetNewTransactionId */ TransactionId xid = proc->xid; - if (! TransactionIdIsSpecial(xid)) + if (TransactionIdIsNormal(xid)) { if (TransactionIdPrecedes(xid, result)) result = xid; xid = proc->xmin; - if (! TransactionIdIsSpecial(xid)) + if (TransactionIdIsNormal(xid)) if (TransactionIdPrecedes(xid, result)) result = xid; } @@ -347,8 +347,8 @@ GetSnapshotData(bool serializable) * treat them as running anyway. */ if (proc == MyProc || - TransactionIdIsSpecial(xid) || - ! TransactionIdPrecedes(xid, snapshot->xmax)) + ! TransactionIdIsNormal(xid) || + TransactionIdFollowsOrEquals(xid, snapshot->xmax)) continue; if (TransactionIdPrecedes(xid, snapshot->xmin)) @@ -364,7 +364,7 @@ GetSnapshotData(bool serializable) SpinRelease(SInvalLock); /* Serializable snapshot must be computed before any other... */ - Assert(MyProc->xmin != InvalidTransactionId); + Assert(TransactionIdIsValid(MyProc->xmin)); snapshot->xcnt = count; return snapshot; diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index cff407a4a8..7816a6c968 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.91 2001/07/09 22:18:33 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.92 2001/08/23 23:06:38 tgl Exp $ * * NOTES * Outside modules can create a lock table and acquire/release @@ -1277,7 +1277,7 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc, goto next_item; /* If not allxids, ignore items that are of the wrong xid */ - if (!allxids && xid != holder->tag.xid) + if (!allxids && !TransactionIdEquals(xid, holder->tag.xid)) goto next_item; HOLDER_PRINT("LockReleaseAll", holder); diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c index 35113a3622..c5fe5fd516 100644 --- a/src/backend/utils/time/tqual.c +++ b/src/backend/utils/time/tqual.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.39 2001/07/16 22:43:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.40 2001/08/23 23:06:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -531,15 +531,15 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) * when... */ - if (tuple->t_xmin >= snapshot->xmax) + if (TransactionIdFollowsOrEquals(tuple->t_xmin, snapshot->xmax)) return false; - if (tuple->t_xmin >= snapshot->xmin) + if (TransactionIdFollowsOrEquals(tuple->t_xmin, snapshot->xmin)) { uint32 i; for (i = 0; i < snapshot->xcnt; i++) { - if (tuple->t_xmin == snapshot->xip[i]) + if (TransactionIdEquals(tuple->t_xmin, snapshot->xip[i])) return false; } } @@ -571,15 +571,15 @@ HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot) tuple->t_infomask |= HEAP_XMAX_COMMITTED; } - if (tuple->t_xmax >= snapshot->xmax) + if (TransactionIdFollowsOrEquals(tuple->t_xmax, snapshot->xmax)) return true; - if (tuple->t_xmax >= snapshot->xmin) + if (TransactionIdFollowsOrEquals(tuple->t_xmax, snapshot->xmin)) { uint32 i; for (i = 0; i < snapshot->xcnt; i++) { - if (tuple->t_xmax == snapshot->xip[i]) + if (TransactionIdEquals(tuple->t_xmax, snapshot->xip[i])) return true; } } diff --git a/src/include/access/transam.h b/src/include/access/transam.h index 9a872278ad..3833d97821 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: transam.h,v 1.37 2001/08/10 18:57:39 tgl Exp $ + * $Id: transam.h,v 1.38 2001/08/23 23:06:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -24,29 +24,37 @@ * 128 bytes of pg_log available for special purposes such as version number * storage. (Currently, we do not actually use them for anything.) * - * AmiTransactionId is the XID for "bootstrap" operations. It should always - * be considered valid. + * BootstrapTransactionId is the XID for "bootstrap" operations. It should + * always be considered valid. * - * FirstTransactionId is the first "normal" transaction id. + * FirstNormalTransactionId is the first "normal" transaction id. * ---------------- */ -#define NullTransactionId ((TransactionId) 0) -#define DisabledTransactionId ((TransactionId) 1) -#define AmiTransactionId ((TransactionId) 512) -#define FirstTransactionId ((TransactionId) 514) +#define InvalidTransactionId ((TransactionId) 0) +#define DisabledTransactionId ((TransactionId) 1) +#define BootstrapTransactionId ((TransactionId) 512) +#define FirstNormalTransactionId ((TransactionId) 514) /* ---------------- * transaction ID manipulation macros * ---------------- */ -#define TransactionIdIsValid(xid) ((bool) ((xid) != NullTransactionId)) -#define TransactionIdIsSpecial(xid) ((bool) ((xid) < FirstTransactionId)) -#define TransactionIdEquals(id1, id2) ((bool) ((id1) == (id2))) -#define TransactionIdPrecedes(id1, id2) ((bool) ((id1) < (id2))) -#define TransactionIdStore(xid, dest) \ - (*((TransactionId*) (dest)) = (TransactionId) (xid)) -#define StoreInvalidTransactionId(dest) \ - (*((TransactionId*) (dest)) = NullTransactionId) +#define TransactionIdIsValid(xid) ((xid) != InvalidTransactionId) +#define TransactionIdIsNormal(xid) ((xid) >= FirstNormalTransactionId) +#define TransactionIdEquals(id1, id2) ((id1) == (id2)) +#define TransactionIdPrecedes(id1, id2) ((id1) < (id2)) +#define TransactionIdPrecedesOrEquals(id1, id2) ((id1) <= (id2)) +#define TransactionIdFollows(id1, id2) ((id1) > (id2)) +#define TransactionIdFollowsOrEquals(id1, id2) ((id1) >= (id2)) +#define TransactionIdStore(xid, dest) (*(dest) = (xid)) +#define StoreInvalidTransactionId(dest) (*(dest) = InvalidTransactionId) +/* advance a transaction ID variable, handling wraparound correctly */ +#define TransactionIdAdvance(dest) \ + do { \ + (dest)++; \ + if ((dest) < FirstNormalTransactionId) \ + (dest) = FirstNormalTransactionId; \ + } while(0) /* ---------------- * transaction status values diff --git a/src/include/c.h b/src/include/c.h index 0457a4af5b..d67dee12ac 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: c.h,v 1.97 2001/07/11 22:12:43 momjian Exp $ + * $Id: c.h,v 1.98 2001/08/23 23:06:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -330,11 +330,9 @@ typedef Oid RegProcedure; typedef uint32 TransactionId; -#define InvalidTransactionId 0 - typedef uint32 CommandId; -#define FirstCommandId 0 +#define FirstCommandId ((CommandId) 0) /* * Array indexing support diff --git a/src/include/postgres.h b/src/include/postgres.h index 1502c84a4c..c40db19dab 100644 --- a/src/include/postgres.h +++ b/src/include/postgres.h @@ -10,7 +10,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1995, Regents of the University of California * - * $Id: postgres.h,v 1.50 2001/08/10 18:57:41 tgl Exp $ + * $Id: postgres.h,v 1.51 2001/08/23 23:06:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -261,6 +261,34 @@ typedef Datum *DatumPtr; #define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X)) +/* + * DatumGetTransactionId + * Returns transaction identifier value of a datum. + */ + +#define DatumGetTransactionId(X) ((TransactionId) GET_4_BYTES(X)) + +/* + * TransactionIdGetDatum + * Returns datum representation for a transaction identifier. + */ + +#define TransactionIdGetDatum(X) ((Datum) SET_4_BYTES((X))) + +/* + * DatumGetCommandId + * Returns command identifier value of a datum. + */ + +#define DatumGetCommandId(X) ((CommandId) GET_4_BYTES(X)) + +/* + * CommandIdGetDatum + * Returns datum representation for a command identifier. + */ + +#define CommandIdGetDatum(X) ((Datum) SET_4_BYTES(X)) + /* * DatumGetPointer * Returns pointer value of a datum. diff --git a/src/include/utils/tqual.h b/src/include/utils/tqual.h index 86c88892ad..bff437f540 100644 --- a/src/include/utils/tqual.h +++ b/src/include/utils/tqual.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: tqual.h,v 1.32 2001/07/12 04:11:13 tgl Exp $ + * $Id: tqual.h,v 1.33 2001/08/23 23:06:38 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -57,7 +57,7 @@ extern bool ReferentialIntegritySnapshotOverride; */ #define HeapTupleSatisfiesVisibility(tuple, snapshot) \ ( \ - TransactionIdEquals((tuple)->t_data->t_xmax, AmiTransactionId) ? \ + TransactionIdEquals((tuple)->t_data->t_xmax, BootstrapTransactionId) ? \ false \ : \ ( \