"repmgr bdr register": improve node name check

We'll use "bdr.bdr_get_local_node_name()" to check the local BDR node
name and the repmgr one match.
This commit is contained in:
Ian Barwick
2018-01-04 16:07:06 +09:00
parent 7476dc84f2
commit c5c86e1ada
3 changed files with 39 additions and 21 deletions

View File

@@ -4289,7 +4289,7 @@ add_table_to_bdr_replication_set(PGconn *conn, const char *tablename, const char
bool
bdr_node_exists(PGconn *conn, const char *node_name)
bdr_node_name_matches(PGconn *conn, const char *node_name, PQExpBufferData *bdr_local_node_name)
{
PQExpBufferData query;
PGresult *res = NULL;
@@ -4298,10 +4298,7 @@ bdr_node_exists(PGconn *conn, const char *node_name)
initPQExpBuffer(&query);
appendPQExpBuffer(&query,
"SELECT COUNT(*)"
" FROM bdr.bdr_nodes"
" WHERE node_name = '%s'",
node_name);
"SELECT bdr.bdr_get_local_node_name() AS node_name");
res = PQexec(conn, query.data);
termPQExpBuffer(&query);
@@ -4312,7 +4309,9 @@ bdr_node_exists(PGconn *conn, const char *node_name)
}
else
{
node_exists = atoi(PQgetvalue(res, 0, 0)) == 1 ? true : false;
node_exists = true;
appendPQExpBuffer(bdr_local_node_name,
"%s", PQgetvalue(res, 0, 0));
}
PQclear(res);

View File

@@ -498,8 +498,7 @@ bool is_bdr_repmgr(PGconn *conn);
bool is_table_in_bdr_replication_set(PGconn *conn, const char *tablename, const char *set);
bool add_table_to_bdr_replication_set(PGconn *conn, const char *tablename, const char *set);
void add_extension_tables_to_bdr_replication_set(PGconn *conn);
bool bdr_node_exists(PGconn *conn, const char *node_name);
bool bdr_node_name_matches(PGconn *conn, const char *node_name, PQExpBufferData *bdr_local_node_name);
ReplSlotStatus get_bdr_node_replication_slot_status(PGconn *conn, const char *node_name);
void get_bdr_other_node_name(PGconn *conn, int node_id, char *name_buf);

View File

@@ -1,5 +1,5 @@
/*
* repmgr-action-standby.c
* repmgr-action-bdr.c
*
* Implements BDR-related actions for the repmgr command line utility
*
@@ -92,6 +92,38 @@ do_bdr_register(void)
exit(ERR_BAD_CONFIG);
}
/* check for a matching BDR node */
{
PQExpBufferData bdr_local_node_name;
bool node_match = false;
initPQExpBuffer(&bdr_local_node_name);
node_match = bdr_node_name_matches(conn, config_file_options.node_name, &bdr_local_node_name);
if (node_match == false)
{
if (strlen(bdr_local_node_name.data))
{
log_error(_("local node BDR node name is \"%s\", expected: \"%s\""),
bdr_local_node_name.data,
config_file_options.node_name);
log_hint(_("\"node_name\" in repmgr.conf must match \"node_name\" in bdr.bdr_nodes"));
}
else
{
log_error(_("local node does not report BDR node name"));
log_hint(_("ensure this is an active BDR node"));
}
PQfinish(conn);
pfree(dbname);
termPQExpBuffer(&bdr_local_node_name);
exit(ERR_BAD_CONFIG);
}
termPQExpBuffer(&bdr_local_node_name);
}
/* check whether repmgr extension exists, and that any other nodes are BDR */
extension_status = get_repmgr_extension_status(conn);
@@ -142,18 +174,6 @@ do_bdr_register(void)
pfree(dbname);
/* check for a matching BDR node */
{
bool node_exists = bdr_node_exists(conn, config_file_options.node_name);
if (node_exists == false)
{
log_error(_("no BDR node with node_name \"%s\" found"), config_file_options.node_name);
log_hint(_("\"node_name\" in repmgr.conf must match \"node_name\" in bdr.bdr_nodes"));
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
}
/*
* before adding the extension tables to the replication set, if any other