Consolidate replication connection code

In a few places, replication connections are generated from the
parameters used by existing connections. This has resulted in a
number of similar blocks of code which do more-or-less the same
thing almost but not quite identically. In two cases, the code
omitted to set "dbname=replication", which can cause problems
in some contexts.

These code blocks have now been consolidated into standardized
functions.

This also resolves the issue addressed by GitHub #619.
This commit is contained in:
Ian Barwick
2020-03-05 15:12:03 +09:00
parent 10304a1a3b
commit 9de31428f1
6 changed files with 59 additions and 77 deletions

View File

@@ -918,7 +918,6 @@ do_node_check_replication_connection(void)
PGconn *repl_conn = NULL;
t_node_info node_record = T_NODE_INFO_INITIALIZER;
RecordStatus record_status = RECORD_NOT_FOUND;
t_conninfo_param_list remote_conninfo = T_CONNINFO_PARAM_LIST_INITIALIZER;
PQExpBufferData output;
@@ -948,17 +947,8 @@ do_node_check_replication_connection(void)
return;
}
initialize_conninfo_params(&remote_conninfo, false);
parse_conninfo_string(node_record.conninfo, &remote_conninfo, NULL, false);
if (strcmp(param_get(&remote_conninfo, "user"), node_record.repluser) != 0)
{
param_set(&remote_conninfo, "user", node_record.repluser);
param_set(&remote_conninfo, "dbname", "replication");
}
param_set(&remote_conninfo, "replication", "1");
repl_conn = establish_db_connection_by_params(&remote_conninfo, false);
repl_conn = establish_replication_connection_from_conninfo(node_record.conninfo,
node_record.repluser);
if (PQstatus(repl_conn) != CONNECTION_OK)
{