8000 porting to version 15 and minor improvements to version 14 by MakSl · Pull Request #33 · postgrespro/pg_query_state · GitHub
[go: up one dir, main page]

Skip to content

porting to version 15 and minor improvements to version 14 #33

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 0 additions & 11 deletions patches/custom_signals_14.0.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
From f2632ea7cd03119c55b8aa0ef60f529380ca2536 Mon Sep 17 00:00:00 2001
From: Kovalenko Anastasia <s2180445@gse.cs.msu.ru>
Date: Tue, 24 Aug 2021 16:22:28 +0300
Subject: [PATCH] custom-signals

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

diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index defb75a..4245d28 100644
--- a/src/backend/storage/ipc/procsignal.c
Expand Down
206 changes: 206 additions & 0 deletions patches/custom_signals_15.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index defb75a..4245d28 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -95,6 +95,13 @@ typedef struct
#define BARRIER_CLEAR_BIT(flags, type) \
((flags) &= ~(((uint32) 1) << (uint32) (type)))

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

@@ -103,6 +110,8 @@ static void CleanupProcSignalState(int status, Datum arg);
static void ResetProcSignalBarrierBits(uint32 flags);
static bool ProcessBarrierPlaceholder(void);

+static void CheckAndSetCustomSignalInterrupts(void);
+
/*
* ProcSignalShmemSize
* Compute space needed for procsignal's shared memory
@@ -246,6 +255,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
@@ -679,7 +718,62 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);

+ CheckAndSetCustomSignalInterrupts();
+
SetLatch(MyLatch);

errno = save_errno;
}
+
+/*
+ * Handle receipt of an interrupt indicating any of custom process signals.
+ */
+static void
+CheckAndSetCustomSignalInterrupts()
+{
+ ProcSignalReason reason;
+
+ 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;
+
+ /* Check on expiring of custom signals and call its handlers if exist */
+ for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
+ {
+ if (!CustomSignalProcessing[i] && CustomSignalPendings[i])
+ {
+ ProcSignalHandler_type handler;
+
+ CustomSignalPendings[i] = false;
+ handler = CustomInterruptHandlers[i];
+ if (handler != NULL)
+ {
+ CustomSignalProcessing[i] = true;
+ handler();
+ CustomSignalProcessing[i] = false;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 8cea10c..dd77c98 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3364,6 +3364,8 @@ ProcessInterrupts(void)
if (ParallelMessagePending)
HandleParallelMessages();

+ CheckAndHandleCustomSignals();
+
if (LogMemoryContextPending)
ProcessLogMemoryContextInterrupt();
}
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
index eec186b..74af186 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 signaling 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 */
@@ -44,6 +48,14 @@ 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;

@@ -56,6 +68,8 @@ typedef enum
*/
PROCSIGNAL_BARRIER_PLACEHOLDER = 0
} ProcSignalBarrierType;
+/* Handler of custom process signal */
+typedef void (*ProcSignalHandler_type) (void);

/*
* prototypes for functions in procsignal.c
@@ -64,12 +78,15 @@ extern Size ProcSignalShmemSize(void);
extern void ProcSignalShmemInit(void);

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

extern uint64 EmitProcSignalBarrier(ProcSignalBarrierType type);
extern void WaitForProcSignalBarrier(uint64 generation);
extern void ProcessProcSignalBarrier(void);
+extern void CheckAndHandleCustomSignals(void);

extern void procsignal_sigusr1_handler(SIGNAL_ARGS);

--
2.25.1

10 changes: 0 additions & 10 deletions patches/runtime_explain_14.0.patch
682B
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
From 71a353d4cac663db43c57452f925082a233c0e49 Mon Sep 17 00:00:00 2001
From: Kovalenko Anastasia <s2180445@gse.cs.msu.ru>
Date: Mon, 23 Aug 2021 15:29:59 +0300
Subject: [PATCH] runtime-explain

---
src/backend/commands/explain.c | 153 ++++++++++++++++++++++++++++-----
src/include/commands/explain.h | 2 +
2 files changed, 133 insertions(+), 22 deletions(-)

diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 10644dfac4..7106ed4257 100644
--- a/src/backend/commands/explain.c
Expand Down
Loading
0