From df3e55fa35aae61a84e1ab65da349040280be6cd Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 17 Nov 2015 13:10:23 +0900 Subject: [PATCH] get_master_connection(): order node list by node type and priority This should make it more likely that the actual primary is first in the retrieved list, reducing the number of connections to other nodes in the cluster which need to be made. --- dbutils.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dbutils.c b/dbutils.c index 14ab2069..2cfcd219 100644 --- a/dbutils.c +++ b/dbutils.c @@ -601,14 +601,16 @@ get_master_connection(PGconn *standby_conn, char *cluster, } /* find all nodes belonging to this cluster */ - log_info(_("finding node list for cluster '%s'\n"), + log_info(_("retrieving node list for cluster '%s'\n"), cluster); sqlquery_snprintf(sqlquery, - "SELECT id, conninfo " - " FROM %s.repl_nodes " - " WHERE cluster = '%s' " - " AND type != 'witness' ", + " SELECT id, conninfo, " + " CASE WHEN type = 'master' THEN 1 ELSE 2 END AS type_priority" + " FROM %s.repl_nodes " + " WHERE cluster = '%s' " + " AND type != 'witness' " + "ORDER BY type_priority, priority, active, id", get_repmgr_schema_quoted(standby_conn), cluster);