From e92856835f77f1458d5c7834cd9ad09979c61f2e Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Thu, 28 Jun 2018 11:30:01 +0900 Subject: [PATCH] Fix find_primary_node() return value in commit f0631a6. In this commit find_primary_node() returns 0, rather than -1 if no primary node exists. This is not correct and should be set to -1. Also fix some thinko in this commit. Problem pointed out by Muhammad Usama. --- src/main/pgpool_main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index 08e60c47c..03ff3aef8 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -2947,12 +2947,12 @@ verify_backend_node_status(POOL_CONNECTION_POOL_SLOT **slots) { if (pool_node_status[i] == POOL_NODE_STATUS_PRIMARY) { - pool_node_status[i] = POOL_NODE_STATUS_UNUSED; - ereport(DEBUG1, - (errmsg("verify_backend_node_status: node %d is a false primary", i))); - if (pool_config->detach_false_primary) + { + ereport(DEBUG1, + (errmsg("verify_backend_node_status: node %d is a false primary", i))); pool_node_status[i] = POOL_NODE_STATUS_INVALID; + } else pool_node_status[i] = POOL_NODE_STATUS_UNUSED; } @@ -2979,6 +2979,13 @@ verify_backend_node_status(POOL_CONNECTION_POOL_SLOT **slots) ereport(DEBUG1, (errmsg("verify_backend_node_status: multiple standbys: %d", num_standbys))); + if (!pool_config->detach_false_primary) + { + ereport(DEBUG1, + (errmsg("verify_backend_node_status: detach_false_primary is off and no additional checking is performed"))); + return pool_node_status; + } + /* * Check connectivity between primary and standby by using * pg_stat_wal_receiver (only >= 9.6.0) if there's more than or equal @@ -3137,7 +3144,7 @@ static int find_primary_node(void) POOL_CONNECTION_POOL_SLOT *slots[MAX_NUM_BACKENDS]; int i; POOL_NODE_STATUS *status; - int primary = 0; + int primary = -1; /* Streaming replication mode? */ if (!SL_MODE) -- 2.39.5