summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc/sinval.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-09-16 18:35:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-09-16 18:35:23 +0000
commit86fff990b2acdbbfaf4340636878313fe270c916 (patch)
tree1bb9b083366b630a2a835f124b6ad3167b7ab86d /src/backend/storage/ipc/sinval.c
parent8f9f1986034a2273e09ad10671e10d1adda21d1f (diff)
downloadpostgresql-86fff990b2acdbbfaf4340636878313fe270c916.tar.gz
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.
Diffstat (limited to 'src/backend/storage/ipc/sinval.c')
-rw-r--r--src/backend/storage/ipc/sinval.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/backend/storage/ipc/sinval.c b/src/backend/storage/ipc/sinval.c
index 5c4db3da80..4f7d161514 100644
--- a/src/backend/storage/ipc/sinval.c
+++ b/src/backend/storage/ipc/sinval.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.73 2004/09/06 23:33:35 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/ipc/sinval.c,v 1.74 2004/09/16 18:35:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -521,7 +521,8 @@ TransactionIdIsInProgress(TransactionId xid)
bool locked;
/*
- * Don't bother checking a very old transaction.
+ * Don't bother checking a transaction older than RecentXmin; it
+ * could not possibly still be running.
*/
if (TransactionIdPrecedes(xid, RecentXmin))
{
@@ -732,10 +733,19 @@ GetOldestXmin(bool allDbs)
* This ensures that the set of transactions seen as "running" by the
* current xact will not change after it takes the snapshot.
*
- * We also compute the current global xmin (oldest xmin across all running
- * transactions) and save it in RecentGlobalXmin. This is the same
- * computation done by GetOldestXmin(TRUE). The xmin value is also stored
- * into RecentXmin.
+ * Note that only top-level XIDs are included in the snapshot. We can
+ * still apply the xmin and xmax limits to subtransaction XIDs, but we
+ * need to work a bit harder to see if XIDs in [xmin..xmax) are running.
+ *
+ * We also update the following backend-global variables:
+ * TransactionXmin: the oldest xmin of any snapshot in use in the
+ * current transaction (this is the same as MyProc->xmin). This
+ * is just the xmin computed for the first, serializable snapshot.
+ * RecentXmin: the xmin computed for the most recent snapshot. XIDs
+ * older than this are known not running any more.
+ * RecentGlobalXmin: the global xmin (oldest TransactionXmin across all
+ * running transactions). This is the same computation done by
+ * GetOldestXmin(TRUE).
*----------
*/
Snapshot
@@ -751,6 +761,11 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
Assert(snapshot != NULL);
+ /* Serializable snapshot must be computed before any other... */
+ Assert(serializable ?
+ !TransactionIdIsValid(MyProc->xmin) :
+ TransactionIdIsValid(MyProc->xmin));
+
/*
* Allocating space for MaxBackends xids is usually overkill;
* lastBackend would be sufficient. But it seems better to do the
@@ -850,13 +865,10 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
}
if (serializable)
- MyProc->xmin = xmin;
+ MyProc->xmin = TransactionXmin = xmin;
LWLockRelease(SInvalLock);
- /* Serializable snapshot must be computed before any other... */
- Assert(TransactionIdIsValid(MyProc->xmin));
-
/*
* Update globalxmin to include actual process xids. This is a
* slightly different way of computing it than GetOldestXmin uses, but
@@ -865,7 +877,7 @@ GetSnapshotData(Snapshot snapshot, bool serializable)
if (TransactionIdPrecedes(xmin, globalxmin))
globalxmin = xmin;
- /* Update globals for use by VACUUM */
+ /* Update global variables too */
RecentGlobalXmin = globalxmin;
RecentXmin = xmin;