Skip to content

Commit fe400d0

Browse files
committed
[refer #PGPRO-6601]: Removed "init_lock_tag" function which interferes with
the same named function in the AQO extension. Init the "receiver" shared memory queue more carefully using an "ExclusiveLock" lock. Tags: pg_wait_sampling.
1 parent e17ab38 commit fe400d0

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

collector.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,9 @@ collector_main(Datum main_arg)
445445
/* Handle request if any */
446446
if (collector_hdr->request != NO_REQUEST)
447447
{
448-
LOCKTAG tag;
449448
SHMRequest request;
450449

451-
init_lock_tag(&tag, PGWS_COLLECTOR_LOCK);
452-
453-
LockAcquire(&tag, ExclusiveLock, false, false);
450+
LockAcquire(&collectorTag, ExclusiveLock, false, false);
454451
request = collector_hdr->request;
455452
collector_hdr->request = NO_REQUEST;
456453

@@ -494,7 +491,7 @@ collector_main(Datum main_arg)
494491
hash_destroy(profile_hash);
495492
profile_hash = make_profile_hash();
496493
}
497-
LockRelease(&tag, ExclusiveLock, false);
494+
LockRelease(&collectorTag, ExclusiveLock, false);
498495
}
499496
}
500497

pg_wait_sampling.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,24 @@ CollectorShmqHeader *collector_hdr = NULL;
5656
/* Receiver (backend) local shm_mq pointers and lock */
5757
shm_mq *recv_mq = NULL;
5858
shm_mq_handle *recv_mqh = NULL;
59-
LOCKTAG queueTag;
59+
60+
const LOCKTAG queueTag = {
61+
.locktag_field1 = PG_WAIT_SAMPLING_MAGIC,
62+
.locktag_field2 = PGWS_QUEUE_LOCK,
63+
.locktag_field3 = 0,
64+
.locktag_field4 = 0,
65+
.locktag_type = LOCKTAG_USERLOCK,
66+
.locktag_lockmethodid = USER_LOCKMETHOD
67+
};
68+
69+
const LOCKTAG collectorTag = {
70+
.locktag_field1 = PG_WAIT_SAMPLING_MAGIC,
71+
.locktag_field2 = PGWS_COLLECTOR_LOCK,
72+
.locktag_field3 = 0,
73+
.locktag_field4 = 0,
74+
.locktag_type = LOCKTAG_USERLOCK,
75+
.locktag_lockmethodid = USER_LOCKMETHOD
76+
};
6077

6178
#if PG_VERSION_NUM >= 150000
6279
static shmem_request_hook_type prev_shmem_request_hook = NULL;
@@ -563,21 +580,9 @@ typedef struct
563580
ProfileItem *items;
564581
} Profile;
565582

566-
void
567-
init_lock_tag(LOCKTAG *tag, uint32 lock)
568-
{
569-
tag->locktag_field1 = PG_WAIT_SAMPLING_MAGIC;
570-
tag->locktag_field2 = lock;
571-
tag->locktag_field3 = 0;
572-
tag->locktag_field4 = 0;
573-
tag->locktag_type = LOCKTAG_USERLOCK;
574-
tag->locktag_lockmethodid = USER_LOCKMETHOD;
575-
}
576-
577583
static void *
578584
receive_array(SHMRequest request, Size item_size, Size *count)
579585
{
580-
LOCKTAG collectorTag;
581586
shm_mq_result res;
582587
Size len,
583588
i;
@@ -587,13 +592,10 @@ receive_array(SHMRequest request, Size item_size, Size *count)
587592
MemoryContext oldctx;
588593

589594
/* Ensure nobody else trying to send request to queue */
590-
init_lock_tag(&queueTag, PGWS_QUEUE_LOCK);
591595
LockAcquire(&queueTag, ExclusiveLock, false, false);
592596

593-
recv_mq = shm_mq_create(collector_mq, COLLECTOR_QUEUE_SIZE);
594-
595-
init_lock_tag(&collectorTag, PGWS_COLLECTOR_LOCK);
596597
LockAcquire(&collectorTag, ExclusiveLock, false, false);
598+
recv_mq = shm_mq_create(collector_mq, COLLECTOR_QUEUE_SIZE);
597599
collector_hdr->request = request;
598600
LockRelease(&collectorTag, ExclusiveLock, false);
599601

@@ -754,23 +756,17 @@ PG_FUNCTION_INFO_V1(pg_wait_sampling_reset_profile);
754756
Datum
755757
pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
756758
{
757-
LOCKTAG tag;
758-
LOCKTAG collectorTag;
759-
760759
check_shmem();
761760

762-
init_lock_tag(&tag, PGWS_QUEUE_LOCK);
763-
764-
LockAcquire(&tag, ExclusiveLock, false, false);
761+
LockAcquire(&queueTag, ExclusiveLock, false, false);
765762

766-
init_lock_tag(&collectorTag, PGWS_COLLECTOR_LOCK);
767763
LockAcquire(&collectorTag, ExclusiveLock, false, false);
768764
collector_hdr->request = PROFILE_RESET;
769765
LockRelease(&collectorTag, ExclusiveLock, false);
770766

771767
SetLatch(collector_hdr->latch);
772768

773-
LockRelease(&tag, ExclusiveLock, false);
769+
LockRelease(&queueTag, ExclusiveLock, false);
774770

775771
PG_RETURN_VOID();
776772
}

pg_wait_sampling.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ typedef struct
7070
bool profileQueries;
7171
} CollectorShmqHeader;
7272

73+
extern const LOCKTAG queueTag;
74+
extern const LOCKTAG collectorTag;
75+
7376
/* pg_wait_sampling.c */
7477
extern void check_shmem(void);
7578
extern CollectorShmqHeader *collector_hdr;
7679
extern shm_mq *collector_mq;
7780
extern uint64 *proc_queryids;
78-
extern void init_lock_tag(LOCKTAG *tag, uint32 lock);
7981

8082
/* collector.c */
8183
extern void register_wait_collector(void);

0 commit comments

Comments
 (0)