Honour shared queue refcount while deciding to remove it from hash table when
authorPavan Deolasee <[email protected]>
Thu, 5 May 2016 10:02:08 +0000 (15:32 +0530)
committerPavan Deolasee <[email protected]>
Thu, 5 May 2016 10:02:08 +0000 (15:32 +0530)
producer unbinds

It's possible that another execution of the portal may start just while we are
unbinding. Hence premature removal of the shared queue should be avoided.

src/backend/pgxc/squeue/squeue.c

index 0d2844aa5c9e7ad5ca0410f828d6324e5cd097db..a93857114707285f2c35fc399b7df9a9151751bc 100644 (file)
@@ -1448,23 +1448,17 @@ CHECK:
                goto CHECK;
        }
 
-       /*
-        * XXX Decrement the refcnt, but it doesn't really matter because we are
-        * unconditionally removing the SQueue anyways. SharedQueueRelease is
-        * prepared to work with already removed SQueue
-        *
-        * This ought to be fixed someday
-        */
-       squeue->sq_refcnt--;
-       
        /* All is done, clean up */
        DisownLatch(&sqsync->sqs_producer_latch);
 
-       /* Now it is OK to remove hash table entry */
-       squeue->sq_sync = NULL;
-       sqsync->queue = NULL;
-       if (hash_search(SharedQueues, squeue->sq_key, HASH_REMOVE, NULL) != squeue)
-               elog(PANIC, "Shared queue data corruption");
+       if (--squeue->sq_refcnt == 0)
+       {
+               /* Now it is OK to remove hash table entry */
+               squeue->sq_sync = NULL;
+               sqsync->queue = NULL;
+               if (hash_search(SharedQueues, squeue->sq_key, HASH_REMOVE, NULL) != squeue)
+                       elog(PANIC, "Shared queue data corruption");
+       }
 
        LWLockRelease(SQueuesLock);
 }