diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-01-18 17:09:44 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-01-18 17:12:58 +0200 |
commit | 02f377dbe50074a7016f4a476a8d15d294cd0874 (patch) | |
tree | 8e768e1a7bde8cc0fac1b4a8f35d2b3118d061bc | |
parent | ef007e67022bf7f2367aa10fd226d6fb86b6fb9c (diff) | |
download | postgresql-02f377dbe50074a7016f4a476a8d15d294cd0874.tar.gz postgresql-02f377dbe50074a7016f4a476a8d15d294cd0874.zip |
Fix corner case in cleanup of transactions using SSI.
When the only remaining active transactions are READ ONLY, we do a "partial
cleanup" of committed transactions because certain types of conflicts
aren't possible anymore. For committed r/w transactions, we release the
SIREAD locks but keep the SERIALIZABLEXACT. However, for committed r/o
transactions, we can go further and release the SERIALIZABLEXACT too. The
problem was with the latter case: we were returning the SERIALIZABLEXACT to
the free list without removing it from the finished list.
The only real change in the patch is the SHMQueueDelete line, but I also
reworked some of the surrounding code to make it obvious that r/o and r/w
transactions are handled differently -- the existing code felt a bit too
clever.
Dan Ports
-rw-r--r-- | src/backend/storage/lmgr/predicate.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c index 1754180453d..27124672da9 100644 --- a/src/backend/storage/lmgr/predicate.c +++ b/src/backend/storage/lmgr/predicate.c @@ -3457,10 +3457,29 @@ ClearOldPredicateLocks(void) else if (finishedSxact->commitSeqNo > PredXact->HavePartialClearedThrough && finishedSxact->commitSeqNo <= PredXact->CanPartialClearThrough) { + /* + * Any active transactions that took their snapshot before this + * transaction committed are read-only, so we can clear part of + * its state. + */ LWLockRelease(SerializableXactHashLock); - ReleaseOneSerializableXact(finishedSxact, - !SxactIsReadOnly(finishedSxact), - false); + + if (SxactIsReadOnly(finishedSxact)) + { + /* A read-only transaction can be removed entirely */ + SHMQueueDelete(&(finishedSxact->finishedLink)); + ReleaseOneSerializableXact(finishedSxact, false, false); + } + else + { + /* + * A read-write transaction can only be partially + * cleared. We need to keep the SERIALIZABLEXACT but + * can release the SIREAD locks and conflicts in. + */ + ReleaseOneSerializableXact(finishedSxact, true, false); + } + PredXact->HavePartialClearedThrough = finishedSxact->commitSeqNo; LWLockAcquire(SerializableXactHashLock, LW_SHARED); } @@ -3566,6 +3585,7 @@ ReleaseOneSerializableXact(SERIALIZABLEXACT *sxact, bool partial, Assert(sxact != NULL); Assert(SxactIsRolledBack(sxact) || SxactIsCommitted(sxact)); + Assert(partial || !SxactIsOnFinishedList(sxact)); Assert(LWLockHeldByMe(SerializableFinishedListLock)); /* |