mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Ensure that all TransactionId comparisons are encapsulated in macros
(TransactionIdPrecedes, TransactionIdFollows, etc). First step on the way to transaction ID wrap solution ...
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/*----------
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user