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

Commit275de5f

Browse files
author
Maksim Milyutin
committed
Specify context memory for custom signals
1 parent73b7295 commit275de5f

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

‎custom_signals.patch‎

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
2-
index a3d6ac5..07270a9 100644
2+
index a3d6ac5..60732a6 100644
33
--- a/src/backend/storage/ipc/procsignal.c
44
+++ b/src/backend/storage/ipc/procsignal.c
5-
@@ -59,12 +59,17 @@ typedef struct
5+
@@ -26,6 +26,7 @@
6+
#include "storage/shmem.h"
7+
#include "storage/sinval.h"
8+
#include "tcop/tcopprot.h"
9+
+#include "utils/memutils.h"
10+
11+
12+
/*
13+
@@ -59,12 +60,17 @@ typedef struct
614
*/
715
#define NumProcSignalSlots(MaxBackends + NUM_AUXPROCTYPES)
816

@@ -20,7 +28,7 @@ index a3d6ac5..07270a9 100644
2028
/*
2129
* ProcSignalShmemSize
2230
*Compute space needed for procsignal's shared memory
23-
@@ -165,6 +170,57 @@ CleanupProcSignalState(int status, Datum arg)
31+
@@ -165,6 +171,57 @@ CleanupProcSignalState(int status, Datum arg)
2432
}
2533

2634
/*
@@ -78,7 +86,7 @@ index a3d6ac5..07270a9 100644
7886
* SendProcSignal
7987
*Send a signal to a Postgres process
8088
*
81-
@@ -259,7 +315,8 @@ CheckProcSignal(ProcSignalReason reason)
89+
@@ -259,7 +316,8 @@ CheckProcSignal(ProcSignalReason reason)
8290
void
8391
procsignal_sigusr1_handler(SIGNAL_ARGS)
8492
{
@@ -88,7 +96,7 @@ index a3d6ac5..07270a9 100644
8896

8997
if (CheckProcSignal(PROCSIG_CATCHUP_INTERRUPT))
9098
HandleCatchupInterrupt();
91-
@@ -288,9 +345,55 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
99+
@@ -288,9 +346,88 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
92100
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
93101
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
94102

@@ -132,6 +140,32 @@ index a3d6ac5..07270a9 100644
132140
+CheckAndHandleCustomSignals(void)
133141
+{
134142
+int i;
143+
+MemoryContext oldcontext;
144+
+
145+
+static MemoryContext hcs_context = NULL;
146+
+
147+
+/*
148+
+ * This is invoked from ProcessInterrupts(), and since some of the
149+
+ * functions it calls contain CHECK_FOR_INTERRUPTS(), there is a potential
150+
+ * for recursive calls if more signals are received while this runs. It's
151+
+ * unclear that recursive entry would be safe, and it doesn't seem useful
152+
+ * even if it is safe, so let's block interrupts until done.
153+
+ */
154+
+HOLD_INTERRUPTS();
155+
+
156+
+/*
157+
+ * Moreover, CurrentMemoryContext might be pointing almost anywhere. We
158+
+ * don't want to risk leaking data into long-lived contexts, so let's do
159+
+ * our work here in a private context that we can reset on each use.
160+
+ */
161+
+if (hcs_context == NULL)/* first time through? */
162+
+hcs_context = AllocSetContextCreate(TopMemoryContext,
163+
+"HandleCustomSignals",
164+
+ALLOCSET_DEFAULT_SIZES);
165+
+else
166+
+MemoryContextReset(hcs_context);
167+
+
168+
+oldcontext = MemoryContextSwitchTo(hcs_context);
135169
+
136170
+for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
137171
+if (CustomSignalPendings[i])
@@ -143,6 +177,13 @@ index a3d6ac5..07270a9 100644
143177
+if (handler)
144178
+handler();
145179
+}
180+
+
181+
+MemoryContextSwitchTo(oldcontext);
182+
+
183+
+/* Might as well clear the context on our way out */
184+
+MemoryContextReset(hcs_context);
185+
+
186+
+RESUME_INTERRUPTS();
146187
+}
147188
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
148189
index 98ccbbb..c5d649c 100644

‎signal_handler.c‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,7 @@ serialize_stack(char *dest, List *qs_stack)
153153
void
154154
SendQueryState(void)
155155
{
156-
shm_mq_handle*mqh;
157-
MemoryContextcurCxt;
158-
MemoryContextoldCxt;
159-
160-
curCxt=AllocSetContextCreate(CurrentMemoryContext,
161-
"pg_query_state signal handler context",
162-
ALLOCSET_DEFAULT_MINSIZE,
163-
ALLOCSET_DEFAULT_INITSIZE,
164-
ALLOCSET_DEFAULT_MAXSIZE);
165-
oldCxt=MemoryContextSwitchTo(curCxt);
166-
167-
mqh=shm_mq_attach(mq,NULL,NULL);
156+
shm_mq_handle*mqh=shm_mq_attach(mq,NULL,NULL);
168157

169158
/* check if module is enabled */
170159
if (!pg_qs_enable)
@@ -210,7 +199,4 @@ SendQueryState(void)
210199
serialize_stack(msg->stack,qs_stack);
211200
shm_mq_send(mqh,msglen,msg, false);
212201
}
213-
214-
MemoryContextSwitchTo(oldCxt);
215-
MemoryContextDelete(curCxt);
216202
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp