pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dan Ports <drkp@csail.mit.edu>
To: pgsql-hackers@postgresql.org
Cc: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
Cc: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>
Subject: Re: SSI bug?
Date: Sun, 3 Apr 2011 02:16:44 -0400
Message-ID: <20110403061644.GS81592@csail.mit.edu> (raw)
In-Reply-To: <4D943BEC020000250003BFDA@gw.wicourts.gov>
References: <4D8F54E6020000250003BD16@gw.wicourts.gov>
	<4D8F54E6020000250003BD16@gw.wicourts.gov>
	<20110328031616.CDAA719CEDF@mail.netbsd.org>
	<4D943BEC020000250003BFDA@gw.wicourts.gov>

I think I see what is going on now. We are sometimes failing to set the
commitSeqNo correctly on the lock. In particular, if a lock assigned to
OldCommittedSxact is marked with InvalidSerCommitNo, it will never be
cleared.

The attached patch corrects this:
 TransferPredicateLocksToNewTarget should initialize a new lock
 entry's commitSeqNo to that of the old one being transferred, or take
 the minimum commitSeqNo if it is merging two lock entries.

 Also, CreatePredicateLock should initialize commitSeqNo for to
 InvalidSerCommitSeqNo instead of to 0. (I don't think using 0 would
 actually affect anything, but we should be consistent.)

 I also added a couple of assertions I used to track this down: a
 lock's commitSeqNo should never be zero, and it should be
 InvalidSerCommitSeqNo if and only if the lock is not held by
 OldCommittedSxact.

Takashi, does this patch fix your problem with leaked SIReadLocks?

Dan


-- 
Dan R. K. Ports              MIT CSAIL                http://drkp.net/

Attachments:

patch-commitseqno.diff (text/x-diff, 2.3K) download diff --git a/src/backend/storage/lmgr/predicate.c b/src/backend/storage/lmgr/predicate.c index f6e49fe..d166da3 100644 --- a/src/backend/storage/lmgr/predicate.c +++ b/src/backend/storage/lmgr/predicate.c @@ -2067,7 +2067,7 @@ CreatePredicateLock(const PREDICATELOCKTARGETTAG *targettag, SHMQueueInsertBefore(&(target->predicateLocks), &(lock->targetLink)); SHMQueueInsertBefore(&(sxact->predicateLocks), &(lock->xactLink)); - lock->commitSeqNo = 0; + lock->commitSeqNo = InvalidSerCommitSeqNo; } LWLockRelease(partitionLock); @@ -2500,6 +2500,7 @@ TransferPredicateLocksToNewTarget(const PREDICATELOCKTARGETTAG oldtargettag, SHM_QUEUE *predlocktargetlink; PREDICATELOCK *nextpredlock; PREDICATELOCK *newpredlock; + SerCommitSeqNo oldCommitSeqNo = oldpredlock->commitSeqNo; predlocktargetlink = &(oldpredlock->targetLink); nextpredlock = (PREDICATELOCK *) @@ -2544,8 +2545,17 @@ TransferPredicateLocksToNewTarget(const PREDICATELOCKTARGETTAG oldtargettag, &(newpredlock->targetLink)); SHMQueueInsertBefore(&(newpredlocktag.myXact->predicateLocks), &(newpredlock->xactLink)); - newpredlock->commitSeqNo = InvalidSerCommitSeqNo; + newpredlock->commitSeqNo = oldCommitSeqNo; } + else + { + if (newpredlock->commitSeqNo < oldCommitSeqNo) + newpredlock->commitSeqNo = oldCommitSeqNo; + } + + Assert(newpredlock->commitSeqNo != 0); + Assert((newpredlock->commitSeqNo == InvalidSerCommitSeqNo) + || (newpredlock->tag.myXact == OldCommittedSxact)); oldpredlock = nextpredlock; } @@ -3130,6 +3140,8 @@ ClearOldPredicateLocks(void) offsetof(PREDICATELOCK, xactLink)); LWLockAcquire(SerializableXactHashLock, LW_SHARED); + Assert(predlock->commitSeqNo != 0); + Assert(predlock->commitSeqNo != InvalidSerCommitSeqNo); canDoPartialCleanup = (predlock->commitSeqNo <= PredXact->CanPartialClearThrough); LWLockRelease(SerializableXactHashLock); @@ -3254,6 +3266,8 @@ ReleaseOneSerializableXact(SERIALIZABLEXACT *sxact, bool partial, errhint("You might need to increase max_pred_locks_per_transaction."))); if (found) { + Assert(predlock->commitSeqNo != 0); + Assert(predlock->commitSeqNo != InvalidSerCommitSeqNo); if (predlock->commitSeqNo < sxact->commitSeqNo) predlock->commitSeqNo = sxact->commitSeqNo; }

view thread (71+ messages)  latest in thread

Message-ID: <20110403061644.GS81592@csail.mit.edu>
Permalink:  ../20110403061644.GS81592@csail.mit.edu/
Also on:    postgresql.org/message-id/20110403061644.GS81592@csail.mit.edu

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: drkp@csail.mit.edu, yamt@mwd.biglobe.ne.jp, Kevin.Grittner@wicourts.gov, heikki.linnakangas@enterprisedb.com
  Subject: Re: SSI bug?
  In-Reply-To: <20110403061644.GS81592@csail.mit.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox