summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2016-05-05 10:02:08 +0000
committerPavan Deolasee2016-10-18 10:05:07 +0000
commit47c7bcd9ac699311c7d2df04793fced7f69620c8 (patch)
treeac509ca6199f51e72e46fa684e9ee8d5756a3a28
parentdecc2d6a71f688de6ae966f4ed8cfeadc11eb367 (diff)
Honour shared queue refcount while deciding to remove it from hash table when
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.
-rw-r--r--src/backend/pgxc/squeue/squeue.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/backend/pgxc/squeue/squeue.c b/src/backend/pgxc/squeue/squeue.c
index 0d2844aa5c..a938571147 100644
--- a/src/backend/pgxc/squeue/squeue.c
+++ b/src/backend/pgxc/squeue/squeue.c
@@ -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);
}