Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4fdf032

Browse files
author
Alexander Korotkov
committed
Introduce collector lock in order to ensure that nobody tries to send next
request to collector before it has previous request completed.
1 parentaa4e0a9 commit4fdf032

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

‎collector.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,12 @@ collector_main(Datum main_arg)
363363
/* Handle request if any */
364364
if (collector_hdr->request!=NO_REQUEST)
365365
{
366-
SHMRequestrequest=collector_hdr->request;
366+
LOCKTAGtag;
367+
SHMRequestrequest=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-
staticvoid
418-
init_lock_tag(LOCKTAG*tag)
417+
void
418+
init_lock_tag(LOCKTAG*tag,uint32lock)
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
staticvoid*
429429
receive_array(SHMRequestrequest,Sizeitem_size,Size*count)
430430
{
431-
LOCKTAGtag;
431+
LOCKTAGqueueTag;
432+
LOCKTAGcollectorTag;
432433
shm_mq*mq;
433434
shm_mq_handle*mqh;
434435
shm_mq_resultres;
@@ -438,8 +439,14 @@ receive_array(SHMRequest request, Size item_size, Size *count)
438439
Pointerresult,
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
returnresult;
478485
}
@@ -568,13 +575,18 @@ Datum
568575
pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
569576
{
570577
LOCKTAGtag;
578+
LOCKTAGtagCollector;
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
#definePG_WAIT_SAMPLING_MAGIC0xCA94B107
2525
#defineCOLLECTOR_QUEUE_SIZE(16 * 1024)
2626
#defineHISTORY_TIME_MULTIPLIER10
27+
#definePGWS_QUEUE_LOCK0
28+
#definePGWS_COLLECTOR_LOCK1
2729

2830
typedefstruct
2931
{
@@ -70,6 +72,7 @@ extern void check_shmem(void);
7072
externCollectorShmqHeader*collector_hdr;
7173
externshm_mq*collector_mq;
7274
externvoidread_current_wait(PGPROC*proc,HistoryItem*item);
75+
externvoidinit_lock_tag(LOCKTAG*tag,uint32lock);
7376

7477
/* collector.c */
7578
externvoidregister_wait_collector(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp