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.
This commit is contained in:
Ian Barwick
2015-11-17 13:10:23 +09:00
committed by Ian Barwick
parent 0ee2a1e6ba
commit df3e55fa35

View File

@@ -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);