v2-0001-Support-worker_spi-to-execute-the-function-dynamical.patch
text/x-diff
Filename: v2-0001-Support-worker_spi-to-execute-the-function-dynamical.patch
Type: text/x-diff
Part: 0
Patch
Format: format-patch
Series: patch v2-0001
Subject: Support worker_spi to execute the function dynamically.
| File | + | − |
|---|---|---|
| src/test/modules/worker_spi/dynamic.conf | 1 | 2 |
| src/test/modules/worker_spi/Makefile | 2 | 2 |
| src/test/modules/worker_spi/worker_spi.c | 16 | 11 |
From 02ef0d8daddd43305842987a6aeac6732b2415a9 Mon Sep 17 00:00:00 2001
From: Masahiro Ikeda <masahiro.ikeda.us@hco.ntt.co.jp>
Date: Thu, 20 Jul 2023 10:34:50 +0900
Subject: [PATCH] Support worker_spi to execute the function dynamically.
Currently, the database name to connect is initialized only
when process_shared_preload_libraries_in_progress is true.
It means that worker_spi_launch() fails if shared_preload_libraries
is empty because the database to connect is NULL.
The patch changes that the database name is always initilized
when called _PG_init(). We can call worker_spi_launch() and
launch SPI workers dynamically.
It also changes the configuration for the test because we don't
need "shared_preload_libraries = worker_spi" anymore, and
background workers launched in initialized phase always have
failed because the "contrib_regression" database is not created yet.
---
src/test/modules/worker_spi/Makefile | 4 ++--
src/test/modules/worker_spi/dynamic.conf | 3 +--
src/test/modules/worker_spi/worker_spi.c | 27 ++++++++++++++----------
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/src/test/modules/worker_spi/Makefile b/src/test/modules/worker_spi/Makefile
index cbf9b2e37f..c2d32d9b72 100644
--- a/src/test/modules/worker_spi/Makefile
+++ b/src/test/modules/worker_spi/Makefile
@@ -8,10 +8,10 @@ PGFILEDESC = "worker_spi - background worker example"
REGRESS = worker_spi
-# enable our module in shared_preload_libraries for dynamic bgworkers
REGRESS_OPTS = --temp-config $(top_srcdir)/src/test/modules/worker_spi/dynamic.conf
-# Disable installcheck to ensure we cover dynamic bgworkers.
+# Disable because these tests require "worker_spi.database = contrib_regression",
+# which typical installcheck users do not have (e.g. buildfarm clients).
NO_INSTALLCHECK = 1
ifdef USE_PGXS
diff --git a/src/test/modules/worker_spi/dynamic.conf b/src/test/modules/worker_spi/dynamic.conf
index bfe015f664..d9fd463a53 100644
--- a/src/test/modules/worker_spi/dynamic.conf
+++ b/src/test/modules/worker_spi/dynamic.conf
@@ -1,2 +1 @@
-shared_preload_libraries = worker_spi
-worker_spi.database = contrib_regression
+worker_spi.database = contrib_regression
\ No newline at end of file
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index 7227cfaa45..f691fbec9f 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -282,7 +282,12 @@ _PG_init(void)
{
BackgroundWorker worker;
- /* get the configuration */
+ /* Get the configuration */
+
+ /*
+ * These GUCs are defined even if this library is not loaded with
+ * shared_preload_libraries, for worker_spi_launch().
+ */
DefineCustomIntVariable("worker_spi.naptime",
"Duration between each check (in seconds).",
NULL,
@@ -296,6 +301,15 @@ _PG_init(void)
NULL,
NULL);
+ DefineCustomStringVariable("worker_spi.database",
+ "Database to connect to.",
+ NULL,
+ &worker_spi_database,
+ "postgres",
+ PGC_SIGHUP,
+ 0,
+ NULL, NULL, NULL);
+
if (!process_shared_preload_libraries_in_progress)
return;
@@ -312,18 +326,9 @@ _PG_init(void)
NULL,
NULL);
- DefineCustomStringVariable("worker_spi.database",
- "Database to connect to.",
- NULL,
- &worker_spi_database,
- "postgres",
- PGC_POSTMASTER,
- 0,
- NULL, NULL, NULL);
-
MarkGUCPrefixReserved("worker_spi");
- /* set up common data for all our workers */
+ /* Set up common data for all our workers */
memset(&worker, 0, sizeof(worker));
worker.bgw_flags = BGWORKER_SHMEM_ACCESS |
BGWORKER_BACKEND_DATABASE_CONNECTION;
--
2.25.1