Ensure that all TransactionId comparisons are encapsulated in macros
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 23 Aug 2001 23:06:38 +0000 (23:06 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 23 Aug 2001 23:06:38 +0000 (23:06 +0000)
(TransactionIdPrecedes, TransactionIdFollows, etc).  First step on the
way to transaction ID wrap solution ...

17 files changed:
src/backend/access/common/heaptuple.c
src/backend/access/heap/heapam.c
src/backend/access/nbtree/nbtinsert.c
src/backend/access/transam/transam.c
src/backend/access/transam/varsup.c
src/backend/access/transam/xid.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogutils.c
src/backend/commands/trigger.c
src/backend/postmaster/pgstat.c
src/backend/storage/ipc/sinval.c
src/backend/storage/lmgr/lock.c
src/backend/utils/time/tqual.c
src/include/access/transam.h
src/include/c.h
src/include/postgres.h
src/include/utils/tqual.h

index faaf33c50965ac11ad0c5d4045b5c4139134506a..ef6cedd92d2df5df33e6b5e6efc2261a09841180 100644 (file)
@@ -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);
index 56f3572153b4c1d229bf169b6ea77de31d32bc72..c64a19faa6148f2b1579288d7828ab1a5213472f 100644 (file)
@@ -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;
index c91c568ed2f544ea12ce57568aee37cce655ace5..a3102163dc797e8dcaaf153914c0b08589030267 100644 (file)
@@ -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;
 }
 
 /*----------
index 910042fb6245e2e032854381bbe04dda22d3f490..65718b4cae9d642bbd63fb1d7f9b52046bf517d9 100644 (file)
@@ -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())
        {
index a1144a2a79d05564b94b435b90cfd0b2aa9c8b5a..86d38c148fafb71eb82da36cca690c4ab49b1dd8 100644 (file)
@@ -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;
        }
 
index 9ec40bb2a93b4bb63b904f42673e1dc2ebda95a1..689fc33ceaff5d65edec367f860e1a29af5ee372 100644 (file)
@@ -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
 
 #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);
 
index abede0edd3bcd1fe4995f9a022964c5c8f7ae61a..9389f1599695aac9ca5ca42bea1bdfb8bd32d34c 100644 (file)
@@ -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)
                {
index 39bd86d8a7fb316246be3c451ade7afa2de2ce90..9e9aa79466090b302c94187d82a8e9116363548f 100644 (file)
@@ -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);
index 1cdbe791227595a3c7e909b74f28faad0b8e9828..de98b33346953b07a20d9032912a8ab5c4374647 100644 (file)
@@ -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;
 
                        /*
index bac549a9262ece266a5b90578553b6bd3f4b2237..298e3470d9680c1c3ea137d8c2cf779a7b3a8fc5 100644 (file)
@@ -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();
        }
 
index a93e91237f6e2df7f80519823f5b48103d9f180e..de05c4a84a243206d8f66370ad7e2c8f632463e7 100644 (file)
@@ -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;
index cff407a4a81db635baca8c32cda88325a1c7ad6a..7816a6c96894f11138c780863cc01780cc8b12ba 100644 (file)
@@ -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);
index 35113a36228ee12aa9a3c761ab9e7f0a43e09dac..c5fe5fd5162e960b8d77d3dc9296744904be0930 100644 (file)
@@ -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;
                }
        }
index 9a872278ad716dbbe49fb5296da4c916a8d7c6e0..3833d97821a9ff134f1ebb716a7e5235725d7232 100644 (file)
@@ -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 $
  *
  *-------------------------------------------------------------------------
  */
  * 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
index 0457a4af5b7ca14f131bc3969882db1f6d66edf3..d67dee12ac695a068336639a381cdc6c5d2e637e 100644 (file)
@@ -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
index 1502c84a4c639d61512711839593c8f0d262f6b0..c40db19dab2132bddbd9af5d1102e8e69059c8c3 100644 (file)
@@ -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.
index 86c88892adf040b958818f11320d5cb3ab1091a4..bff437f540bd7d9211b230a5135c90bbac8793e9 100644 (file)
@@ -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 \
        : \
        ( \