Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7326e78

Browse files
committed
Ensure that all TransactionId comparisons are encapsulated in macros
(TransactionIdPrecedes, TransactionIdFollows, etc). First step on the way to transaction ID wrap solution ...
1 parent 29ec29f commit 7326e78

File tree

17 files changed

+139
-100
lines changed

17 files changed

+139
-100
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.72 2001/06/12 05:55:49 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.73 2001/08/23 23:06:37 tgl Exp $
1313
*
1414
* NOTES
1515
* The old interface functions have been converted to macros
@@ -441,20 +441,16 @@ heap_getsysattr(HeapTuple tup, int attnum, bool *isnull)
441441
result = ObjectIdGetDatum(tup->t_data->t_oid);
442442
break;
443443
case MinTransactionIdAttributeNumber:
444-
/* XXX should have a TransactionIdGetDatum macro */
445-
result = (Datum) (tup->t_data->t_xmin);
444+
result = TransactionIdGetDatum(tup->t_data->t_xmin);
446445
break;
447446
case MinCommandIdAttributeNumber:
448-
/* XXX should have a CommandIdGetDatum macro */
449-
result = (Datum) (tup->t_data->t_cmin);
447+
result = CommandIdGetDatum(tup->t_data->t_cmin);
450448
break;
451449
case MaxTransactionIdAttributeNumber:
452-
/* XXX should have a TransactionIdGetDatum macro */
453-
result = (Datum) (tup->t_data->t_xmax);
450+
result = TransactionIdGetDatum(tup->t_data->t_xmax);
454451
break;
455452
case MaxCommandIdAttributeNumber:
456-
/* XXX should have a CommandIdGetDatum macro */
457-
result = (Datum) (tup->t_data->t_cmax);
453+
result = CommandIdGetDatum(tup->t_data->t_cmax);
458454
break;
459455
case TableOidAttributeNumber:
460456
result = ObjectIdGetDatum(tup->t_tableOid);

src/backend/access/heap/heapam.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.124 2001/08/10 18:57:32 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.125 2001/08/23 23:06:37 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1206,7 +1206,7 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
12061206
* update then some other xaction could update this tuple before
12071207
* we got to this point.
12081208
*/
1209-
if (tp.t_data->t_xmax != xwait)
1209+
if (!TransactionIdEquals(tp.t_data->t_xmax, xwait))
12101210
goto l1;
12111211
if (!(tp.t_data->t_infomask & HEAP_XMAX_COMMITTED))
12121212
{
@@ -1398,7 +1398,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
13981398
* update then some other xaction could update this tuple before
13991399
* we got to this point.
14001400
*/
1401-
if (oldtup.t_data->t_xmax != xwait)
1401+
if (!TransactionIdEquals(oldtup.t_data->t_xmax, xwait))
14021402
goto l2;
14031403
if (!(oldtup.t_data->t_infomask & HEAP_XMAX_COMMITTED))
14041404
{
@@ -1694,7 +1694,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer)
16941694
* update then some other xaction could update this tuple before
16951695
* we got to this point.
16961696
*/
1697-
if (tuple->t_data->t_xmax != xwait)
1697+
if (!TransactionIdEquals(tuple->t_data->t_xmax, xwait))
16981698
goto l3;
16991699
if (!(tuple->t_data->t_infomask & HEAP_XMAX_COMMITTED))
17001700
{
@@ -2123,7 +2123,8 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
21232123
htup->t_hoff = xlhdr.t_hoff;
21242124
htup->t_xmin = record->xl_xid;
21252125
htup->t_cmin = FirstCommandId;
2126-
htup->t_xmax = htup->t_cmax = 0;
2126+
htup->t_xmax = InvalidTransactionId;
2127+
htup->t_cmax = FirstCommandId;
21272128
htup->t_infomask = HEAP_XMAX_INVALID | xlhdr.mask;
21282129

21292130
offnum = PageAddItem(page, (Item) htup, newlen, offnum,
@@ -2310,7 +2311,8 @@ newsame:;
23102311
{
23112312
htup->t_xmin = record->xl_xid;
23122313
htup->t_cmin = FirstCommandId;
2313-
htup->t_xmax = htup->t_cmax = 0;
2314+
htup->t_xmax = InvalidTransactionId;
2315+
htup->t_cmax = FirstCommandId;
23142316
htup->t_infomask = HEAP_XMAX_INVALID | xlhdr.mask;
23152317
}
23162318

@@ -2366,7 +2368,7 @@ _heap_unlock_tuple(void *data)
23662368

23672369
htup = (HeapTupleHeader) PageGetItem(page, lp);
23682370

2369-
if (htup->t_xmax != GetCurrentTransactionId() ||
2371+
if (!TransactionIdEquals(htup->t_xmax, GetCurrentTransactionId()) ||
23702372
htup->t_cmax != GetCurrentCommandId())
23712373
elog(STOP, "_heap_unlock_tuple: invalid xmax/cmax in rollback");
23722374
htup->t_infomask &= ~HEAP_XMAX_UNLOGGED;

src/backend/access/nbtree/nbtinsert.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.84 2001/07/15 22:48:16 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.85 2001/08/23 23:06:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -149,8 +149,8 @@ _bt_doinsert(Relation rel, BTItem btitem,
149149
/*
150150
* _bt_check_unique() -- Check for violation of unique index constraint
151151
*
152-
* Returns NullTransactionId if there is no conflict, else an xact ID we
153-
* must wait for to see if it commits a conflicting tuple. If an actual
152+
* Returns InvalidTransactionId if there is no conflict, else an xact ID
153+
* we must wait for to see if it commits a conflicting tuple. If an actual
154154
* conflict is detected, no return --- just elog().
155155
*/
156156
static TransactionId
@@ -275,7 +275,7 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
275275
if (nbuf != InvalidBuffer)
276276
_bt_relbuf(rel, nbuf);
277277

278-
return NullTransactionId;
278+
return InvalidTransactionId;
279279
}
280280

281281
/*----------

src/backend/access/transam/transam.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.45 2001/07/12 04:11:13 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.46 2001/08/23 23:06:37 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains the high level access-method interface to the
@@ -44,7 +44,7 @@ Relation LogRelation = (Relation) NULL;
4444
* Single-item cache for results of TransactionLogTest.
4545
* ----------------
4646
*/
47-
static TransactionId cachedTestXid = NullTransactionId;
47+
static TransactionId cachedTestXid = InvalidTransactionId;
4848
static XidStatus cachedTestXidStatus;
4949

5050
/* ----------------
@@ -333,18 +333,19 @@ InitializeTransactionLog(void)
333333

334334
/*
335335
* if we have a virgin database, we initialize the log relation by
336-
* committing the AmiTransactionId and we initialize the
336+
* committing the BootstrapTransactionId and we initialize the
337337
* variable relation by setting the next available transaction id to
338-
* FirstTransactionId. OID initialization happens as a side
338+
* FirstNormalTransactionId. OID initialization happens as a side
339339
* effect of bootstrapping in varsup.c.
340340
*/
341341
SpinAcquire(OidGenLockId);
342-
if (!TransactionIdDidCommit(AmiTransactionId))
342+
if (!TransactionIdDidCommit(BootstrapTransactionId))
343343
{
344-
TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
344+
TransactionLogUpdate(BootstrapTransactionId, XID_COMMIT);
345345
Assert(!IsUnderPostmaster &&
346-
ShmemVariableCache->nextXid <= FirstTransactionId);
347-
ShmemVariableCache->nextXid = FirstTransactionId;
346+
TransactionIdEquals(ShmemVariableCache->nextXid,
347+
FirstNormalTransactionId));
348+
ShmemVariableCache->nextXid = FirstNormalTransactionId;
348349
}
349350
else if (RecoveryCheckingEnabled())
350351
{

src/backend/access/transam/varsup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2000, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.43 2001/08/10 18:57:33 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.44 2001/08/23 23:06:37 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -41,15 +41,15 @@ GetNewTransactionId(TransactionId *xid)
4141
*/
4242
if (AMI_OVERRIDE)
4343
{
44-
*xid = AmiTransactionId;
44+
*xid = BootstrapTransactionId;
4545
return;
4646
}
4747

4848
SpinAcquire(XidGenLockId);
4949

5050
*xid = ShmemVariableCache->nextXid;
5151

52-
(ShmemVariableCache->nextXid)++;
52+
TransactionIdAdvance(ShmemVariableCache->nextXid);
5353

5454
/*
5555
* Must set MyProc->xid before releasing XidGenLock. This ensures that
@@ -89,7 +89,7 @@ ReadNewTransactionId(TransactionId *xid)
8989
*/
9090
if (AMI_OVERRIDE)
9191
{
92-
*xid = AmiTransactionId;
92+
*xid = BootstrapTransactionId;
9393
return;
9494
}
9595

src/backend/access/transam/xid.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: xid.c,v 1.31 2001/07/12 04:11:13 tgl Exp $
9+
* $Id: xid.c,v 1.32 2001/08/23 23:06:37 tgl Exp $
1010
*
1111
* OLD COMMENTS
1212
* XXX WARNING
@@ -23,11 +23,8 @@
2323

2424
#include "access/xact.h"
2525

26-
/*
27-
* TransactionId is typedef'd as uint32, so...
28-
*/
29-
#define PG_GETARG_TRANSACTIONID(n) PG_GETARG_UINT32(n)
30-
#define PG_RETURN_TRANSACTIONID(x) PG_RETURN_UINT32(x)
26+
#define PG_GETARG_TRANSACTIONID(n) DatumGetTransactionId(PG_GETARG_DATUM(n))
27+
#define PG_RETURN_TRANSACTIONID(x) return TransactionIdGetDatum(x)
3128

3229

3330
Datum
@@ -42,7 +39,6 @@ Datum
4239
xidout(PG_FUNCTION_ARGS)
4340
{
4441
TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
45-
4642
/* maximum 32 bit unsigned integer representation takes 10 chars */
4743
char *representation = palloc(11);
4844

src/backend/access/transam/xlog.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.73 2001/08/10 18:57:33 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.74 2001/08/23 23:06:37 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2349,7 +2349,7 @@ BootStrapXLOG(void)
23492349
checkPoint.redo.xrecoff = SizeOfXLogPHD;
23502350
checkPoint.undo = checkPoint.redo;
23512351
checkPoint.ThisStartUpID = 0;
2352-
checkPoint.nextXid = FirstTransactionId;
2352+
checkPoint.nextXid = FirstNormalTransactionId;
23532353
checkPoint.nextOid = BootstrapObjectIdData;
23542354
checkPoint.time = time(NULL);
23552355

@@ -2508,7 +2508,7 @@ StartupXLOG(void)
25082508
wasShutdown ? "TRUE" : "FALSE");
25092509
elog(LOG, "next transaction id: %u; next oid: %u",
25102510
checkPoint.nextXid, checkPoint.nextOid);
2511-
if (checkPoint.nextXid < FirstTransactionId)
2511+
if (!TransactionIdIsNormal(checkPoint.nextXid))
25122512
elog(STOP, "invalid next transaction id");
25132513

25142514
ShmemVariableCache->nextXid = checkPoint.nextXid;
@@ -2550,8 +2550,10 @@ StartupXLOG(void)
25502550
if (XLByteLT(checkPoint.redo, RecPtr))
25512551
record = ReadRecord(&(checkPoint.redo), STOP, buffer);
25522552
else
2553-
/* read past CheckPoint record */
2553+
{
2554+
/* read past CheckPoint record */
25542555
record = ReadRecord(NULL, LOG, buffer);
2556+
}
25552557

25562558
if (record != NULL)
25572559
{
@@ -2560,8 +2562,13 @@ StartupXLOG(void)
25602562
ReadRecPtr.xlogid, ReadRecPtr.xrecoff);
25612563
do
25622564
{
2563-
if (record->xl_xid >= ShmemVariableCache->nextXid)
2564-
ShmemVariableCache->nextXid = record->xl_xid + 1;
2565+
/* nextXid must be beyond record's xid */
2566+
if (TransactionIdFollowsOrEquals(record->xl_xid,
2567+
ShmemVariableCache->nextXid))
2568+
{
2569+
ShmemVariableCache->nextXid = record->xl_xid;
2570+
TransactionIdAdvance(ShmemVariableCache->nextXid);
2571+
}
25652572
if (XLOG_DEBUG)
25662573
{
25672574
char buf[8192];
@@ -3101,7 +3108,8 @@ xlog_redo(XLogRecPtr lsn, XLogRecord *record)
31013108

31023109
memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
31033110
/* In an ONLINE checkpoint, treat the counters like NEXTOID */
3104-
if (ShmemVariableCache->nextXid < checkPoint.nextXid)
3111+
if (TransactionIdPrecedes(ShmemVariableCache->nextXid,
3112+
checkPoint.nextXid))
31053113
ShmemVariableCache->nextXid = checkPoint.nextXid;
31063114
if (ShmemVariableCache->nextOid < checkPoint.nextOid)
31073115
{

src/backend/access/transam/xlogutils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.16 2001/06/29 21:08:24 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.17 2001/08/23 23:06:37 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -76,7 +76,7 @@ XLogIsOwnerOfTuple(RelFileNode hnode, ItemPointer iptr,
7676
htup = (HeapTupleHeader) PageGetItem(page, lp);
7777

7878
Assert(PageGetSUI(page) == ThisStartUpID);
79-
if (htup->t_xmin != xid || htup->t_cmin != cid)
79+
if (!TransactionIdEquals(htup->t_xmin, xid) || htup->t_cmin != cid)
8080
{
8181
UnlockAndReleaseBuffer(buffer);
8282
return (-1);

src/backend/commands/trigger.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.95 2001/08/10 18:57:34 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.96 2001/08/23 23:06:37 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2078,7 +2078,8 @@ DeferredTriggerSaveEvent(ResultRelInfo *relinfo, int event,
20782078
* foreign referenced key value that's changing now has been
20792079
* updated once before in this transaction.
20802080
*/
2081-
if (oldtup->t_data->t_xmin != GetCurrentTransactionId())
2081+
if (!TransactionIdEquals(oldtup->t_data->t_xmin,
2082+
GetCurrentTransactionId()))
20822083
prev_event = NULL;
20832084
else
20842085
prev_event =
@@ -2212,7 +2213,8 @@ DeferredTriggerSaveEvent(ResultRelInfo *relinfo, int event,
22122213
* possibly referenced key value has changed in this
22132214
* transaction.
22142215
*/
2215-
if (oldtup->t_data->t_xmin != GetCurrentTransactionId())
2216+
if (!TransactionIdEquals(oldtup->t_data->t_xmin,
2217+
GetCurrentTransactionId()))
22162218
break;
22172219

22182220
/*

0 commit comments

Comments
 (0)