Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit86fff99

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 usein the current top transaction. Introduce a new variable TransactionXminto play this role. Fixes intermittent regression failure reported byNeil Conway.
1 parent8f9f198 commit86fff99

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

‎src/backend/access/transam/subtrans.c

Lines changed: 7 additions & 7 deletions
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
TransactionIdparent;
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 thanRecentXmin, it is possible
132+
* Because we cannot look back further thanTransactionXmin, 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 beforeRecentXmin is as good as any other.
137+
* Therefore, any XID beforeTransactionXmin is as good as any other.
138138
*/
139139
TransactionId
140140
SubTransGetTopmostTransaction(TransactionIdxid)
@@ -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-
* oldestXMIN of any running transaction.
315+
* oldestTransactionXmin of any running transaction.
316316
*/
317317
void
318318
TruncateSUBTRANS(TransactionIdoldestXact)

‎src/backend/access/transam/transam.c

Lines changed: 7 additions & 7 deletions
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 thanRecentXmin, we can't look
204-
* at pg_subtrans; instead assume that the parent crashed without
203+
* recursively. However, if it's older thanTransactionXmin, we can't
204+
*lookat pg_subtrans; instead assume that the parent crashed without
205205
* cleaning up its children.
206206
*/
207207
if (xidstatus==TRANSACTION_STATUS_SUB_COMMITTED)
208208
{
209209
TransactionIdparentXid;
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 thanRecentXmin, we can't look
253-
* at pg_subtrans; instead assume that the parent crashed without
252+
* recursively. However, if it's older thanTransactionXmin, we can't
253+
*lookat pg_subtrans; instead assume that the parent crashed without
254254
* cleaning up its children.
255255
*/
256256
if (xidstatus==TRANSACTION_STATUS_SUB_COMMITTED)
257257
{
258258
TransactionIdparentXid;
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

Lines changed: 23 additions & 11 deletions
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
boollocked;
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-
/* Updateglobals for use by VACUUM */
880+
/* Updateglobal variables too */
869881
RecentGlobalXmin=globalxmin;
870882
RecentXmin=xmin;
871883

‎src/backend/utils/time/tqual.c

Lines changed: 2 additions & 1 deletion
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 @@ SnapshotLatestSnapshot = NULL;
4848
SnapshotActiveSnapshot=NULL;
4949

5050
/* These are updated by GetSnapshotData: */
51+
TransactionIdTransactionXmin=InvalidTransactionId;
5152
TransactionIdRecentXmin=InvalidTransactionId;
5253
TransactionIdRecentGlobalXmin=InvalidTransactionId;
5354

‎src/include/utils/tqual.h

Lines changed: 2 additions & 1 deletion
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
externDLLIMPORTSnapshotLatestSnapshot;
6060
externDLLIMPORTSnapshotActiveSnapshot;
6161

62+
externTransactionIdTransactionXmin;
6263
externTransactionIdRecentXmin;
6364
externTransactionIdRecentGlobalXmin;
6465

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp