aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-01-26 19:16:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-01-26 19:16:23 +0000
commita51d4b8dc02b777080e6250b7164f5961cc59c84 (patch)
treea9078731c3b3f3201b9945515999d38e070a3f56
parentac760b6bff6022f294c0d988f07e80abc0ac7a69 (diff)
downloadpostgresql-a51d4b8dc02b777080e6250b7164f5961cc59c84.tar.gz
postgresql-a51d4b8dc02b777080e6250b7164f5961cc59c84.zip
Repair incorrect order of operations in GetNewTransactionId(). We must
complete ExtendCLOG() before advancing nextXid, so that if that routine fails, the next incoming transaction will try it again. Per trouble report from Christopher Kings-Lynne.
-rw-r--r--src/backend/access/transam/varsup.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c
index ae2032bccf0..e3cb0108910 100644
--- a/src/backend/access/transam/varsup.c
+++ b/src/backend/access/transam/varsup.c
@@ -6,7 +6,7 @@
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.52 2003/08/04 23:59:37 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.52.4.1 2004/01/26 19:16:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -45,10 +45,8 @@ GetNewTransactionId(void)
xid = ShmemVariableCache->nextXid;
- TransactionIdAdvance(ShmemVariableCache->nextXid);
-
/*
- * If we have just allocated the first XID of a new page of the commit
+ * If we are allocating the first XID of a new page of the commit
* log, zero out that commit-log page before returning. We must do
* this while holding XidGenLock, else another xact could acquire and
* commit a later XID before we zero the page. Fortunately, a page of
@@ -58,6 +56,14 @@ GetNewTransactionId(void)
ExtendCLOG(xid);
/*
+ * Now advance the nextXid counter. This must not happen until after
+ * we have successfully completed ExtendCLOG() --- if that routine fails,
+ * we want the next incoming transaction to try it again. We cannot
+ * assign more XIDs until there is CLOG space for them.
+ */
+ TransactionIdAdvance(ShmemVariableCache->nextXid);
+
+ /*
* Must set MyProc->xid before releasing XidGenLock. This ensures
* that when GetSnapshotData calls ReadNewTransactionId, all active
* XIDs before the returned value of nextXid are already present in
@@ -74,7 +80,7 @@ GetNewTransactionId(void)
*
* A solution to the atomic-store problem would be to give each PGPROC
* its own spinlock used only for fetching/storing that PGPROC's xid.
- * (SInvalLock would then mean primarily that PROCs couldn't be added/
+ * (SInvalLock would then mean primarily that PGPROCs couldn't be added/
* removed while holding the lock.)
*/
if (MyProc != (PGPROC *) NULL)