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

Commit 86fff99

Browse files
committed
RecentXmin is too recent to use as the cutoff point for accessing
pg_subtrans --- what we need is the oldest xmin of any snapshot in use in the current top transaction. Introduce a new variable TransactionXmin to play this role. Fixes intermittent regression failure reported by Neil Conway.
1 parent 8f9f198 commit 86fff99

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

src/backend/access/transam/subtrans.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
2323
* Portions Copyright (c) 1994, Regents of the University of California
2424
*
25-
* $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.5 2004/08/29 05:06:40 momjian Exp $
25+
* $PostgreSQL: pgsql/src/backend/access/transam/subtrans.c,v 1.6 2004/09/16 18:35:20 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -105,7 +105,7 @@ SubTransGetParent(TransactionId xid)
105105
TransactionId parent;
106106

107107
/* Can't ask about stuff that might not be around anymore */
108-
Assert(TransactionIdFollowsOrEquals(xid, RecentXmin));
108+
Assert(TransactionIdFollowsOrEquals(xid, TransactionXmin));
109109

110110
/* Bootstrap and frozen XIDs have no parent */
111111
if (!TransactionIdIsNormal(xid))
@@ -129,12 +129,12 @@ SubTransGetParent(TransactionId xid)
129129
*
130130
* Returns the topmost transaction of the given transaction id.
131131
*
132-
* Because we cannot look back further than RecentXmin, it is possible
132+
* Because we cannot look back further than TransactionXmin, it is possible
133133
* that this function will lie and return an intermediate subtransaction ID
134134
* instead of the true topmost parent ID. This is OK, because in practice
135135
* we only care about detecting whether the topmost parent is still running
136136
* or is part of a current snapshot's list of still-running transactions.
137-
* Therefore, any XID before RecentXmin is as good as any other.
137+
* Therefore, any XID before TransactionXmin is as good as any other.
138138
*/
139139
TransactionId
140140
SubTransGetTopmostTransaction(TransactionId xid)
@@ -143,12 +143,12 @@ SubTransGetTopmostTransaction(TransactionId xid)
143143
previousXid = xid;
144144

145145
/* Can't ask about stuff that might not be around anymore */
146-
Assert(TransactionIdFollowsOrEquals(xid, RecentXmin));
146+
Assert(TransactionIdFollowsOrEquals(xid, TransactionXmin));
147147

148148
while (TransactionIdIsValid(parentXid))
149149
{
150150
previousXid = parentXid;
151-
if (TransactionIdPrecedes(parentXid, RecentXmin))
151+
if (TransactionIdPrecedes(parentXid, TransactionXmin))
152152
break;
153153
parentXid = SubTransGetParent(parentXid);
154154
}
@@ -312,7 +312,7 @@ ExtendSUBTRANS(TransactionId newestXact)
312312
* Remove all SUBTRANS segments before the one holding the passed transaction ID
313313
*
314314
* This is normally called during checkpoint, with oldestXact being the
315-
* oldest XMIN of any running transaction.
315+
* oldest TransactionXmin of any running transaction.
316316
*/
317317
void
318318
TruncateSUBTRANS(TransactionId oldestXact)

src/backend/access/transam/transam.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/transam/transam.c,v 1.61 2004/08/29 05:06:40 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/transam/transam.c,v 1.62 2004/09/16 18:35:20 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains the high level access-method interface to the
@@ -200,15 +200,15 @@ TransactionIdDidCommit(TransactionId transactionId)
200200

201201
/*
202202
* If it's marked subcommitted, we have to check the parent
203-
* recursively. However, if it's older than RecentXmin, we can't look
204-
* at pg_subtrans; instead assume that the parent crashed without
203+
* recursively. However, if it's older than TransactionXmin, we can't
204+
* look at pg_subtrans; instead assume that the parent crashed without
205205
* cleaning up its children.
206206
*/
207207
if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
208208
{
209209
TransactionId parentXid;
210210

211-
if (TransactionIdPrecedes(transactionId, RecentXmin))
211+
if (TransactionIdPrecedes(transactionId, TransactionXmin))
212212
return false;
213213
parentXid = SubTransGetParent(transactionId);
214214
Assert(TransactionIdIsValid(parentXid));
@@ -249,15 +249,15 @@ TransactionIdDidAbort(TransactionId transactionId)
249249

250250
/*
251251
* If it's marked subcommitted, we have to check the parent
252-
* recursively. However, if it's older than RecentXmin, we can't look
253-
* at pg_subtrans; instead assume that the parent crashed without
252+
* recursively. However, if it's older than TransactionXmin, we can't
253+
* look at pg_subtrans; instead assume that the parent crashed without
254254
* cleaning up its children.
255255
*/
256256
if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
257257
{
258258
TransactionId parentXid;
259259

260-
if (TransactionIdPrecedes(transactionId, RecentXmin))
260+
if (TransactionIdPrecedes(transactionId, TransactionXmin))
261261
return true;
262262
parentXid = SubTransGetParent(transactionId);
263263
Assert(TransactionIdIsValid(parentXid));

src/backend/storage/ipc/sinval.c

+23-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.73 2004/09/06 23:33:35 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.74 2004/09/16 18:35:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -521,7 +521,8 @@ TransactionIdIsInProgress(TransactionId xid)
521521
bool locked;
522522

523523
/*
524-
* Don't bother checking a very old transaction.
524+
* Don't bother checking a transaction older than RecentXmin; it
525+
* could not possibly still be running.
525526
*/
526527
if (TransactionIdPrecedes(xid, RecentXmin))
527528
{
@@ -732,10 +733,19 @@ GetOldestXmin(bool allDbs)
732733
* This ensures that the set of transactions seen as "running" by the
733734
* current xact will not change after it takes the snapshot.
734735
*
735-
* We also compute the current global xmin (oldest xmin across all running
736-
* transactions) and save it in RecentGlobalXmin. This is the same
737-
* computation done by GetOldestXmin(TRUE). The xmin value is also stored
738-
* into RecentXmin.
736+
* Note that only top-level XIDs are included in the snapshot. We can
737+
* still apply the xmin and xmax limits to subtransaction XIDs, but we
738+
* need to work a bit harder to see if XIDs in [xmin..xmax) are running.
739+
*
740+
* We also update the following backend-global variables:
741+
* TransactionXmin: the oldest xmin of any snapshot in use in the
742+
* current transaction (this is the same as MyProc->xmin). This
743+
* is just the xmin computed for the first, serializable snapshot.
744+
* RecentXmin: the xmin computed for the most recent snapshot. XIDs
745+
* older than this are known not running any more.
746+
* RecentGlobalXmin: the global xmin (oldest TransactionXmin across all
747+
* running transactions). This is the same computation done by
748+
* GetOldestXmin(TRUE).
739749
*----------
740750
*/
741751
Snapshot
@@ -751,6 +761,11 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
751761

752762
Assert(snapshot != NULL);
753763

764+
/* Serializable snapshot must be computed before any other... */
765+
Assert(serializable ?
766+
!TransactionIdIsValid(MyProc->xmin) :
767+
TransactionIdIsValid(MyProc->xmin));
768+
754769
/*
755770
* Allocating space for MaxBackends xids is usually overkill;
756771
* lastBackend would be sufficient. But it seems better to do the
@@ -850,13 +865,10 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
850865
}
851866

852867
if (serializable)
853-
MyProc->xmin = xmin;
868+
MyProc->xmin = TransactionXmin = xmin;
854869

855870
LWLockRelease(SInvalLock);
856871

857-
/* Serializable snapshot must be computed before any other... */
858-
Assert(TransactionIdIsValid(MyProc->xmin));
859-
860872
/*
861873
* Update globalxmin to include actual process xids. This is a
862874
* slightly different way of computing it than GetOldestXmin uses, but
@@ -865,7 +877,7 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
865877
if (TransactionIdPrecedes(xmin, globalxmin))
866878
globalxmin = xmin;
867879

868-
/* Update globals for use by VACUUM */
880+
/* Update global variables too */
869881
RecentGlobalXmin = globalxmin;
870882
RecentXmin = xmin;
871883

src/backend/utils/time/tqual.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Portions Copyright (c) 1994, Regents of the University of California
1717
*
1818
* IDENTIFICATION
19-
* $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.78 2004/09/13 20:07:36 tgl Exp $
19+
* $PostgreSQL: pgsql/src/backend/utils/time/tqual.c,v 1.79 2004/09/16 18:35:22 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -48,6 +48,7 @@ Snapshot LatestSnapshot = NULL;
4848
Snapshot ActiveSnapshot = NULL;
4949

5050
/* These are updated by GetSnapshotData: */
51+
TransactionId TransactionXmin = InvalidTransactionId;
5152
TransactionId RecentXmin = InvalidTransactionId;
5253
TransactionId RecentGlobalXmin = InvalidTransactionId;
5354

src/include/utils/tqual.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.52 2004/09/13 20:08:35 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.53 2004/09/16 18:35:23 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -59,6 +59,7 @@ extern DLLIMPORT Snapshot SerializableSnapshot;
5959
extern DLLIMPORT Snapshot LatestSnapshot;
6060
extern DLLIMPORT Snapshot ActiveSnapshot;
6161

62+
extern TransactionId TransactionXmin;
6263
extern TransactionId RecentXmin;
6364
extern TransactionId RecentGlobalXmin;
6465

0 commit comments

Comments
 (0)