From: Tomas Vondra Date: Mon, 9 Jan 2017 20:52:56 +0000 (+0100) Subject: fix SharedQueuesInit to register the tranche properly X-Git-Tag: XL_10_R1BETA1~490 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=512af227199a480f74b2906ab534a07453e80c28;p=postgres-xl.git fix SharedQueuesInit to register the tranche properly The code was mixing code for named and regular tranches (identified by just ID, in this case LWTRANCHE_SHARED_QUEUES). So switch to the LWLockRegisterTranche() approach. There were a two more bugs though: 1) The tranche struct was local in the block, which does not work as it's referenced in the global array without creating a copy. So just make it static and global. 2) The locks were not properly initialized. Add a LWLockInitialize call to the loop. --- diff --git a/src/backend/pgxc/squeue/squeue.c b/src/backend/pgxc/squeue/squeue.c index fdc67551fb..4fbae5b31b 100644 --- a/src/backend/pgxc/squeue/squeue.c +++ b/src/backend/pgxc/squeue/squeue.c @@ -120,6 +120,7 @@ typedef struct SQueueHeader */ static HTAB *SharedQueues = NULL; static LWLockPadded *SQueueLocks = NULL; +static LWLockTranche SharedQueueLocksTranche; /* * Pool of synchronization items @@ -224,19 +225,21 @@ SharedQueuesInit(void) { int i, l; int nlocks = (NUM_SQUEUES * (MaxDataNodes-1)); - LWLockTranche tranche; + bool foundLocks; /* Initialize LWLocks for queues */ - SQueueLocks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * nlocks); + SQueueLocks = (LWLockPadded *) ShmemInitStruct("Shared Queue Locks", + sizeof(LWLockPadded) * nlocks, &foundLocks); - tranche.name = "Shared Queue Locks"; - tranche.array_base = SQueueLocks; - tranche.array_stride = sizeof(LWLockPadded); + /* either both syncs and locks, or none of them */ + Assert(! foundLocks); - /* Register the trannche tranche in the main tranches array */ - LWLockRegisterTranche(LWTRANCHE_SHARED_QUEUES, &tranche); + SharedQueueLocksTranche.name = "Shared Queue Locks"; + SharedQueueLocksTranche.array_base = SQueueLocks; + SharedQueueLocksTranche.array_stride = sizeof(LWLockPadded); - Assert(SQueueLocks == GetNamedLWLockTranche("Shared Queue Locks")); + /* Register the trannche tranche in the main tranches array */ + LWLockRegisterTranche(LWTRANCHE_SHARED_QUEUES, &SharedQueueLocksTranche); l = 0; for (i = 0; i < NUM_SQUEUES; i++) @@ -249,6 +252,10 @@ SharedQueuesInit(void) for (j = 0; j < MaxDataNodes-1; j++) { InitSharedLatch(&sqs->sqs_consumer_sync[j].cs_latch); + + LWLockInitialize(&(SQueueLocks[l]).lock, + LWTRANCHE_SHARED_QUEUES); + sqs->sqs_consumer_sync[j].cs_lwlock = &(SQueueLocks[l++]).lock; } }