1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +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:
Tom Lane
2001-08-23 23:06:38 +00:00
parent 29ec29ffac
commit 7326e78c42
17 changed files with 139 additions and 100 deletions

View 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())
{

View 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;
}

View 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
@@ -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);

View 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)
{

View 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);