From 7df2fb7b74a3c5287319e56112840d9c2a3e7d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Villemain?= Date: Thu, 3 Feb 2011 18:42:36 +0100 Subject: [PATCH] Change the is_pgup () check test remove spurious 'return' --- dbutils.c | 16 ++++++++-------- repmgrd.c | 14 ++------------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/dbutils.c b/dbutils.c index bdbf63875..0276f46e4 100644 --- a/dbutils.c +++ b/dbutils.c @@ -131,7 +131,14 @@ is_pgup(PGconn *conn) /* Check the connection status twice in case it changes after reset */ for (;;) { - if (PQstatus(conn) == CONNECTION_OK) + if (PQstatus(conn) != CONNECTION_OK) + { + if (twice) + return false; + PQreset(conn); // reconnect + twice = true; + } + else { /* * Send a SELECT 1 just to check if connection is OK @@ -158,13 +165,6 @@ is_pgup(PGconn *conn) return true; } } - else - { - if (twice) - return false; - PQreset(conn); // reconnect - twice = true; - } } } diff --git a/repmgrd.c b/repmgrd.c index 71a4cbb55..74d455a41 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -305,7 +305,7 @@ WitnessMonitor(void) * Check if the master is still available, if after 5 minutes of retries * we cannot reconnect, return false. */ - return CheckPrimaryConnection(); // this take up to NUM_RETRY * SLEEP_RETRY seconds + CheckPrimaryConnection(); // this take up to NUM_RETRY * SLEEP_RETRY seconds } /* * Insert monitor info, this is basically the time and xlog replayed, @@ -651,17 +651,7 @@ CheckPrimaryConnection(void) { log_err(_("\n%s: We couldn't reconnect for long enough, exiting...\n", progname)); /* XXX Anything else to do here? */ - exit(ERR_BAD_CON); - } - - /* Send a SELECT 1 just to check if connection is OK */ - sprintf(sqlquery, "SELECT 1"); - res = PQexec(primaryConn, sqlquery); - if (PQresultStatus(res) != PGRES_TUPLES_OK) - { - log_err(_("PQexec failed: %s\n", PQerrorMessage(primaryConn))); - PQclear(res); - return; + return false; } return true; }