Skip to content

Commit 34547de

Browse files
committed
Merge branch 'master' into testgres
2 parents fa6ce2d + 0ebe691 commit 34547de

9 files changed

+514
-62
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ notifications:
1818
on_failure: always
1919

2020
env:
21+
- PG_VERSION=12 LEVEL=hardcore
22+
- PG_VERSION=12
2123
- PG_VERSION=11 LEVEL=hardcore
2224
- PG_VERSION=11
2325
- PG_VERSION=10 LEVEL=hardcore
@@ -29,4 +31,4 @@ env:
2931
matrix:
3032
allow_failures:
3133
- env: PG_VERSION=10 LEVEL=nightmare
32-
- env: PG_VERSION=9.6 LEVEL=nightmare
34+
- env: PG_VERSION=9.6 LEVEL=nightmare

Dockerfile.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN apk add --no-cache \
66
perl perl-ipc-run \
77
make musl-dev gcc bison flex coreutils linux-headers git\
88
zlib-dev libedit-dev \
9-
clang clang-analyzer \
9+
clang clang-analyzer linux-headers \
1010
python2 python2-dev py2-virtualenv;
1111

1212

LICENSE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pg_query_state is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.
2+
3+
Copyright (c) 2016-2019, Postgres Professional
4+
Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
5+
Portions Copyright (c) 1994, The Regents of the University of California
6+
7+
Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.
8+
9+
IN NO EVENT SHALL POSTGRES PROFESSIONAL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF POSTGRES PROFESSIONAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
11+
POSTGRES PROFESSIONAL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND POSTGRES PROFESSIONAL HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ EXTRA_CLEAN = ./isolation_output $(EXTENSION)--$(EXTVERSION).sql \
1212
Dockerfile ./tests/*.pyc ./tmp_stress
1313

1414
ifdef USE_PGXS
15-
PG_CONFIG = pg_config
15+
PG_CONFIG ?= pg_config
1616
PGXS := $(shell $(PG_CONFIG) --pgxs)
1717
include $(PGXS)
1818
else

patches/custom_signals_12.0.patch

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
2+
index 7605b2c367..6a4327fe76 100644
3+
--- a/src/backend/storage/ipc/procsignal.c
4+
+++ b/src/backend/storage/ipc/procsignal.c
5+
@@ -60,12 +60,20 @@ typedef struct
6+
*/
7+
#define NumProcSignalSlots (MaxBackends + NUM_AUXPROCTYPES)
8+
9+
+#define IsCustomProcSignalReason(reason) \
10+
+ ((reason) >= PROCSIG_CUSTOM_1 && (reason) <= PROCSIG_CUSTOM_N)
11+
+
12+
+static bool CustomSignalPendings[NUM_CUSTOM_PROCSIGNALS];
13+
+static ProcSignalHandler_type CustomInterruptHandlers[NUM_CUSTOM_PROCSIGNALS];
14+
+
15+
static ProcSignalSlot *ProcSignalSlots = NULL;
16+
static volatile ProcSignalSlot *MyProcSignalSlot = NULL;
17+
18+
static bool CheckProcSignal(ProcSignalReason reason);
19+
static void CleanupProcSignalState(int status, Datum arg);
20+
21+
+static void CheckAndSetCustomSignalInterrupts(void);
22+
+
23+
/*
24+
* ProcSignalShmemSize
25+
* Compute space needed for procsignal's shared memory
26+
@@ -165,6 +173,36 @@ CleanupProcSignalState(int status, Datum arg)
27+
slot->pss_pid = 0;
28+
}
29+
30+
+/*
31+
+ * RegisterCustomProcSignalHandler
32+
+ * Assign specific handler of custom process signal with new
33+
+ * ProcSignalReason key.
34+
+ *
35+
+ * This function has to be called in _PG_init function of extensions at the
36+
+ * stage of loading shared preloaded libraries. Otherwise it throws fatal error.
37+
+ *
38+
+ * Return INVALID_PROCSIGNAL if all slots for custom signals are occupied.
39+
+ */
40+
+ProcSignalReason
41+
+RegisterCustomProcSignalHandler(ProcSignalHandler_type handler)
42+
+{
43+
+ ProcSignalReason reason;
44+
+
45+
+ if (!process_shared_preload_libraries_in_progress)
46+
+ ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR),
47+
+ errmsg("cannot register custom signal after startup")));
48+
+
49+
+ /* Iterate through custom signal slots to find a free one */
50+
+ for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
51+
+ if (!CustomInterruptHandlers[reason - PROCSIG_CUSTOM_1])
52+
+ {
53+
+ CustomInterruptHandlers[reason - PROCSIG_CUSTOM_1] = handler;
54+
+ return reason;
55+
+ }
56+
+
57+
+ return INVALID_PROCSIGNAL;
58+
+}
59+
+
60+
/*
61+
* SendProcSignal
62+
* Send a signal to a Postgres process
63+
@@ -292,9 +330,63 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
64+
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
65+
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
66+
67+
+ CheckAndSetCustomSignalInterrupts();
68+
+
69+
SetLatch(MyLatch);
70+
71+
latch_sigusr1_handler();
72+
73+
errno = save_errno;
74+
}
75+
+
76+
+/*
77+
+ * Handle receipt of an interrupt indicating any of custom process signals.
78+
+ */
79+
+static void
80+
+CheckAndSetCustomSignalInterrupts()
81+
+{
82+
+ ProcSignalReason reason;
83+
+
84+
+ for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
85+
+ {
86+
+ if (CheckProcSignal(reason))
87+
+ {
88+
+
89+
+ /* set interrupt flags */
90+
+ InterruptPending = true;
91+
+ CustomSignalPendings[reason - PROCSIG_CUSTOM_1] = true;
92+
+ }
93+
+ }
94+
+
95+
+ SetLatch(MyLatch);
96+
+}
97+
+
98+
+/*
99+
+ * CheckAndHandleCustomSignals
100+
+ * Check custom signal flags and call handler assigned to that signal
101+
+ * if it is not NULL
102+
+ *
103+
+ * This function is called within CHECK_FOR_INTERRUPTS if interrupt occurred.
104+
+ */
105+
+void
106+
+CheckAndHandleCustomSignals(void)
107+
+{
108+
+ int i;
109+
+
110+
+ /* Disable interrupts to avoid recursive calls */
111+
+ HOLD_INTERRUPTS();
112+
+
113+
+ /* Check on expiring of custom signals and call its handlers if exist */
114+
+ for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
115+
+ if (CustomSignalPendings[i])
116+
+ {
117+
+ ProcSignalHandler_type handler;
118+
+
119+
+ CustomSignalPendings[i] = false;
120+
+ handler = CustomInterruptHandlers[i];
121+
+ if (handler != NULL)
122+
+ handler();
123+
+ }
124+
+
125+
+ RESUME_INTERRUPTS();
126+
+}
127+
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
128+
index c28cc37012..f5a48b98e8 100644
129+
--- a/src/backend/tcop/postgres.c
130+
+++ b/src/backend/tcop/postgres.c
131+
@@ -3139,6 +3139,8 @@ ProcessInterrupts(void)
132+
133+
if (ParallelMessagePending)
134+
HandleParallelMessages();
135+
+
136+
+ CheckAndHandleCustomSignals();
137+
}
138+
139+
140+
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
141+
index 05b186a05c..d961790b7e 100644
142+
--- a/src/include/storage/procsignal.h
143+
+++ b/src/include/storage/procsignal.h
144+
@@ -17,6 +17,8 @@
145+
#include "storage/backendid.h"
146+
147+
148+
+#define NUM_CUSTOM_PROCSIGNALS 64
149+
+
150+
/*
151+
* Reasons for signalling a Postgres child process (a backend or an auxiliary
152+
* process, like checkpointer). We can cope with concurrent signals for different
153+
@@ -29,6 +31,8 @@
154+
*/
155+
typedef enum
156+
{
157+
+ INVALID_PROCSIGNAL = -1, /* Must be first */
158+
+
159+
PROCSIG_CATCHUP_INTERRUPT, /* sinval catchup interrupt */
160+
PROCSIG_NOTIFY_INTERRUPT, /* listen/notify interrupt */
161+
PROCSIG_PARALLEL_MESSAGE, /* message from cooperating parallel backend */
162+
@@ -42,9 +46,20 @@ typedef enum
163+
PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
164+
PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
165+
166+
+ PROCSIG_CUSTOM_1,
167+
+ /*
168+
+ * PROCSIG_CUSTOM_2,
169+
+ * ...,
170+
+ * PROCSIG_CUSTOM_N-1,
171+
+ */
172+
+ PROCSIG_CUSTOM_N = PROCSIG_CUSTOM_1 + NUM_CUSTOM_PROCSIGNALS - 1,
173+
+
174+
NUM_PROCSIGNALS /* Must be last! */
175+
} ProcSignalReason;
176+
177+
+/* Handler of custom process signal */
178+
+typedef void (*ProcSignalHandler_type) (void);
179+
+
180+
/*
181+
* prototypes for functions in procsignal.c
182+
*/
183+
@@ -52,9 +67,13 @@ extern Size ProcSignalShmemSize(void);
184+
extern void ProcSignalShmemInit(void);
185+
186+
extern void ProcSignalInit(int pss_idx);
187+
+extern ProcSignalReason
188+
+ RegisterCustomProcSignalHandler(ProcSignalHandler_type handler);
189+
extern int SendProcSignal(pid_t pid, ProcSignalReason reason,
190+
BackendId backendId);
191+
192+
+extern void CheckAndHandleCustomSignals(void);
193+
+
194+
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);
195+
196+
#endif /* PROCSIGNAL_H */

0 commit comments

Comments
 (0)