pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Nathan Bossart <nathandbossart@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers@postgresql.org
Subject: Re: recovery modules
Date: Fri, 27 Jan 2023 22:27:29 -0800
Message-ID: <20230128062729.GA2570237@nathanxps13> (raw )
In-Reply-To: <20230128041746.GA2288302@nathanxps13 >
References: <20230117182356.GA3015764@nathanxps13 >
<Y8dZgIeqsLe6NP6B@paquier.xyz >
<20230118044427.GA3369836@nathanxps13 >
<Y830qTRZJP6XGuOF@paquier.xyz >
<20230123214428.GA572995@nathanxps13 >
<Y9Dbfe3C0wGJqyav@paquier.xyz >
<20230128002319.362oxrxf7ardfz2a@awork3.anarazel.de >
<20230128005910.GA2245287@nathanxps13 >
<20230128015542.baefifnqgpgtkij6@awork3.anarazel.de >
<20230128041746.GA2288302@nathanxps13 >
On Fri, Jan 27, 2023 at 08:17:46PM -0800, Nathan Bossart wrote:
> On Fri, Jan 27, 2023 at 05:55:42PM -0800, Andres Freund wrote:
>> On 2023-01-27 16:59:10 -0800, Nathan Bossart wrote:
>>> I think it would be weird for the archive module and
>>> recovery module interfaces to look so different, but if that's okay, I can
>>> change it.
>>
>> I'm a bit sad about the archive module case - I wonder if we should change it
>> now, there can't be many users of it out there. And I think it's more likely
>> that we'll eventually want multiple archiving scripts to run concurrently -
>> which will be quite hard with the current interface (no private state).
>
> I'm open to that. IIUC it wouldn't require too many changes to existing
> archive modules, and if it gets us closer to batching or parallelism, it's
> probably worth doing sooner than later.
Here is a work-in-progress patch set for adjusting the archive modules
interface. Is this roughly what you had in mind?
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
Attachments:
[text/x-diff] 0001-s-ArchiveContext-ArchiveCallbacks.patch (2.8K, ../20230128062729.GA2570237@nathanxps13/2-0001-s-ArchiveContext-ArchiveCallbacks.patch)
download | inline diff:
From f865032283d0c937ff1c47441d70a2b11e89d3f4 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathandbossart@gmail.com>
Date: Fri, 27 Jan 2023 21:01:22 -0800
Subject: [PATCH 1/4] s/ArchiveContext/ArchiveCallbacks
---
src/backend/postmaster/pgarch.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 8ecdb9ca23..36800127e8 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -97,7 +97,7 @@ char *XLogArchiveLibrary = "";
*/
static time_t last_sigterm_time = 0;
static PgArchData *PgArch = NULL;
-static ArchiveModuleCallbacks ArchiveContext;
+static ArchiveModuleCallbacks ArchiveCallbacks;
/*
@@ -416,8 +416,8 @@ pgarch_ArchiverCopyLoop(void)
HandlePgArchInterrupts();
/* can't do anything if not configured ... */
- if (ArchiveContext.check_configured_cb != NULL &&
- !ArchiveContext.check_configured_cb())
+ if (ArchiveCallbacks.check_configured_cb != NULL &&
+ !ArchiveCallbacks.check_configured_cb())
{
ereport(WARNING,
(errmsg("archive_mode enabled, yet archiving is not configured")));
@@ -518,7 +518,7 @@ pgarch_archiveXlog(char *xlog)
snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
set_ps_display(activitymsg);
- ret = ArchiveContext.archive_file_cb(xlog, pathname);
+ ret = ArchiveCallbacks.archive_file_cb(xlog, pathname);
if (ret)
snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog);
else
@@ -824,7 +824,7 @@ HandlePgArchInterrupts(void)
/*
* LoadArchiveLibrary
*
- * Loads the archiving callbacks into our local ArchiveContext.
+ * Loads the archiving callbacks into our local ArchiveCallbacks.
*/
static void
LoadArchiveLibrary(void)
@@ -837,7 +837,7 @@ LoadArchiveLibrary(void)
errmsg("both archive_command and archive_library set"),
errdetail("Only one of archive_command, archive_library may be set.")));
- memset(&ArchiveContext, 0, sizeof(ArchiveModuleCallbacks));
+ memset(&ArchiveCallbacks, 0, sizeof(ArchiveModuleCallbacks));
/*
* If shell archiving is enabled, use our special initialization function.
@@ -854,9 +854,9 @@ LoadArchiveLibrary(void)
ereport(ERROR,
(errmsg("archive modules have to define the symbol %s", "_PG_archive_module_init")));
- (*archive_init) (&ArchiveContext);
+ (*archive_init) (&ArchiveCallbacks);
- if (ArchiveContext.archive_file_cb == NULL)
+ if (ArchiveCallbacks.archive_file_cb == NULL)
ereport(ERROR,
(errmsg("archive modules must register an archive callback")));
@@ -869,6 +869,6 @@ LoadArchiveLibrary(void)
static void
pgarch_call_module_shutdown_cb(int code, Datum arg)
{
- if (ArchiveContext.shutdown_cb != NULL)
- ArchiveContext.shutdown_cb();
+ if (ArchiveCallbacks.shutdown_cb != NULL)
+ ArchiveCallbacks.shutdown_cb();
}
--
2.25.1
[text/x-diff] 0002-move-archive-module-exports-to-dedicated-header.patch (6.0K, ../20230128062729.GA2570237@nathanxps13/3-0002-move-archive-module-exports-to-dedicated-header.patch)
download | inline diff:
From 1ea6fb293a1e69e6fdd39e1d6b96a0af601d8542 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathandbossart@gmail.com>
Date: Fri, 27 Jan 2023 21:16:34 -0800
Subject: [PATCH 2/4] move archive module exports to dedicated header
---
contrib/basic_archive/basic_archive.c | 2 +-
src/backend/postmaster/pgarch.c | 1 +
src/backend/postmaster/shell_archive.c | 2 +-
src/backend/utils/misc/guc_tables.c | 1 +
src/include/postmaster/archive_module.h | 54 +++++++++++++++++++++++++
src/include/postmaster/pgarch.h | 39 ------------------
6 files changed, 58 insertions(+), 41 deletions(-)
create mode 100644 src/include/postmaster/archive_module.h
diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c
index 3d29711a31..87bbb2174d 100644
--- a/contrib/basic_archive/basic_archive.c
+++ b/contrib/basic_archive/basic_archive.c
@@ -32,7 +32,7 @@
#include "common/int.h"
#include "miscadmin.h"
-#include "postmaster/pgarch.h"
+#include "postmaster/archive_module.h"
#include "storage/copydir.h"
#include "storage/fd.h"
#include "utils/guc.h"
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 36800127e8..eca02d5e74 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -34,6 +34,7 @@
#include "lib/binaryheap.h"
#include "libpq/pqsignal.h"
#include "pgstat.h"
+#include "postmaster/archive_module.h"
#include "postmaster/interrupt.h"
#include "postmaster/pgarch.h"
#include "storage/fd.h"
diff --git a/src/backend/postmaster/shell_archive.c b/src/backend/postmaster/shell_archive.c
index 806b81c3f2..b64297e3bb 100644
--- a/src/backend/postmaster/shell_archive.c
+++ b/src/backend/postmaster/shell_archive.c
@@ -20,7 +20,7 @@
#include "access/xlog.h"
#include "common/percentrepl.h"
#include "pgstat.h"
-#include "postmaster/pgarch.h"
+#include "postmaster/archive_module.h"
static bool shell_archive_configured(void);
static bool shell_archive_file(const char *file, const char *path);
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 4ac808ed22..5ebec364a2 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -52,6 +52,7 @@
#include "parser/parse_expr.h"
#include "parser/parser.h"
#include "pgstat.h"
+#include "postmaster/archive_module.h"
#include "postmaster/autovacuum.h"
#include "postmaster/bgworker_internals.h"
#include "postmaster/bgwriter.h"
diff --git a/src/include/postmaster/archive_module.h b/src/include/postmaster/archive_module.h
new file mode 100644
index 0000000000..099050c1ca
--- /dev/null
+++ b/src/include/postmaster/archive_module.h
@@ -0,0 +1,54 @@
+/*-------------------------------------------------------------------------
+ *
+ * archive_module.h
+ * Exports for archive modules.
+ *
+ * Copyright (c) 2022-2023, PostgreSQL Global Development Group
+ *
+ * src/include/postmaster/archive_module.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef _ARCHIVE_MODULE_H
+#define _ARCHIVE_MODULE_H
+
+/*
+ * The value of the archive_library GUC.
+ */
+extern PGDLLIMPORT char *XLogArchiveLibrary;
+
+/*
+ * Archive module callbacks
+ *
+ * These callback functions should be defined by archive libraries and returned
+ * via _PG_archive_module_init(). ArchiveFileCB is the only required callback.
+ * For more information about the purpose of each callback, refer to the
+ * archive modules documentation.
+ */
+typedef bool (*ArchiveCheckConfiguredCB) (void);
+typedef bool (*ArchiveFileCB) (const char *file, const char *path);
+typedef void (*ArchiveShutdownCB) (void);
+
+typedef struct ArchiveModuleCallbacks
+{
+ ArchiveCheckConfiguredCB check_configured_cb;
+ ArchiveFileCB archive_file_cb;
+ ArchiveShutdownCB shutdown_cb;
+} ArchiveModuleCallbacks;
+
+/*
+ * Type of the shared library symbol _PG_archive_module_init that is looked
+ * up when loading an archive library.
+ */
+typedef void (*ArchiveModuleInit) (ArchiveModuleCallbacks *cb);
+
+extern PGDLLEXPORT void _PG_archive_module_init(ArchiveModuleCallbacks *cb);
+
+/*
+ * Since the logic for archiving via a shell command is in the core server
+ * and does not need to be loaded via a shared library, it has a special
+ * initialization function.
+ */
+extern void shell_archive_init(ArchiveModuleCallbacks *cb);
+
+#endif /* _ARCHIVE_MODULE_H */
diff --git a/src/include/postmaster/pgarch.h b/src/include/postmaster/pgarch.h
index bcd51dfad6..3bd4fac71e 100644
--- a/src/include/postmaster/pgarch.h
+++ b/src/include/postmaster/pgarch.h
@@ -33,43 +33,4 @@ extern void PgArchiverMain(void) pg_attribute_noreturn();
extern void PgArchWakeup(void);
extern void PgArchForceDirScan(void);
-/*
- * The value of the archive_library GUC.
- */
-extern PGDLLIMPORT char *XLogArchiveLibrary;
-
-/*
- * Archive module callbacks
- *
- * These callback functions should be defined by archive libraries and returned
- * via _PG_archive_module_init(). ArchiveFileCB is the only required callback.
- * For more information about the purpose of each callback, refer to the
- * archive modules documentation.
- */
-typedef bool (*ArchiveCheckConfiguredCB) (void);
-typedef bool (*ArchiveFileCB) (const char *file, const char *path);
-typedef void (*ArchiveShutdownCB) (void);
-
-typedef struct ArchiveModuleCallbacks
-{
- ArchiveCheckConfiguredCB check_configured_cb;
- ArchiveFileCB archive_file_cb;
- ArchiveShutdownCB shutdown_cb;
-} ArchiveModuleCallbacks;
-
-/*
- * Type of the shared library symbol _PG_archive_module_init that is looked
- * up when loading an archive library.
- */
-typedef void (*ArchiveModuleInit) (ArchiveModuleCallbacks *cb);
-
-extern PGDLLEXPORT void _PG_archive_module_init(ArchiveModuleCallbacks *cb);
-
-/*
- * Since the logic for archiving via a shell command is in the core server
- * and does not need to be loaded via a shared library, it has a special
- * initialization function.
- */
-extern void shell_archive_init(ArchiveModuleCallbacks *cb);
-
#endif /* _PGARCH_H */
--
2.25.1
[text/x-diff] 0003-restructure-archive-module-API.patch (6.9K, ../20230128062729.GA2570237@nathanxps13/4-0003-restructure-archive-module-API.patch)
download | inline diff:
From 92eab334ce94b4e5e8dba5189ce2ffbecdeb67e6 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathandbossart@gmail.com>
Date: Fri, 27 Jan 2023 21:57:13 -0800
Subject: [PATCH 3/4] restructure archive module API
---
contrib/basic_archive/basic_archive.c | 13 +++++++++----
src/backend/postmaster/pgarch.c | 18 ++++++++---------
src/backend/postmaster/shell_archive.c | 14 ++++++++-----
src/include/postmaster/archive_module.h | 26 ++++++++++---------------
4 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c
index 87bbb2174d..1655f72b5b 100644
--- a/contrib/basic_archive/basic_archive.c
+++ b/contrib/basic_archive/basic_archive.c
@@ -49,6 +49,12 @@ static void basic_archive_file_internal(const char *file, const char *path);
static bool check_archive_directory(char **newval, void **extra, GucSource source);
static bool compare_files(const char *file1, const char *file2);
+static const ArchiveModuleCallbacks basic_archive_callbacks = {
+ .check_configured_cb = basic_archive_configured,
+ .archive_file_cb = basic_archive_file,
+ .shutdown_cb = NULL
+};
+
/*
* _PG_init
*
@@ -78,13 +84,12 @@ _PG_init(void)
*
* Returns the module's archiving callbacks.
*/
-void
-_PG_archive_module_init(ArchiveModuleCallbacks *cb)
+const ArchiveModuleCallbacks *
+_PG_archive_module_init(void)
{
AssertVariableIsOfType(&_PG_archive_module_init, ArchiveModuleInit);
- cb->check_configured_cb = basic_archive_configured;
- cb->archive_file_cb = basic_archive_file;
+ return &basic_archive_callbacks;
}
/*
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index eca02d5e74..627c579f0e 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -98,7 +98,7 @@ char *XLogArchiveLibrary = "";
*/
static time_t last_sigterm_time = 0;
static PgArchData *PgArch = NULL;
-static ArchiveModuleCallbacks ArchiveCallbacks;
+static const ArchiveModuleCallbacks *ArchiveCallbacks;
/*
@@ -417,8 +417,8 @@ pgarch_ArchiverCopyLoop(void)
HandlePgArchInterrupts();
/* can't do anything if not configured ... */
- if (ArchiveCallbacks.check_configured_cb != NULL &&
- !ArchiveCallbacks.check_configured_cb())
+ if (ArchiveCallbacks->check_configured_cb != NULL &&
+ !ArchiveCallbacks->check_configured_cb())
{
ereport(WARNING,
(errmsg("archive_mode enabled, yet archiving is not configured")));
@@ -519,7 +519,7 @@ pgarch_archiveXlog(char *xlog)
snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
set_ps_display(activitymsg);
- ret = ArchiveCallbacks.archive_file_cb(xlog, pathname);
+ ret = ArchiveCallbacks->archive_file_cb(xlog, pathname);
if (ret)
snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog);
else
@@ -838,8 +838,6 @@ LoadArchiveLibrary(void)
errmsg("both archive_command and archive_library set"),
errdetail("Only one of archive_command, archive_library may be set.")));
- memset(&ArchiveCallbacks, 0, sizeof(ArchiveModuleCallbacks));
-
/*
* If shell archiving is enabled, use our special initialization function.
* Otherwise, load the library and call its _PG_archive_module_init().
@@ -855,9 +853,9 @@ LoadArchiveLibrary(void)
ereport(ERROR,
(errmsg("archive modules have to define the symbol %s", "_PG_archive_module_init")));
- (*archive_init) (&ArchiveCallbacks);
+ ArchiveCallbacks = (*archive_init) ();
- if (ArchiveCallbacks.archive_file_cb == NULL)
+ if (ArchiveCallbacks->archive_file_cb == NULL)
ereport(ERROR,
(errmsg("archive modules must register an archive callback")));
@@ -870,6 +868,6 @@ LoadArchiveLibrary(void)
static void
pgarch_call_module_shutdown_cb(int code, Datum arg)
{
- if (ArchiveCallbacks.shutdown_cb != NULL)
- ArchiveCallbacks.shutdown_cb();
+ if (ArchiveCallbacks->shutdown_cb != NULL)
+ ArchiveCallbacks->shutdown_cb();
}
diff --git a/src/backend/postmaster/shell_archive.c b/src/backend/postmaster/shell_archive.c
index b64297e3bb..dde20c83de 100644
--- a/src/backend/postmaster/shell_archive.c
+++ b/src/backend/postmaster/shell_archive.c
@@ -26,14 +26,18 @@ static bool shell_archive_configured(void);
static bool shell_archive_file(const char *file, const char *path);
static void shell_archive_shutdown(void);
-void
-shell_archive_init(ArchiveModuleCallbacks *cb)
+static const ArchiveModuleCallbacks shell_archive_callbacks = {
+ .check_configured_cb = shell_archive_configured,
+ .archive_file_cb = shell_archive_file,
+ .shutdown_cb = shell_archive_shutdown
+};
+
+const ArchiveModuleCallbacks *
+shell_archive_init(void)
{
AssertVariableIsOfType(&shell_archive_init, ArchiveModuleInit);
- cb->check_configured_cb = shell_archive_configured;
- cb->archive_file_cb = shell_archive_file;
- cb->shutdown_cb = shell_archive_shutdown;
+ return &shell_archive_callbacks;
}
static bool
diff --git a/src/include/postmaster/archive_module.h b/src/include/postmaster/archive_module.h
index 099050c1ca..67b5624874 100644
--- a/src/include/postmaster/archive_module.h
+++ b/src/include/postmaster/archive_module.h
@@ -18,37 +18,31 @@
extern PGDLLIMPORT char *XLogArchiveLibrary;
/*
- * Archive module callbacks
- *
- * These callback functions should be defined by archive libraries and returned
- * via _PG_archive_module_init(). ArchiveFileCB is the only required callback.
- * For more information about the purpose of each callback, refer to the
- * archive modules documentation.
+ * API struct for an archive module. This should be allocated as a static
+ * const struct and returned via _PG_archive_module_init. archive_file_cb is
+ * the only required callback. For more information about the purpose of each
+ * callback, refer to the archive modules documentation.
*/
-typedef bool (*ArchiveCheckConfiguredCB) (void);
-typedef bool (*ArchiveFileCB) (const char *file, const char *path);
-typedef void (*ArchiveShutdownCB) (void);
-
typedef struct ArchiveModuleCallbacks
{
- ArchiveCheckConfiguredCB check_configured_cb;
- ArchiveFileCB archive_file_cb;
- ArchiveShutdownCB shutdown_cb;
+ bool (*check_configured_cb) (void);
+ bool (*archive_file_cb) (const char *file, const char *path);
+ void (*shutdown_cb) (void);
} ArchiveModuleCallbacks;
/*
* Type of the shared library symbol _PG_archive_module_init that is looked
* up when loading an archive library.
*/
-typedef void (*ArchiveModuleInit) (ArchiveModuleCallbacks *cb);
+typedef const ArchiveModuleCallbacks *(*ArchiveModuleInit) (void);
-extern PGDLLEXPORT void _PG_archive_module_init(ArchiveModuleCallbacks *cb);
+extern PGDLLEXPORT const ArchiveModuleCallbacks *_PG_archive_module_init(void);
/*
* Since the logic for archiving via a shell command is in the core server
* and does not need to be loaded via a shared library, it has a special
* initialization function.
*/
-extern void shell_archive_init(ArchiveModuleCallbacks *cb);
+extern const ArchiveModuleCallbacks *shell_archive_init(void);
#endif /* _ARCHIVE_MODULE_H */
--
2.25.1
[text/x-diff] 0004-add-private-state-to-archive-modules.patch (8.3K, ../20230128062729.GA2570237@nathanxps13/5-0004-add-private-state-to-archive-modules.patch)
download | inline diff:
From 5abe0ba43ca079a0af5905ed617795e885be81c9 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathandbossart@gmail.com>
Date: Fri, 27 Jan 2023 22:19:57 -0800
Subject: [PATCH 4/4] add private state to archive modules
---
contrib/basic_archive/basic_archive.c | 27 ++++++++++++-------------
src/backend/postmaster/pgarch.c | 9 +++++----
src/backend/postmaster/shell_archive.c | 14 ++++++-------
src/include/postmaster/archive_module.h | 12 +++++------
4 files changed, 31 insertions(+), 31 deletions(-)
diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c
index 1655f72b5b..fefa79debc 100644
--- a/contrib/basic_archive/basic_archive.c
+++ b/contrib/basic_archive/basic_archive.c
@@ -41,10 +41,9 @@
PG_MODULE_MAGIC;
static char *archive_directory = NULL;
-static MemoryContext basic_archive_context;
-static bool basic_archive_configured(void);
-static bool basic_archive_file(const char *file, const char *path);
+static bool basic_archive_configured(void *arg);
+static bool basic_archive_file(const char *file, const char *path, void *arg);
static void basic_archive_file_internal(const char *file, const char *path);
static bool check_archive_directory(char **newval, void **extra, GucSource source);
static bool compare_files(const char *file1, const char *file2);
@@ -73,22 +72,22 @@ _PG_init(void)
check_archive_directory, NULL, NULL);
MarkGUCPrefixReserved("basic_archive");
-
- basic_archive_context = AllocSetContextCreate(TopMemoryContext,
- "basic_archive",
- ALLOCSET_DEFAULT_SIZES);
}
/*
* _PG_archive_module_init
*
- * Returns the module's archiving callbacks.
+ * Returns the module's archiving callbacks and initializes private state.
*/
const ArchiveModuleCallbacks *
-_PG_archive_module_init(void)
+_PG_archive_module_init(void **arg)
{
AssertVariableIsOfType(&_PG_archive_module_init, ArchiveModuleInit);
+ (*arg) = (void *) AllocSetContextCreate(TopMemoryContext,
+ "basic_archive",
+ ALLOCSET_DEFAULT_SIZES);
+
return &basic_archive_callbacks;
}
@@ -140,7 +139,7 @@ check_archive_directory(char **newval, void **extra, GucSource source)
* Checks that archive_directory is not blank.
*/
static bool
-basic_archive_configured(void)
+basic_archive_configured(void *arg)
{
return archive_directory != NULL && archive_directory[0] != '\0';
}
@@ -151,7 +150,7 @@ basic_archive_configured(void)
* Archives one file.
*/
static bool
-basic_archive_file(const char *file, const char *path)
+basic_archive_file(const char *file, const char *path, void *arg)
{
sigjmp_buf local_sigjmp_buf;
MemoryContext oldcontext;
@@ -161,7 +160,7 @@ basic_archive_file(const char *file, const char *path)
* we can easily reset it during error recovery (thus avoiding memory
* leaks).
*/
- oldcontext = MemoryContextSwitchTo(basic_archive_context);
+ oldcontext = MemoryContextSwitchTo((MemoryContext) arg);
/*
* Since the archiver operates at the bottom of the exception stack,
@@ -188,7 +187,7 @@ basic_archive_file(const char *file, const char *path)
/* Reset our memory context and switch back to the original one */
MemoryContextSwitchTo(oldcontext);
- MemoryContextReset(basic_archive_context);
+ MemoryContextReset((MemoryContext) arg);
/* Remove our exception handler */
PG_exception_stack = NULL;
@@ -211,7 +210,7 @@ basic_archive_file(const char *file, const char *path)
/* Reset our memory context and switch back to the original one */
MemoryContextSwitchTo(oldcontext);
- MemoryContextReset(basic_archive_context);
+ MemoryContextReset((MemoryContext) arg);
return true;
}
diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c
index 627c579f0e..939b5beb00 100644
--- a/src/backend/postmaster/pgarch.c
+++ b/src/backend/postmaster/pgarch.c
@@ -99,6 +99,7 @@ char *XLogArchiveLibrary = "";
static time_t last_sigterm_time = 0;
static PgArchData *PgArch = NULL;
static const ArchiveModuleCallbacks *ArchiveCallbacks;
+static void *arch_module_private = NULL;
/*
@@ -418,7 +419,7 @@ pgarch_ArchiverCopyLoop(void)
/* can't do anything if not configured ... */
if (ArchiveCallbacks->check_configured_cb != NULL &&
- !ArchiveCallbacks->check_configured_cb())
+ !ArchiveCallbacks->check_configured_cb(arch_module_private))
{
ereport(WARNING,
(errmsg("archive_mode enabled, yet archiving is not configured")));
@@ -519,7 +520,7 @@ pgarch_archiveXlog(char *xlog)
snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
set_ps_display(activitymsg);
- ret = ArchiveCallbacks->archive_file_cb(xlog, pathname);
+ ret = ArchiveCallbacks->archive_file_cb(xlog, pathname, arch_module_private);
if (ret)
snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog);
else
@@ -853,7 +854,7 @@ LoadArchiveLibrary(void)
ereport(ERROR,
(errmsg("archive modules have to define the symbol %s", "_PG_archive_module_init")));
- ArchiveCallbacks = (*archive_init) ();
+ ArchiveCallbacks = (*archive_init) (&arch_module_private);
if (ArchiveCallbacks->archive_file_cb == NULL)
ereport(ERROR,
@@ -869,5 +870,5 @@ static void
pgarch_call_module_shutdown_cb(int code, Datum arg)
{
if (ArchiveCallbacks->shutdown_cb != NULL)
- ArchiveCallbacks->shutdown_cb();
+ ArchiveCallbacks->shutdown_cb(arch_module_private);
}
diff --git a/src/backend/postmaster/shell_archive.c b/src/backend/postmaster/shell_archive.c
index dde20c83de..31ceca67a3 100644
--- a/src/backend/postmaster/shell_archive.c
+++ b/src/backend/postmaster/shell_archive.c
@@ -22,9 +22,9 @@
#include "pgstat.h"
#include "postmaster/archive_module.h"
-static bool shell_archive_configured(void);
-static bool shell_archive_file(const char *file, const char *path);
-static void shell_archive_shutdown(void);
+static bool shell_archive_configured(void *arg);
+static bool shell_archive_file(const char *file, const char *path, void *arg);
+static void shell_archive_shutdown(void *arg);
static const ArchiveModuleCallbacks shell_archive_callbacks = {
.check_configured_cb = shell_archive_configured,
@@ -33,7 +33,7 @@ static const ArchiveModuleCallbacks shell_archive_callbacks = {
};
const ArchiveModuleCallbacks *
-shell_archive_init(void)
+shell_archive_init(void **arg)
{
AssertVariableIsOfType(&shell_archive_init, ArchiveModuleInit);
@@ -41,13 +41,13 @@ shell_archive_init(void)
}
static bool
-shell_archive_configured(void)
+shell_archive_configured(void *arg)
{
return XLogArchiveCommand[0] != '\0';
}
static bool
-shell_archive_file(const char *file, const char *path)
+shell_archive_file(const char *file, const char *path, void *arg)
{
char *xlogarchcmd;
char *nativePath = NULL;
@@ -129,7 +129,7 @@ shell_archive_file(const char *file, const char *path)
}
static void
-shell_archive_shutdown(void)
+shell_archive_shutdown(void *arg)
{
elog(DEBUG1, "archiver process shutting down");
}
diff --git a/src/include/postmaster/archive_module.h b/src/include/postmaster/archive_module.h
index 67b5624874..fb4ef8730e 100644
--- a/src/include/postmaster/archive_module.h
+++ b/src/include/postmaster/archive_module.h
@@ -25,24 +25,24 @@ extern PGDLLIMPORT char *XLogArchiveLibrary;
*/
typedef struct ArchiveModuleCallbacks
{
- bool (*check_configured_cb) (void);
- bool (*archive_file_cb) (const char *file, const char *path);
- void (*shutdown_cb) (void);
+ bool (*check_configured_cb) (void *arg);
+ bool (*archive_file_cb) (const char *file, const char *path, void *arg);
+ void (*shutdown_cb) (void *arg);
} ArchiveModuleCallbacks;
/*
* Type of the shared library symbol _PG_archive_module_init that is looked
* up when loading an archive library.
*/
-typedef const ArchiveModuleCallbacks *(*ArchiveModuleInit) (void);
+typedef const ArchiveModuleCallbacks *(*ArchiveModuleInit) (void **arg);
-extern PGDLLEXPORT const ArchiveModuleCallbacks *_PG_archive_module_init(void);
+extern PGDLLEXPORT const ArchiveModuleCallbacks *_PG_archive_module_init(void **arg);
/*
* Since the logic for archiving via a shell command is in the core server
* and does not need to be loaded via a shared library, it has a special
* initialization function.
*/
-extern const ArchiveModuleCallbacks *shell_archive_init(void);
+extern const ArchiveModuleCallbacks *shell_archive_init(void **arg);
#endif /* _ARCHIVE_MODULE_H */
--
2.25.1
view thread (90+ messages) latest in thread
Message-ID: <20230128062729.GA2570237@nathanxps13>
Permalink: ../20230128062729.GA2570237@nathanxps13/
Also on: postgresql.org/message-id/20230128062729.GA2570237@nathanxps13
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, andres@anarazel.de, michael@paquier.xyz
Subject: Re: recovery modules
In-Reply-To: <20230128062729.GA2570237@nathanxps13>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox