aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2008-05-12 20:02:02 +0000
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2008-05-12 20:02:02 +0000
commit5da9da71c44f27ba48fdad08ef263bf70e43e689 (patch)
treed8afb52acd9386a59c1862a265d4f8e6d2fdbaba /src/backend/access/transam/xact.c
parentaa82790fcab98b8d3d4eca2e2f6f7bfce57870bc (diff)
downloadpostgresql-5da9da71c44f27ba48fdad08ef263bf70e43e689.tar.gz
postgresql-5da9da71c44f27ba48fdad08ef263bf70e43e689.zip
Improve snapshot manager by keeping explicit track of snapshots.
There are two ways to track a snapshot: there's the "registered" list, which is used for arbitrary long-lived snapshots; and there's the "active stack", which is used for the snapshot that is considered "active" at any time. This also allows users of snapshots to stop worrying about snapshot memory allocation and freeing, and about using PG_TRY blocks around ActiveSnapshot assignment. This is all done automatically now. As a consequence, this allows us to reset MyProc->xmin when there are no more snapshots registered in the current backend, reducing the impact that long-running transactions have on VACUUM.
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r--src/backend/access/transam/xact.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index f1200af8ee2..10645b2b7fb 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.263 2008/05/12 00:00:46 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.264 2008/05/12 20:01:58 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -622,12 +622,9 @@ CommandCounterIncrement(void)
}
currentCommandIdUsed = false;
- /* Propagate new command ID into static snapshots, if set */
- if (SerializableSnapshot)
- SerializableSnapshot->curcid = currentCommandId;
- if (LatestSnapshot)
- LatestSnapshot->curcid = currentCommandId;
-
+ /* Propagate new command ID into static snapshots */
+ SnapshotSetCommandId(currentCommandId);
+
/*
* Make any catalog changes done by the just-completed command
* visible in the local syscache. We obviously don't need to do
@@ -1509,9 +1506,8 @@ StartTransaction(void)
s->transactionId = InvalidTransactionId; /* until assigned */
/*
- * Make sure we've freed any old snapshot, and reset xact state variables
+ * Make sure we've reset xact state variables
*/
- FreeXactSnapshot();
XactIsoLevel = DefaultXactIsoLevel;
XactReadOnly = DefaultXactReadOnly;
forceSyncCommit = false;
@@ -1753,6 +1749,7 @@ CommitTransaction(void)
AtEOXact_ComboCid();
AtEOXact_HashTables(true);
AtEOXact_PgStat(true);
+ AtEOXact_Snapshot(true);
pgstat_report_xact_timestamp(0);
CurrentResourceOwner = NULL;
@@ -1985,6 +1982,7 @@ PrepareTransaction(void)
AtEOXact_ComboCid();
AtEOXact_HashTables(true);
/* don't call AtEOXact_PgStat here */
+ AtEOXact_Snapshot(true);
CurrentResourceOwner = NULL;
ResourceOwnerDelete(TopTransactionResourceOwner);
@@ -2129,6 +2127,7 @@ AbortTransaction(void)
AtEOXact_ComboCid();
AtEOXact_HashTables(false);
AtEOXact_PgStat(false);
+ AtEOXact_Snapshot(false);
pgstat_report_xact_timestamp(0);
/*
@@ -3844,6 +3843,7 @@ CommitSubTransaction(void)
s->parent->subTransactionId);
AtEOSubXact_HashTables(true, s->nestingLevel);
AtEOSubXact_PgStat(true, s->nestingLevel);
+ AtSubCommit_Snapshot(s->nestingLevel);
/*
* We need to restore the upper transaction's read-only state, in case the
@@ -3963,6 +3963,7 @@ AbortSubTransaction(void)
s->parent->subTransactionId);
AtEOSubXact_HashTables(false, s->nestingLevel);
AtEOSubXact_PgStat(false, s->nestingLevel);
+ AtSubAbort_Snapshot(s->nestingLevel);
}
/*