Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6d53f88

Browse files
committed
Merge commit '3551603141e8d285c6bfc302831bd095c05ce872' into PGPROEE9_6_wait_sampling
2 parents 3fbf707 + 3551603 commit 6d53f88

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

collector.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,19 @@ collector_main(Datum main_arg)
356356
profile_period - (int)profile_diff));
357357

358358
if (rc & WL_POSTMASTER_DEATH)
359-
exit(1);
359+
proc_exit(1);
360360

361361
ResetLatch(&MyProc->procLatch);
362362

363363
/* Handle request if any */
364364
if (collector_hdr->request != NO_REQUEST)
365365
{
366-
SHMRequest request = collector_hdr->request;
366+
LOCKTAG tag;
367+
SHMRequest request = collector_hdr->request;
367368

369+
init_lock_tag(&tag, PGWS_COLLECTOR_LOCK);
370+
371+
LockAcquire(&tag, ExclusiveLock, false, false);
368372
collector_hdr->request = NO_REQUEST;
369373

370374
if (request == HISTORY_REQUEST || request == PROFILE_REQUEST)
@@ -392,6 +396,7 @@ collector_main(Datum main_arg)
392396
hash_destroy(profile_hash);
393397
profile_hash = make_profile_hash();
394398
}
399+
LockRelease(&tag, ExclusiveLock, false);
395400
}
396401
}
397402

pg_wait_sampling.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@ typedef struct
414414
ProfileItem *items;
415415
} Profile;
416416

417-
static void
418-
init_lock_tag(LOCKTAG *tag)
417+
void
418+
init_lock_tag(LOCKTAG *tag, uint32 lock)
419419
{
420420
tag->locktag_field1 = PG_WAIT_SAMPLING_MAGIC;
421-
tag->locktag_field2 = 0;
421+
tag->locktag_field2 = lock;
422422
tag->locktag_field3 = 0;
423423
tag->locktag_field4 = 0;
424424
tag->locktag_type = LOCKTAG_USERLOCK;
@@ -428,7 +428,8 @@ init_lock_tag(LOCKTAG *tag)
428428
static void *
429429
receive_array(SHMRequest request, Size item_size, Size *count)
430430
{
431-
LOCKTAG tag;
431+
LOCKTAG queueTag;
432+
LOCKTAG collectorTag;
432433
shm_mq *mq;
433434
shm_mq_handle *mqh;
434435
shm_mq_result res;
@@ -438,8 +439,14 @@ receive_array(SHMRequest request, Size item_size, Size *count)
438439
Pointer result,
439440
ptr;
440441

441-
init_lock_tag(&tag);
442-
LockAcquire(&tag, ExclusiveLock, false, false);
442+
/* Ensure nobody else trying to send request to queue */
443+
init_lock_tag(&queueTag, PGWS_QUEUE_LOCK);
444+
LockAcquire(&queueTag, ExclusiveLock, false, false);
445+
446+
/* Ensure collector has processed previous request */
447+
init_lock_tag(&collectorTag, PGWS_COLLECTOR_LOCK);
448+
LockAcquire(&collectorTag, ExclusiveLock, false, false);
449+
LockRelease(&collectorTag, ExclusiveLock, false);
443450

444451
mq = shm_mq_create(collector_mq, COLLECTOR_QUEUE_SIZE);
445452
collector_hdr->request = request;
@@ -472,7 +479,7 @@ receive_array(SHMRequest request, Size item_size, Size *count)
472479

473480
shm_mq_detach(mq);
474481

475-
LockRelease(&tag, ExclusiveLock, false);
482+
LockRelease(&queueTag, ExclusiveLock, false);
476483

477484
return result;
478485
}
@@ -568,13 +575,18 @@ Datum
568575
pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
569576
{
570577
LOCKTAG tag;
578+
LOCKTAG tagCollector;
571579

572580
check_shmem();
573581

574-
init_lock_tag(&tag);
582+
init_lock_tag(&tag, false);
575583

576584
LockAcquire(&tag, ExclusiveLock, false, false);
577585

586+
init_lock_tag(&tagCollector, true);
587+
LockAcquire(&tagCollector, ExclusiveLock, false, false);
588+
LockRelease(&tagCollector, ExclusiveLock, false);
589+
578590
collector_hdr->request = PROFILE_RESET;
579591
SetLatch(collector_hdr->latch);
580592

pg_wait_sampling.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#define PG_WAIT_SAMPLING_MAGIC 0xCA94B107
2525
#define COLLECTOR_QUEUE_SIZE (16 * 1024)
2626
#define HISTORY_TIME_MULTIPLIER 10
27+
#define PGWS_QUEUE_LOCK 0
28+
#define PGWS_COLLECTOR_LOCK 1
2729

2830
typedef struct
2931
{
@@ -70,6 +72,7 @@ extern void check_shmem(void);
7072
extern CollectorShmqHeader *collector_hdr;
7173
extern shm_mq *collector_mq;
7274
extern void read_current_wait(PGPROC *proc, HistoryItem *item);
75+
extern void init_lock_tag(LOCKTAG *tag, uint32 lock);
7376

7477
/* collector.c */
7578
extern void register_wait_collector(void);

0 commit comments

Comments
 (0)