diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-09-08 20:31:15 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-09-08 20:31:15 +0000 |
commit | 6bd4f401b0cb85f2e81caffc457e415e15e2ed5d (patch) | |
tree | a0edebb698a1a288be3e66c064c36399cbf5f93f /src/backend/access/transam/twophase.c | |
parent | 0a51e7073c045b5fce50092dae19f398f7b38e16 (diff) |
Replace the former method of determining snapshot xmax --- to wit, calling
ReadNewTransactionId from GetSnapshotData --- with a "latestCompletedXid"
variable that is updated during transaction commit or abort. Since
latestCompletedXid is written only in places that had to lock ProcArrayLock
exclusively anyway, and is read only in places that had to lock ProcArrayLock
shared anyway, it adds no new locking requirements to the system despite being
cluster-wide. Moreover, removing ReadNewTransactionId from snapshot
acquisition eliminates the need to take both XidGenLock and ProcArrayLock at
the same time. Since XidGenLock is sometimes held across I/O this can be a
significant win. Some preliminary benchmarking suggested that this patch has
no effect on average throughput but can significantly improve the worst-case
transaction times seen in pgbench. Concept by Florian Pflug, implementation
by Tom Lane.
Diffstat (limited to 'src/backend/access/transam/twophase.c')
-rw-r--r-- | src/backend/access/transam/twophase.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index db47e95cf84..03ac9e98e45 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.34 2007/09/05 20:53:17 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.35 2007/09/08 20:31:14 tgl Exp $ * * NOTES * Each global transaction is associated with a global transaction @@ -1127,6 +1127,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit) char *buf; char *bufptr; TwoPhaseFileHeader *hdr; + TransactionId latestXid; TransactionId *children; RelFileNode *commitrels; RelFileNode *abortrels; @@ -1162,6 +1163,9 @@ FinishPreparedTransaction(const char *gid, bool isCommit) abortrels = (RelFileNode *) bufptr; bufptr += MAXALIGN(hdr->nabortrels * sizeof(RelFileNode)); + /* compute latestXid among all children */ + latestXid = TransactionIdLatest(xid, hdr->nsubxacts, children); + /* * The order of operations here is critical: make the XLOG entry for * commit or abort, then mark the transaction committed or aborted in @@ -1179,7 +1183,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit) hdr->nsubxacts, children, hdr->nabortrels, abortrels); - ProcArrayRemove(&gxact->proc); + ProcArrayRemove(&gxact->proc, latestXid); /* * In case we fail while running the callbacks, mark the gxact invalid so |