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

Add core patches for Postgres v12#14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
maksm90 merged 1 commit intopostgrespro:masterfromololobus:master
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletionspatches/custom_signals_12.0.patch
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
From 44e4d28abd0a63a6e1c4a75c55ad27fb827dbfa4 Mon Sep 17 00:00:00 2001
From: Alexey Kondratov <kondratov.aleksey@gmail.com>
Date: Fri, 18 Oct 2019 19:44:01 +0300
Subject: [PATCH] [custom_signals] Allow extensions to set custom signal
handlers

---
src/backend/storage/ipc/procsignal.c | 94 ++++++++++++++++++++++++++++
src/backend/tcop/postgres.c | 2 +
src/include/storage/procsignal.h | 19 ++++++
3 files changed, 115 insertions(+)

diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 7605b2c3674..0802ed1119b 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -60,12 +60,20 @@ typedef struct
*/
#define NumProcSignalSlots(MaxBackends + NUM_AUXPROCTYPES)

+#define IsCustomProcSignalReason(reason) \
+((reason) >= PROCSIG_CUSTOM_1 && (reason) <= PROCSIG_CUSTOM_N)
+
+static bool CustomSignalPendings[NUM_CUSTOM_PROCSIGNALS];
+static ProcSignalHandler_type CustomInterruptHandlers[NUM_CUSTOM_PROCSIGNALS];
+
static ProcSignalSlot *ProcSignalSlots = NULL;
static volatile ProcSignalSlot *MyProcSignalSlot = NULL;

static bool CheckProcSignal(ProcSignalReason reason);
static void CleanupProcSignalState(int status, Datum arg);

+static void CheckAndSetCustomSignalInterrupts(void);
+
/*
* ProcSignalShmemSize
*Compute space needed for procsignal's shared memory
@@ -165,6 +173,36 @@ CleanupProcSignalState(int status, Datum arg)
slot->pss_pid = 0;
}

+/*
+ * RegisterCustomProcSignalHandler
+ *Assign specific handler of custom process signal with new
+ *ProcSignalReason key.
+ *
+ * This function has to be called in _PG_init function of extensions at the
+ * stage of loading shared preloaded libraries. Otherwise it throws fatal error.
+ *
+ * Return INVALID_PROCSIGNAL if all slots for custom signals are occupied.
+ */
+ProcSignalReason
+RegisterCustomProcSignalHandler(ProcSignalHandler_type handler)
+{
+ProcSignalReason reason;
+
+if (!process_shared_preload_libraries_in_progress)
+ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR),
+errmsg("cannot register custom signal after startup")));
+
+/* Iterate through custom signal slots to find a free one */
+for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
+if (!CustomInterruptHandlers[reason - PROCSIG_CUSTOM_1])
+{
+CustomInterruptHandlers[reason - PROCSIG_CUSTOM_1] = handler;
+return reason;
+}
+
+return INVALID_PROCSIGNAL;
+}
+
/*
* SendProcSignal
*Send a signal to a Postgres process
@@ -292,9 +330,65 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);

+CheckAndSetCustomSignalInterrupts();
+
SetLatch(MyLatch);

latch_sigusr1_handler();

errno = save_errno;
}
+
+/*
+ * Handle receipt of an interrupt indicating any of custom process signals.
+ */
+static void
+CheckAndSetCustomSignalInterrupts()
+{
+ProcSignalReasonreason;
+
+for (reason = PROCSIG_CUSTOM_1; reason <= PROCSIG_CUSTOM_N; reason++)
+{
+if (CheckProcSignal(reason))
+{
+
+/* set interrupt flags */
+InterruptPending = true;
+CustomSignalPendings[reason - PROCSIG_CUSTOM_1] = true;
+}
+}
+
+SetLatch(MyLatch);
+}
+
+/*
+ * CheckAndHandleCustomSignals
+ *Check custom signal flags and call handler assigned to that signal
+ *if it is not NULL
+ *
+ * This function is called within CHECK_FOR_INTERRUPTS if interrupt occurred.
+ */
+void
+CheckAndHandleCustomSignals(void)
+{
+int i;
+
+/* Disable interrupts to avoid recursive calls */
+HOLD_INTERRUPTS();
+
+/* Check on expiring of custom signals and call its handlers if exist */
+for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
+if (CustomSignalPendings[i])
+{
+ProcSignalHandler_type handler;
+ProcSignalReason reason;
+
+CustomSignalPendings[i] = false;
+handler = CustomInterruptHandlers[i];
+reason = PROCSIG_CUSTOM_1 + i;
+if (handler != NULL)
+handler(reason);
+}
+
+RESUME_INTERRUPTS();
+}
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index c28cc370129..f5a48b98e86 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3139,6 +3139,8 @@ ProcessInterrupts(void)

if (ParallelMessagePending)
HandleParallelMessages();
+
+CheckAndHandleCustomSignals();
}


diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
index 05b186a05c2..84290d60975 100644
--- a/src/include/storage/procsignal.h
+++ b/src/include/storage/procsignal.h
@@ -17,6 +17,8 @@
#include "storage/backendid.h"


+#define NUM_CUSTOM_PROCSIGNALS 64
+
/*
* Reasons for signalling a Postgres child process (a backend or an auxiliary
* process, like checkpointer). We can cope with concurrent signals for different
@@ -29,6 +31,8 @@
*/
typedef enum
{
+INVALID_PROCSIGNAL = -1,/* Must be first */
+
PROCSIG_CATCHUP_INTERRUPT,/* sinval catchup interrupt */
PROCSIG_NOTIFY_INTERRUPT,/* listen/notify interrupt */
PROCSIG_PARALLEL_MESSAGE,/* message from cooperating parallel backend */
@@ -42,9 +46,20 @@ typedef enum
PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,

+PROCSIG_CUSTOM_1,
+/*
+ * PROCSIG_CUSTOM_2,
+ * ...,
+ * PROCSIG_CUSTOM_N-1,
+ */
+PROCSIG_CUSTOM_N = PROCSIG_CUSTOM_1 + NUM_CUSTOM_PROCSIGNALS - 1,
+
NUM_PROCSIGNALS/* Must be last! */
} ProcSignalReason;

+/* Handler of custom process signal */
+typedef void (*ProcSignalHandler_type) (ProcSignalReason reason);
+
/*
* prototypes for functions in procsignal.c
*/
@@ -52,9 +67,13 @@ extern Size ProcSignalShmemSize(void);
extern void ProcSignalShmemInit(void);

extern void ProcSignalInit(int pss_idx);
+extern ProcSignalReason
+RegisterCustomProcSignalHandler(ProcSignalHandler_type handler);
extern intSendProcSignal(pid_t pid, ProcSignalReason reason,
BackendId backendId);

+extern void CheckAndHandleCustomSignals(void);
+
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);

#endif/* PROCSIGNAL_H */
--
2.17.1

Loading

[8]ページ先頭

©2009-2025 Movatter.jp