]> granicus.if.org Git - postgresql/commitdiff
TransferPredicateLocksToNewTarget should initialize a new lock
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 11 Apr 2011 10:46:37 +0000 (13:46 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 11 Apr 2011 10:46:37 +0000 (13:46 +0300)
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.

Dan Ports, to fix leak of predicate locks reported by YAMAMOTO Takashi.

src/backend/storage/lmgr/predicate.c

index eceb384e581fb7370bae11f074a9a495070881b0..f02d5d5a1e465db2e54f466c1ce538c2fdb5c5b5 100644 (file)
@@ -2074,7 +2074,7 @@ CreatePredicateLock(const PREDICATELOCKTARGETTAG *targettag,
                SHMQueueInsertBefore(&(target->predicateLocks), &(lock->targetLink));
                SHMQueueInsertBefore(&(sxact->predicateLocks),
                                                         &(lock->xactLink));
-               lock->commitSeqNo = 0;
+               lock->commitSeqNo = InvalidSerCommitSeqNo;
        }
 
        LWLockRelease(partitionLock);
@@ -2508,6 +2508,7 @@ TransferPredicateLocksToNewTarget(const PREDICATELOCKTARGETTAG oldtargettag,
                        SHM_QUEUE  *predlocktargetlink;
                        PREDICATELOCK *nextpredlock;
                        PREDICATELOCK *newpredlock;
+                       SerCommitSeqNo oldCommitSeqNo = oldpredlock->commitSeqNo;
 
                        predlocktargetlink = &(oldpredlock->targetLink);
                        nextpredlock = (PREDICATELOCK *)
@@ -2552,8 +2553,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;
                }
@@ -3137,6 +3147,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);
 
@@ -3261,6 +3273,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;
                        }