Skip to content

Commit 72f5432

Browse files
authored
Merge branch 'master' into isolation_tests
2 parents 6406719 + 25e7d37 commit 72f5432

File tree

9 files changed

+181
-166
lines changed

9 files changed

+181
-166
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
*.o
33
*.so
44
/results
5-
*pg_wait_sampling--1.1.sql
65
.log
76
Dockerfile
87
/log/

.travis.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ script:
1717
- docker-compose run tests
1818

1919
env:
20-
- PG_VERSION=9.6 CHECK_CODE=clang
21-
- PG_VERSION=9.6 CHECK_CODE=cppcheck
22-
- PG_VERSION=9.6 CHECK_CODE=false
23-
- PG_VERSION=10 CHECK_CODE=clang
24-
- PG_VERSION=10 CHECK_CODE=cppcheck
25-
- PG_VERSION=10 CHECK_CODE=false
26-
- PG_VERSION=11 CHECK_CODE=clang
27-
- PG_VERSION=11 CHECK_CODE=false
28-
- PG_VERSION=12 CHECK_CODE=clang
29-
- PG_VERSION=12 CHECK_CODE=false
30-
- PG_VERSION=13 CHECK_CODE=clang
31-
- PG_VERSION=13 CHECK_CODE=false
20+
- PG_VERSION=10 CHECK_CODE=clang
21+
- PG_VERSION=10 CHECK_CODE=cppcheck
22+
- PG_VERSION=10 CHECK_CODE=false
23+
- PG_VERSION=11 CHECK_CODE=clang
24+
- PG_VERSION=11 CHECK_CODE=false
25+
- PG_VERSION=12 CHECK_CODE=clang
26+
- PG_VERSION=12 CHECK_CODE=false
27+
- PG_VERSION=13 CHECK_CODE=clang
28+
- PG_VERSION=13 CHECK_CODE=false
29+
- PG_VERSION=14 CHECK_CODE=clang
30+
- PG_VERSION=14 CHECK_CODE=false
31+
- PG_VERSION=15beta3 CHECK_CODE=clang
32+
- PG_VERSION=15beta3 CHECK_CODE=false

Makefile

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
# contrib/pg_wait_sampling/Makefile
22

33
MODULE_big = pg_wait_sampling
4-
OBJS = pg_wait_sampling.o collector.o compat.o
4+
OBJS = pg_wait_sampling.o collector.o
55

66
EXTENSION = pg_wait_sampling
7-
EXTVERSION = 1.1
8-
DATA_built = pg_wait_sampling--$(EXTVERSION).sql
9-
DATA = pg_wait_sampling--1.0--1.1.sql
7+
DATA = pg_wait_sampling--1.1.sql pg_wait_sampling--1.0--1.1.sql
108

119
REGRESS = load queries
1210
ISOLATION_TESTS = queryid bfv_queryid_for_relation_lock
1311

14-
EXTRA_CLEAN = pg_wait_sampling--$(EXTVERSION).sql
15-
1612
ifdef USE_PGXS
1713
PG_CONFIG = pg_config
1814
PGXS = $(shell $(PG_CONFIG) --pgxs)
@@ -31,9 +27,6 @@ include $(top_builddir)/src/Makefile.global
3127
include $(top_srcdir)/contrib/contrib-global.mk
3228
endif
3329

34-
$(EXTENSION)--$(EXTVERSION).sql: setup.sql
35-
cat $^ > $@
36-
3730
# Prepare the package for PGXN submission
3831
package: dist .git
3932
$(eval DISTVERSION := $(shell git tag -l | tail -n 1 | cut -d 'v' -f 2))

collector.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "utils/resowner.h"
2727
#include "pgstat.h"
2828

29+
#include "compat.h"
2930
#include "pg_wait_sampling.h"
3031

3132
static volatile sig_atomic_t shutdown_requested = false;
@@ -36,7 +37,7 @@ static void handle_sigterm(SIGNAL_ARGS);
3637
* Register background worker for collecting waits history.
3738
*/
3839
void
39-
register_wait_collector(void)
40+
pgws_register_wait_collector(void)
4041
{
4142
BackgroundWorker worker;
4243

@@ -47,7 +48,7 @@ register_wait_collector(void)
4748
worker.bgw_restart_time = 1;
4849
worker.bgw_notify_pid = 0;
4950
snprintf(worker.bgw_library_name, BGW_MAXLEN, "pg_wait_sampling");
50-
snprintf(worker.bgw_function_name, BGW_MAXLEN, CppAsString(collector_main));
51+
snprintf(worker.bgw_function_name, BGW_MAXLEN, CppAsString(pgws_collector_main));
5152
snprintf(worker.bgw_name, BGW_MAXLEN, "pg_wait_sampling collector");
5253
worker.bgw_main_arg = (Datum) 0;
5354
RegisterBackgroundWorker(&worker);
@@ -56,7 +57,7 @@ register_wait_collector(void)
5657
/*
5758
* Allocate memory for waits history.
5859
*/
59-
void
60+
static void
6061
alloc_history(History *observations, int count)
6162
{
6263
observations->items = (HistoryItem *) palloc0(sizeof(HistoryItem) * count);
@@ -150,7 +151,7 @@ probe_waits(History *observations, HTAB *profile_hash,
150151
TimestampTz ts = GetCurrentTimestamp();
151152

152153
/* Realloc waits history if needed */
153-
newSize = collector_hdr->historySize;
154+
newSize = pgws_collector_hdr->historySize;
154155
if (observations->count != newSize)
155156
realloc_history(observations, newSize);
156157

@@ -172,8 +173,8 @@ probe_waits(History *observations, HTAB *profile_hash,
172173
item.pid = proc->pid;
173174
item.wait_event_info = proc->wait_event_info;
174175

175-
if (collector_hdr->profileQueries)
176-
item.queryId = proc_queryids[i];
176+
if (pgws_collector_hdr->profileQueries)
177+
item.queryId = pgws_proc_queryids[i];
177178
else
178179
item.queryId = 0;
179180

@@ -291,7 +292,7 @@ make_profile_hash()
291292
hash_ctl.hash = tag_hash;
292293
hash_ctl.hcxt = TopMemoryContext;
293294

294-
if (collector_hdr->profileQueries)
295+
if (pgws_collector_hdr->profileQueries)
295296
hash_ctl.keysize = offsetof(ProfileItem, count);
296297
else
297298
hash_ctl.keysize = offsetof(ProfileItem, queryId);
@@ -320,7 +321,7 @@ millisecs_diff(TimestampTz tz1, TimestampTz tz2)
320321
* Main routine of wait history collector.
321322
*/
322323
void
323-
collector_main(Datum main_arg)
324+
pgws_collector_main(Datum main_arg)
324325
{
325326
HTAB *profile_hash = NULL;
326327
History observations;
@@ -350,25 +351,20 @@ collector_main(Datum main_arg)
350351
pqsignal(SIGTERM, handle_sigterm);
351352
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
352353
BackgroundWorkerUnblockSignals();
353-
354-
#if PG_VERSION_NUM >= 110000
355-
InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL, false);
356-
#else
357-
InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL);
358-
#endif
354+
InitPostgresCompat(NULL, InvalidOid, NULL, InvalidOid, false, false, NULL);
359355
SetProcessingMode(NormalProcessing);
360356

361357
/* Make pg_wait_sampling recognisable in pg_stat_activity */
362358
pgstat_report_appname("pg_wait_sampling collector");
363359

364360
profile_hash = make_profile_hash();
365-
collector_hdr->latch = &MyProc->procLatch;
361+
pgws_collector_hdr->latch = &MyProc->procLatch;
366362

367363
CurrentResourceOwner = ResourceOwnerCreate(NULL, "pg_wait_sampling collector");
368364
collector_context = AllocSetContextCreate(TopMemoryContext,
369365
"pg_wait_sampling context", ALLOCSET_DEFAULT_SIZES);
370366
old_context = MemoryContextSwitchTo(collector_context);
371-
alloc_history(&observations, collector_hdr->historySize);
367+
alloc_history(&observations, pgws_collector_hdr->historySize);
372368
MemoryContextSwitchTo(old_context);
373369

374370
ereport(LOG, (errmsg("pg_wait_sampling collector started")));
@@ -395,16 +391,16 @@ collector_main(Datum main_arg)
395391

396392
history_diff = millisecs_diff(history_ts, current_ts);
397393
profile_diff = millisecs_diff(profile_ts, current_ts);
398-
history_period = collector_hdr->historyPeriod;
399-
profile_period = collector_hdr->profilePeriod;
394+
history_period = pgws_collector_hdr->historyPeriod;
395+
profile_period = pgws_collector_hdr->profilePeriod;
400396

401397
write_history = (history_diff >= (int64)history_period);
402398
write_profile = (profile_diff >= (int64)profile_period);
403399

404400
if (write_history || write_profile)
405401
{
406402
probe_waits(&observations, profile_hash,
407-
write_history, write_profile, collector_hdr->profilePid);
403+
write_history, write_profile, pgws_collector_hdr->profilePid);
408404

409405
if (write_history)
410406
{
@@ -443,23 +439,24 @@ collector_main(Datum main_arg)
443439
ResetLatch(&MyProc->procLatch);
444440

445441
/* Handle request if any */
446-
if (collector_hdr->request != NO_REQUEST)
442+
if (pgws_collector_hdr->request != NO_REQUEST)
447443
{
448444
LOCKTAG tag;
449-
SHMRequest request = collector_hdr->request;
445+
SHMRequest request;
450446

451-
init_lock_tag(&tag, PGWS_COLLECTOR_LOCK);
447+
pgws_init_lock_tag(&tag, PGWS_COLLECTOR_LOCK);
452448

453449
LockAcquire(&tag, ExclusiveLock, false, false);
454-
collector_hdr->request = NO_REQUEST;
450+
request = pgws_collector_hdr->request;
451+
pgws_collector_hdr->request = NO_REQUEST;
455452

456453
if (request == HISTORY_REQUEST || request == PROFILE_REQUEST)
457454
{
458455
shm_mq_result mq_result;
459456

460457
/* Send history or profile */
461-
shm_mq_set_sender(collector_mq, MyProc);
462-
mqh = shm_mq_attach(collector_mq, NULL, NULL);
458+
shm_mq_set_sender(pgws_collector_mq, MyProc);
459+
mqh = shm_mq_attach(pgws_collector_mq, NULL, NULL);
463460
mq_result = shm_mq_wait_for_attach(mqh);
464461
switch (mq_result)
465462
{
@@ -485,7 +482,7 @@ collector_main(Datum main_arg)
485482
default:
486483
AssertState(false);
487484
}
488-
shm_mq_detach_compat(mqh, collector_mq);
485+
shm_mq_detach_compat(mqh, pgws_collector_mq);
489486
}
490487
else if (request == PROFILE_RESET)
491488
{

compat.c

Lines changed: 0 additions & 35 deletions
This file was deleted.

compat.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* compat.h
3+
* Definitions for function wrappers compatible between PG versions.
4+
*
5+
* Copyright (c) 2015-2022, Postgres Professional
6+
*
7+
* IDENTIFICATION
8+
* contrib/pg_wait_sampling/compat.h
9+
*/
10+
#ifndef __COMPAT_H__
11+
#define __COMPAT_H__
12+
13+
#include "postgres.h"
14+
15+
#include "access/tupdesc.h"
16+
#include "miscadmin.h"
17+
#include "storage/shm_mq.h"
18+
19+
static inline TupleDesc
20+
CreateTemplateTupleDescCompat(int nattrs, bool hasoid)
21+
{
22+
#if PG_VERSION_NUM >= 120000
23+
return CreateTemplateTupleDesc(nattrs);
24+
#else
25+
return CreateTemplateTupleDesc(nattrs, hasoid);
26+
#endif
27+
}
28+
29+
static inline void
30+
shm_mq_detach_compat(shm_mq_handle *mqh, shm_mq *mq)
31+
{
32+
#if PG_VERSION_NUM >= 100000
33+
shm_mq_detach(mqh);
34+
#else
35+
shm_mq_detach(mq);
36+
#endif
37+
}
38+
39+
static inline shm_mq_result
40+
shm_mq_send_compat(shm_mq_handle *mqh, Size nbytes, const void *data,
41+
bool nowait, bool force_flush)
42+
{
43+
#if PG_VERSION_NUM >= 150000
44+
return shm_mq_send(mqh, nbytes, data, nowait, force_flush);
45+
#else
46+
return shm_mq_send(mqh, nbytes, data, nowait);
47+
#endif
48+
}
49+
50+
static inline void
51+
InitPostgresCompat(const char *in_dbname, Oid dboid,
52+
const char *username, Oid useroid,
53+
bool load_session_libraries,
54+
bool override_allow_connections,
55+
char *out_dbname)
56+
{
57+
#if PG_VERSION_NUM >= 150000
58+
InitPostgres(in_dbname, dboid, username, useroid, load_session_libraries,
59+
override_allow_connections, out_dbname);
60+
#elif PG_VERSION_NUM >= 110000
61+
InitPostgres(in_dbname, dboid, username, useroid, out_dbname,
62+
override_allow_connections);
63+
#else
64+
InitPostgres(in_dbname, dboid, username, useroid, out_dbname);
65+
#endif
66+
}
67+
68+
#endif
File renamed without changes.

0 commit comments

Comments
 (0)