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

Commitb984f33

Browse files
committed
Merge branch 'master' into stable
2 parents32c389d +fc6647b commitb984f33

File tree

5 files changed

+83
-38
lines changed

5 files changed

+83
-38
lines changed

‎META.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name":"pg_wait_sampling",
33
"abstract":"Sampling based statistics of wait events",
44
"description":"pg_wait_sampling provides functions for detailed per backend and per query statistics about PostgreSQL wait events",
5-
"version":"1.1.1",
5+
"version":"1.1.3",
66
"maintainer": [
77
"Alexander Korotkov <a.korotkov@postgrespro.ru>",
88
"Ildus Kurbangaliev <i.kurbangaliev@gmail.com>"
@@ -21,7 +21,7 @@
2121
"pg_wait_sampling": {
2222
"file":"pg_wait_sampling--1.1.sql",
2323
"docfile":"README.md",
24-
"version":"1.1.1",
24+
"version":"1.1.3",
2525
"abstract":"Sampling based statistics of wait events"
2626
}
2727
},

‎Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ $(EXTENSION)--$(EXTVERSION).sql: setup.sql
2828
cat$^>$@
2929

3030
# Prepare the package for PGXN submission
31-
package: dist dist/$(EXTENSION)-$(EXTVERSION).zip
31+
DISTVERSION :=$(shell git tag -l | tail -n 1 | cut -d 'v' -f 2)
32+
package: dist dist/$(EXTENSION)-$(DISTVERSION).zip
3233

3334
dist:
3435
mkdir -p dist
3536

36-
dist/$(EXTENSION)-$(EXTVERSION).zip:
37-
git archive --format zip --prefix=$(EXTENSION)-$(EXTVERSION)/ --output$@master
37+
dist/$(EXTENSION)-$(DISTVERSION).zip:
38+
git archive --format zip --prefix=$(EXTENSION)-$(DISTVERSION)/ --output$@HEAD

‎README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ your bug reports.
153153
If you're lacking of some functionality in`pg_wait_sampling` and feeling power
154154
to implement it then you're welcome to make pull requests.
155155

156+
Releases
157+
--------
158+
159+
New features are developed in feature-branches and then merged into[master](https://github.com/postgrespro/pg_wait_sampling/tree/master). To make a new release:
160+
161+
1) Bump`PGXN` version in the`META.json`.
162+
2) Merge[master](https://github.com/postgrespro/pg_wait_sampling/tree/master) into[stable](https://github.com/postgrespro/pg_wait_sampling/tree/stable).
163+
3) Tag new release in the[stable](https://github.com/postgrespro/pg_wait_sampling/tree/stable) with`git tag -a v1.1.X`, where the last digit is used for indicating compatible shared library changes and bugfixes. Second digit is used to indicate extension schema change, i.e. when`ALTER EXTENSION pg_wait_sampling UPDATE;` is required.
164+
4) Merge[stable](https://github.com/postgrespro/pg_wait_sampling/tree/stable) into[debian](https://github.com/postgrespro/pg_wait_sampling/tree/debian). This separate branch is used to independently support`Debian` packaging and@anayrat with@df7cb have an access there.
165+
156166
Authors
157167
-------
158168

‎collector.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ send_history(History *observations, shm_mq_handle *mqh)
225225
{
226226
ereport(WARNING,
227227
(errmsg("pg_wait_sampling collector: "
228-
"receiver of message queuehave been detached")));
228+
"receiver of message queuehas been detached")));
229229
return;
230230
}
231231
for (i=0;i<count;i++)
@@ -238,7 +238,7 @@ send_history(History *observations, shm_mq_handle *mqh)
238238
{
239239
ereport(WARNING,
240240
(errmsg("pg_wait_sampling collector: "
241-
"receiver of message queuehave been detached")));
241+
"receiver of message queuehas been detached")));
242242
return;
243243
}
244244
}
@@ -260,7 +260,7 @@ send_profile(HTAB *profile_hash, shm_mq_handle *mqh)
260260
{
261261
ereport(WARNING,
262262
(errmsg("pg_wait_sampling collector: "
263-
"receiver of message queuehave been detached")));
263+
"receiver of message queuehas been detached")));
264264
return;
265265
}
266266
hash_seq_init(&scan_status,profile_hash);
@@ -272,7 +272,7 @@ send_profile(HTAB *profile_hash, shm_mq_handle *mqh)
272272
hash_seq_term(&scan_status);
273273
ereport(WARNING,
274274
(errmsg("pg_wait_sampling collector: "
275-
"receiver of message queuehave been detached")));
275+
"receiver of message queuehas been detached")));
276276
return;
277277
}
278278
}
@@ -468,7 +468,7 @@ collector_main(Datum main_arg)
468468
caseSHM_MQ_DETACHED:
469469
ereport(WARNING,
470470
(errmsg("pg_wait_sampling collector: "
471-
"receiver of message queuehave been "
471+
"receiver of message queuehas been "
472472
"detached")));
473473
break;
474474
default:

‎pg_wait_sampling.c

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,27 @@
88
* contrib/pg_wait_sampling/pg_wait_sampling.c
99
*/
1010
#include"postgres.h"
11-
#include"fmgr.h"
12-
#include"funcapi.h"
11+
1312
#include"access/htup_details.h"
1413
#include"access/twophase.h"
1514
#include"catalog/pg_type.h"
15+
#include"fmgr.h"
16+
#include"funcapi.h"
1617
#include"miscadmin.h"
1718
#include"optimizer/planner.h"
1819
#include"pgstat.h"
19-
#include"storage/spin.h"
2020
#include"storage/ipc.h"
2121
#include"storage/pg_shmem.h"
2222
#include"storage/procarray.h"
2323
#include"storage/shm_mq.h"
2424
#include"storage/shm_toc.h"
25+
#include"storage/spin.h"
2526
#include"utils/builtins.h"
2627
#include"utils/datetime.h"
27-
#include"utils/guc.h"
2828
#include"utils/guc_tables.h"
29+
#include"utils/guc.h"
30+
#include"utils/memutils.h"/* TopMemoryContext. Actually for PG 9.6 only,
31+
* but there should be no harm for others. */
2932

3033
#include"pg_wait_sampling.h"
3134

@@ -47,6 +50,11 @@ shm_mq *collector_mq = NULL;
4750
uint64*proc_queryids=NULL;
4851
CollectorShmqHeader*collector_hdr=NULL;
4952

53+
/* Receiver (backend) local shm_mq pointers and lock */
54+
shm_mq*recv_mq=NULL;
55+
shm_mq_handle*recv_mqh=NULL;
56+
LOCKTAGqueueTag;
57+
5058
staticshmem_startup_hook_typeprev_shmem_startup_hook=NULL;
5159
staticPGPROC*search_proc(intbackendPid);
5260
staticPlannedStmt*pgws_planner_hook(Query*parse,
@@ -290,6 +298,14 @@ check_shmem(void)
290298
}
291299
}
292300

301+
staticvoid
302+
pgws_cleanup_callback(intcode,Datumarg)
303+
{
304+
elog(DEBUG3,"pg_wait_sampling cleanup: detaching shm_mq and releasing queue lock");
305+
shm_mq_detach_compat(recv_mqh,recv_mq);
306+
LockRelease(&queueTag,ExclusiveLock, false);
307+
}
308+
293309
/*
294310
* Module load callback
295311
*/
@@ -499,16 +515,14 @@ init_lock_tag(LOCKTAG *tag, uint32 lock)
499515
staticvoid*
500516
receive_array(SHMRequestrequest,Sizeitem_size,Size*count)
501517
{
502-
LOCKTAGqueueTag;
503518
LOCKTAGcollectorTag;
504-
shm_mq*mq;
505-
shm_mq_handle*mqh;
506519
shm_mq_resultres;
507520
Sizelen,
508521
i;
509522
void*data;
510523
Pointerresult,
511524
ptr;
525+
MemoryContextoldctx;
512526

513527
/* Ensure nobody else trying to send request to queue */
514528
init_lock_tag(&queueTag,PGWS_QUEUE_LOCK);
@@ -519,7 +533,7 @@ receive_array(SHMRequest request, Size item_size, Size *count)
519533
LockAcquire(&collectorTag,ExclusiveLock, false, false);
520534
LockRelease(&collectorTag,ExclusiveLock, false);
521535

522-
mq=shm_mq_create(collector_mq,COLLECTOR_QUEUE_SIZE);
536+
recv_mq=shm_mq_create(collector_mq,COLLECTOR_QUEUE_SIZE);
523537
collector_hdr->request=request;
524538

525539
if (!collector_hdr->latch)
@@ -528,34 +542,54 @@ receive_array(SHMRequest request, Size item_size, Size *count)
528542

529543
SetLatch(collector_hdr->latch);
530544

531-
shm_mq_set_receiver(mq,MyProc);
532-
mqh=shm_mq_attach(mq,NULL,NULL);
545+
shm_mq_set_receiver(recv_mq,MyProc);
546+
547+
/*
548+
* We switch to TopMemoryContext, so that recv_mqh is allocated there
549+
* and is guaranteed to survive until before_shmem_exit callbacks are
550+
* fired. Anyway, shm_mq_detach() will free handler on its own.
551+
*
552+
* NB: we do not pass `seg` to shm_mq_attach(), so it won't set its own
553+
* callback, i.e. we do not interfere here with shm_mq_detach_callback().
554+
*/
555+
oldctx=MemoryContextSwitchTo(TopMemoryContext);
556+
recv_mqh=shm_mq_attach(recv_mq,NULL,NULL);
557+
MemoryContextSwitchTo(oldctx);
533558

534-
res=shm_mq_receive(mqh,&len,&data, false);
535-
if (res!=SHM_MQ_SUCCESS||len!=sizeof(*count))
559+
/*
560+
* Now we surely attached to the shm_mq and got collector's attention.
561+
* If anything went wrong (e.g. Ctrl+C received from the client) we have
562+
* to cleanup some things, i.e. detach from the shm_mq, so collector was
563+
* able to continue responding to other requests.
564+
*
565+
* PG_ENSURE_ERROR_CLEANUP() guaranties that cleanup callback will be
566+
* fired for both ERROR and FATAL.
567+
*/
568+
PG_ENSURE_ERROR_CLEANUP(pgws_cleanup_callback,0);
536569
{
537-
shm_mq_detach_compat(mqh,mq);
538-
elog(ERROR,"Error reading mq.");
539-
}
540-
memcpy(count,data,sizeof(*count));
570+
res=shm_mq_receive(recv_mqh,&len,&data, false);
571+
if (res!=SHM_MQ_SUCCESS||len!=sizeof(*count))
572+
elog(ERROR,"error reading mq");
541573

542-
result=palloc(item_size* (*count));
543-
ptr=result;
574+
memcpy(count,data,sizeof(*count));
544575

545-
for (i=0;i<*count;i++)
546-
{
547-
res=shm_mq_receive(mqh,&len,&data, false);
548-
if (res!=SHM_MQ_SUCCESS||len!=item_size)
576+
result=palloc(item_size* (*count));
577+
ptr=result;
578+
579+
for (i=0;i<*count;i++)
549580
{
550-
shm_mq_detach_compat(mqh,mq);
551-
elog(ERROR,"Error reading mq.");
581+
res=shm_mq_receive(recv_mqh,&len,&data, false);
582+
if (res!=SHM_MQ_SUCCESS||len!=item_size)
583+
elog(ERROR,"error reading mq");
584+
585+
memcpy(ptr,data,item_size);
586+
ptr+=item_size;
552587
}
553-
memcpy(ptr,data,item_size);
554-
ptr+=item_size;
555588
}
589+
PG_END_ENSURE_ERROR_CLEANUP(pgws_cleanup_callback,0);
556590

557-
shm_mq_detach_compat(mqh,mq);
558-
591+
/* We still have to detach and release lock during normal operation. */
592+
shm_mq_detach_compat(recv_mqh,recv_mq);
559593
LockRelease(&queueTag,ExclusiveLock, false);
560594

561595
returnresult;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp