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

Commit8712971

Browse files
author
Maksim Milyutin
committed
Add patchs
1 parentad7b358 commit8712971

File tree

3 files changed

+564
-0
lines changed

3 files changed

+564
-0
lines changed

‎custom_signals.patch

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
2+
index 0abde43..961d267 100644
3+
--- a/src/backend/storage/ipc/procsignal.c
4+
+++ b/src/backend/storage/ipc/procsignal.c
5+
@@ -67,12 +67,17 @@ typedef struct
6+
*/
7+
boolset_latch_on_sigusr1;
8+
9+
+static bool CustomSignalPendings[NUM_CUSTOM_PROCSIGNALS];
10+
+static ProcSignalHandler_type CustomHandlers[NUM_CUSTOM_PROCSIGNALS];
11+
+
12+
static ProcSignalSlot *ProcSignalSlots = NULL;
13+
static volatile ProcSignalSlot *MyProcSignalSlot = NULL;
14+
15+
static bool CheckProcSignal(ProcSignalReason reason);
16+
static void CleanupProcSignalState(int status, Datum arg);
17+
18+
+static void CustomSignalInterrupt(ProcSignalReason reason);
19+
+
20+
/*
21+
* ProcSignalShmemSize
22+
*Compute space needed for procsignal's shared memory
23+
@@ -173,6 +178,57 @@ CleanupProcSignalState(int status, Datum arg)
24+
}
25+
26+
/*
27+
+ * RegisterCustomProcSignalHandler
28+
+ * Assign specific handler of custom process signal with new ProcSignalReason key.
29+
+ * Return INVALID_PROCSIGNAL if all custom signals have been assigned.
30+
+ */
31+
+ProcSignalReason
32+
+RegisterCustomProcSignalHandler(ProcSignalHandler_type handler)
33+
+{
34+
+ProcSignalReason reason;
35+
+
36+
+/* iterate through custom signal keys to find free spot */
37+
+for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
38+
+if (!CustomHandlers[reason - PROCSIG_CUSTOM_1])
39+
+{
40+
+CustomHandlers[reason - PROCSIG_CUSTOM_1] = handler;
41+
+return reason;
42+
+}
43+
+return INVALID_PROCSIGNAL;
44+
+}
45+
+
46+
+/*
47+
+ * AssignCustomProcSignalHandler
48+
+ * Assign handler of custom process signal with specific ProcSignalReason key.
49+
+ * Return old ProcSignal handler.
50+
+ * Assume incoming reason is one of custom ProcSignals.
51+
+ */
52+
+ProcSignalHandler_type
53+
+AssignCustomProcSignalHandler(ProcSignalReason reason, ProcSignalHandler_type handler)
54+
+{
55+
+ProcSignalHandler_type old;
56+
+
57+
+Assert(reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
58+
+
59+
+old = CustomHandlers[reason - PROCSIG_CUSTOM_1];
60+
+CustomHandlers[reason - PROCSIG_CUSTOM_1] = handler;
61+
+return old;
62+
+}
63+
+
64+
+/*
65+
+ * GetCustomProcSignalHandler
66+
+ * Get handler of custom process signal.
67+
+ *Assume incoming reason is one of custom ProcSignals.
68+
+ */
69+
+ProcSignalHandler_type
70+
+GetCustomProcSignalHandler(ProcSignalReason reason)
71+
+{
72+
+Assert(reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
73+
+
74+
+return CustomHandlers[reason - PROCSIG_CUSTOM_1];
75+
+}
76+
+
77+
+/*
78+
* SendProcSignal
79+
*Send a signal to a Postgres process
80+
*
81+
@@ -267,7 +323,8 @@ CheckProcSignal(ProcSignalReason reason)
82+
void
83+
procsignal_sigusr1_handler(SIGNAL_ARGS)
84+
{
85+
-intsave_errno = errno;
86+
+intsave_errno = errno;
87+
+ProcSignalReason reason;
88+
89+
if (CheckProcSignal(PROCSIG_CATCHUP_INTERRUPT))
90+
HandleCatchupInterrupt();
91+
@@ -296,6 +353,10 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
92+
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
93+
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
94+
95+
+for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
96+
+if (CheckProcSignal(reason))
97+
+CustomSignalInterrupt(reason);
98+
+
99+
if (set_latch_on_sigusr1)
100+
SetLatch(MyLatch);
101+
102+
@@ -303,3 +364,45 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
103+
104+
errno = save_errno;
105+
}
106+
+
107+
+/*
108+
+ * Handle receipt of an interrupt indicating a custom process signal.
109+
+ */
110+
+static void
111+
+CustomSignalInterrupt(ProcSignalReason reason)
112+
+{
113+
+intsave_errno = errno;
114+
+
115+
+Assert(reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
116+
+
117+
+/* set interrupt flags */
118+
+InterruptPending = true;
119+
+CustomSignalPendings[reason - PROCSIG_CUSTOM_1] = true;
120+
+
121+
+/* make sure the event is processed in due course */
122+
+SetLatch(MyLatch);
123+
+
124+
+errno = save_errno;
125+
+}
126+
+
127+
+/*
128+
+ * CheckAndHandleCustomSignals
129+
+ * Check custom signal flags and call handler assigned to that signal if it is not NULL.
130+
+ * This function is called within CHECK_FOR_INTERRUPTS if interrupt have been occurred.
131+
+ */
132+
+void
133+
+CheckAndHandleCustomSignals(void)
134+
+{
135+
+int i;
136+
+
137+
+for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
138+
+if (CustomSignalPendings[i])
139+
+{
140+
+ProcSignalHandler_type handler;
141+
+
142+
+CustomSignalPendings[i] = false;
143+
+handler = CustomHandlers[i];
144+
+if (handler)
145+
+handler();
146+
+}
147+
+}
148+
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
149+
index f78321d..9ef7dd8 100644
150+
--- a/src/backend/tcop/postgres.c
151+
+++ b/src/backend/tcop/postgres.c
152+
@@ -3006,6 +3006,8 @@ ProcessInterrupts(void)
153+
154+
if (ParallelMessagePending)
155+
HandleParallelMessages();
156+
+
157+
+CheckAndHandleCustomSignals();
158+
}
159+
160+
161+
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
162+
index af1a0cd..507a63c 100644
163+
--- a/src/include/storage/procsignal.h
164+
+++ b/src/include/storage/procsignal.h
165+
@@ -17,6 +17,8 @@
166+
#include "storage/backendid.h"
167+
168+
169+
+#define NUM_CUSTOM_PROCSIGNALS 64
170+
+
171+
/*
172+
* Reasons for signalling a Postgres child process (a backend or an auxiliary
173+
* process, like checkpointer). We can cope with concurrent signals for different
174+
@@ -29,6 +31,8 @@
175+
*/
176+
typedef enum
177+
{
178+
+INVALID_PROCSIGNAL = -1,/* Must be first */
179+
+
180+
PROCSIG_CATCHUP_INTERRUPT,/* sinval catchup interrupt */
181+
PROCSIG_NOTIFY_INTERRUPT,/* listen/notify interrupt */
182+
PROCSIG_PARALLEL_MESSAGE,/* message from cooperating parallel backend */
183+
@@ -41,9 +45,20 @@ typedef enum
184+
PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
185+
PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
186+
187+
+PROCSIG_CUSTOM_1,
188+
+/*
189+
+ * PROCSIG_CUSTOM_2,
190+
+ * ...,
191+
+ * PROCSIG_CUSTOM_N-1,
192+
+ */
193+
+PROCSIG_CUSTOM_N = PROCSIG_CUSTOM_1 + NUM_CUSTOM_PROCSIGNALS - 1,
194+
+
195+
NUM_PROCSIGNALS/* Must be last! */
196+
} ProcSignalReason;
197+
198+
+/* Handler of custom process signal */
199+
+typedef void (*ProcSignalHandler_type) (void);
200+
+
201+
/*
202+
* prototypes for functions in procsignal.c
203+
*/
204+
@@ -51,9 +66,15 @@ extern Size ProcSignalShmemSize(void);
205+
extern void ProcSignalShmemInit(void);
206+
207+
extern void ProcSignalInit(int pss_idx);
208+
+extern ProcSignalReason RegisterCustomProcSignalHandler(ProcSignalHandler_type handler);
209+
+extern ProcSignalHandler_type AssignCustomProcSignalHandler(ProcSignalReason reason,
210+
+ ProcSignalHandler_type handler);
211+
+extern ProcSignalHandler_type GetCustomProcSignalHandler(ProcSignalReason reason);
212+
extern int SendProcSignal(pid_t pid, ProcSignalReason reason,
213+
BackendId backendId);
214+
215+
+extern void CheckAndHandleCustomSignals(void);
216+
+
217+
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);
218+
extern PGDLLIMPORT bool set_latch_on_sigusr1;
219+

‎executor_hooks.patch

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
diff --git a/src/backend/executor/execProcnode.c b/src/backend/executor/execProcnode.c
2+
index 03c2feb..b8675d2 100644
3+
--- a/src/backend/executor/execProcnode.c
4+
+++ b/src/backend/executor/execProcnode.c
5+
@@ -115,7 +115,6 @@
6+
#include "executor/nodeWorktablescan.h"
7+
#include "miscadmin.h"
8+
9+
-
10+
/* ------------------------------------------------------------------------
11+
*ExecInitNode
12+
*
13+
@@ -356,6 +355,9 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
14+
return result;
15+
}
16+
17+
+/* Hooks for plugins to pre/post process ExecProcNode */
18+
+PreExecProcNode_hook_type preExecProcNode_hook = NULL;
19+
+PostExecProcNode_hook_type postExecProcNode_hook = NULL;
20+
21+
/* ----------------------------------------------------------------
22+
*ExecProcNode
23+
@@ -373,6 +375,9 @@ ExecProcNode(PlanState *node)
24+
if (node->chgParam != NULL) /* something changed */
25+
ExecReScan(node);/* let ReScan handle this */
26+
27+
+if (preExecProcNode_hook)
28+
+preExecProcNode_hook(node);
29+
+
30+
if (node->instrument)
31+
InstrStartNode(node->instrument);
32+
33+
@@ -529,6 +534,9 @@ ExecProcNode(PlanState *node)
34+
if (node->instrument)
35+
InstrStopNode(node->instrument, TupIsNull(result) ? 0.0 : 1.0);
36+
37+
+if (postExecProcNode_hook)
38+
+postExecProcNode_hook(node, result);
39+
+
40+
return result;
41+
}
42+
43+
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
44+
index 110bc93..8801419 100644
45+
--- a/src/include/executor/executor.h
46+
+++ b/src/include/executor/executor.h
47+
@@ -95,6 +95,12 @@ extern PGDLLIMPORT ExecutorEnd_hook_type ExecutorEnd_hook;
48+
typedef bool (*ExecutorCheckPerms_hook_type) (List *, bool);
49+
extern PGDLLIMPORT ExecutorCheckPerms_hook_type ExecutorCheckPerms_hook;
50+
51+
+/* Hook for plugins to pre/post process ExecProcNode() */
52+
+typedef void (*PreExecProcNode_hook_type) (PlanState *node);
53+
+typedef void (*PostExecProcNode_hook_type) (PlanState *node, TupleTableSlot *result);
54+
+extern PGDLLIMPORT PreExecProcNode_hook_type preExecProcNode_hook;
55+
+extern PGDLLIMPORT PostExecProcNode_hook_type postExecProcNode_hook;
56+
+
57+
58+
/*
59+
* prototypes from functions in execAmi.c

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp