aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/slotsync.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2024-03-18 11:35:08 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2024-03-18 11:35:30 +0200
commitaafc05de1bf5c0324cb5e690c6742118c1ac4af6 (patch)
treec750628b17b1175e2ec4bb420275d3b6f2bced6b /src/backend/replication/logical/slotsync.c
parentf1baed18bc3db50c72bfb00b6247b47689158445 (diff)
downloadpostgresql-aafc05de1bf5c0324cb5e690c6742118c1ac4af6.tar.gz
postgresql-aafc05de1bf5c0324cb5e690c6742118c1ac4af6.zip
Refactor postmaster child process launching
Introduce new postmaster_child_launch() function that deals with the differences in EXEC_BACKEND mode. Refactor the mechanism of passing information from the parent to child process. Instead of using different command-line arguments when launching the child process in EXEC_BACKEND mode, pass a variable-length blob of startup data along with all the global variables. The contents of that blob depend on the kind of child process being launched. In !EXEC_BACKEND mode, we use the same blob, but it's simply inherited from the parent to child process. Reviewed-by: Tristan Partin, Andres Freund Discussion: https://www.postgresql.org/message-id/7a59b073-5b5b-151e-7ed3-8b01ff7ce9ef@iki.fi
Diffstat (limited to 'src/backend/replication/logical/slotsync.c')
-rw-r--r--src/backend/replication/logical/slotsync.c72
1 files changed, 4 insertions, 68 deletions
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 5074c8409f7..7b180bdb5c8 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -139,11 +139,6 @@ typedef struct RemoteSlot
ReplicationSlotInvalidationCause invalidated;
} RemoteSlot;
-#ifdef EXEC_BACKEND
-static pid_t slotsyncworker_forkexec(void);
-#endif
-NON_EXEC_STATIC void ReplSlotSyncWorkerMain(int argc, char *argv[]) pg_attribute_noreturn();
-
static void slotsync_failure_callback(int code, Datum arg);
/*
@@ -1113,8 +1108,8 @@ wait_for_slot_activity(bool some_slot_updated)
* It connects to the primary server, fetches logical failover slots
* information periodically in order to create and sync the slots.
*/
-NON_EXEC_STATIC void
-ReplSlotSyncWorkerMain(int argc, char *argv[])
+void
+ReplSlotSyncWorkerMain(char *startup_data, size_t startup_data_len)
{
WalReceiverConn *wrconn = NULL;
char *dbname;
@@ -1122,6 +1117,8 @@ ReplSlotSyncWorkerMain(int argc, char *argv[])
sigjmp_buf local_sigjmp_buf;
StringInfoData app_name;
+ Assert(startup_data_len == 0);
+
MyBackendType = B_SLOTSYNC_WORKER;
init_ps_display(NULL);
@@ -1300,67 +1297,6 @@ ReplSlotSyncWorkerMain(int argc, char *argv[])
}
/*
- * Main entry point for slot sync worker process, to be called from the
- * postmaster.
- */
-int
-StartSlotSyncWorker(void)
-{
- pid_t pid;
-
-#ifdef EXEC_BACKEND
- switch ((pid = slotsyncworker_forkexec()))
- {
-#else
- switch ((pid = fork_process()))
- {
- case 0:
- /* in postmaster child ... */
- InitPostmasterChild();
-
- /* Close the postmaster's sockets */
- ClosePostmasterPorts(false);
-
- ReplSlotSyncWorkerMain(0, NULL);
- break;
-#endif
- case -1:
- ereport(LOG,
- (errmsg("could not fork slot sync worker process: %m")));
- return 0;
-
- default:
- return (int) pid;
- }
-
- /* shouldn't get here */
- return 0;
-}
-
-#ifdef EXEC_BACKEND
-/*
- * The forkexec routine for the slot sync worker process.
- *
- * Format up the arglist, then fork and exec.
- */
-static pid_t
-slotsyncworker_forkexec(void)
-{
- char *av[10];
- int ac = 0;
-
- av[ac++] = "postgres";
- av[ac++] = "--forkssworker";
- av[ac++] = NULL; /* filled in by postmaster_forkexec */
- av[ac] = NULL;
-
- Assert(ac < lengthof(av));
-
- return postmaster_forkexec(ac, av);
-}
-#endif
-
-/*
* Shut down the slot sync worker.
*/
void