YAMAMOTO Takashi <y...@mwd.biglobe.ne.jp> wrote:
 
> hoge=# select locktype,count(*) from pg_locks group by locktype;  
> -[ RECORD 1 ]--------
> locktype | virtualxid
> count    | 1
> -[ RECORD 2 ]--------
> locktype | relation
> count    | 1
> -[ RECORD 3 ]--------
> locktype | tuple
> count    | 7061
 
I've stared at the code for hours and have only come up with one
race condition which can cause this, although the window is so small
it's hard to believe that you would get this volume of orphaned
locks.  I'll keep looking, but if you could try this to see if it
has a material impact, that would be great.
 
I am very sure this patch is needed and that it is safe.  It moves a
LWLockAcquire statement up to cover the setup for the loop that it
already covers.  It also includes a fix to a comment that got missed
when we switched from the pointer between lock targets to
duplicating the locks.
 
-Kevin

*** a/src/backend/storage/lmgr/predicate.c
--- b/src/backend/storage/lmgr/predicate.c
***************
*** 1755,1763 **** CoarserLockCovers(const PREDICATELOCKTARGETTAG *newtargettag)
  }
  
  /*
!  * Check whether both the list of related predicate locks and the pointer to
!  * a prior version of the row (if this is a tuple lock target) are empty for
!  * a predicate lock target, and remove the target if they are.
   */
  static void
  RemoveTargetIfNoLongerUsed(PREDICATELOCKTARGET *target, uint32 targettaghash)
--- 1755,1762 ----
  }
  
  /*
!  * Check whether the list of related predicate locks is empty for a
!  * predicate lock target, and remove the target if it is.
   */
  static void
  RemoveTargetIfNoLongerUsed(PREDICATELOCKTARGET *target, uint32 targettaghash)
***************
*** 3120,3130 **** ClearOldPredicateLocks(void)
        /*
         * Loop through predicate locks on dummy transaction for summarized 
data.
         */
        predlock = (PREDICATELOCK *)
                SHMQueueNext(&OldCommittedSxact->predicateLocks,
                                         &OldCommittedSxact->predicateLocks,
                                         offsetof(PREDICATELOCK, xactLink));
-       LWLockAcquire(SerializablePredicateLockListLock, LW_SHARED);
        while (predlock)
        {
                PREDICATELOCK *nextpredlock;
--- 3119,3129 ----
        /*
         * Loop through predicate locks on dummy transaction for summarized 
data.
         */
+       LWLockAcquire(SerializablePredicateLockListLock, LW_SHARED);
        predlock = (PREDICATELOCK *)
                SHMQueueNext(&OldCommittedSxact->predicateLocks,
                                         &OldCommittedSxact->predicateLocks,
                                         offsetof(PREDICATELOCK, xactLink));
        while (predlock)
        {
                PREDICATELOCK *nextpredlock;
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to