From dad4ae45515e566477c5574232a7ced1f957a89a Mon Sep 17 00:00:00 2001 From: Euler Taveira Date: Thu, 21 Mar 2024 23:38:11 -0300 Subject: [PATCH v34 3/4] Check both servers before exiting The current code provides multiple errors for each server. If any subscriber condition is not met, it terminates without checking the publisher conditions. This change allows it to check both servers before terminating if any condition is not met. It saves at least one dry run execution. --- src/bin/pg_basebackup/pg_createsubscriber.c | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index 3a8240ea78..1139c15896 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -76,9 +76,9 @@ static uint64 get_standby_sysid(const char *datadir); static void modify_subscriber_sysid(const struct CreateSubscriberOptions *opt); static bool server_is_in_recovery(PGconn *conn); static char *generate_object_name(PGconn *conn); -static void check_publisher(const struct LogicalRepInfo *dbinfo); +static bool check_publisher(const struct LogicalRepInfo *dbinfo); static char *setup_publisher(struct LogicalRepInfo *dbinfo); -static void check_subscriber(const struct LogicalRepInfo *dbinfo); +static bool check_subscriber(const struct LogicalRepInfo *dbinfo); static void setup_subscriber(struct LogicalRepInfo *dbinfo, const char *consistent_lsn); static void setup_recovery(const struct LogicalRepInfo *dbinfo, const char *datadir, @@ -798,7 +798,7 @@ server_is_in_recovery(PGconn *conn) * * XXX Does it not allow a synchronous replica? */ -static void +static bool check_publisher(const struct LogicalRepInfo *dbinfo) { PGconn *conn; @@ -939,8 +939,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo) failed = true; } - if (failed) - exit(1); + return failed; } /* @@ -954,7 +953,7 @@ check_publisher(const struct LogicalRepInfo *dbinfo) * there is not a reliable way to provide a suitable error saying the server C * will be broken at the end of this process (due to pg_resetwal). */ -static void +static bool check_subscriber(const struct LogicalRepInfo *dbinfo) { PGconn *conn; @@ -1045,8 +1044,7 @@ check_subscriber(const struct LogicalRepInfo *dbinfo) failed = true; } - if (failed) - exit(1); + return failed; } /* @@ -1763,6 +1761,9 @@ main(int argc, char **argv) char pidfile[MAXPGPATH]; + bool failed_pub = false; + bool failed_sub = false; + pg_logging_init(argv[0]); pg_logging_set_level(PG_LOG_WARNING); progname = get_progname(argv[0]); @@ -2051,7 +2052,7 @@ main(int argc, char **argv) start_standby_server(&opt, true); /* Check if the standby server is ready for logical replication */ - check_subscriber(dbinfo); + failed_sub = check_subscriber(dbinfo); /* * Check if the primary server is ready for logical replication. This @@ -2059,7 +2060,10 @@ main(int argc, char **argv) * on check_subscriber() to obtain the primary_slot_name. That's why it is * called after it. */ - check_publisher(dbinfo); + failed_pub = check_publisher(dbinfo); + + if (failed_pub || failed_sub) + exit(1); /* * Stop the target server. The recovery process requires that the server -- 2.43.0