"witness register": don't try and read nodes table if it doesn't exist

Previously, "repmgr witness register --dry-run" would attempt to check
for records in the nodes table, but that might not exist yet. Skip
that check if the repmgr extension is not yet installed.

Implements GitHub #513.
This commit is contained in:
Ian Barwick
2018-11-28 15:04:32 +09:00
parent 311f7e561e
commit 2aacd29e60

View File

@@ -37,6 +37,7 @@ do_witness_register(void)
PGconn *witness_conn = NULL; PGconn *witness_conn = NULL;
PGconn *primary_conn = NULL; PGconn *primary_conn = NULL;
RecoveryType recovery_type = RECTYPE_UNKNOWN; RecoveryType recovery_type = RECTYPE_UNKNOWN;
ExtensionStatus extension_status = REPMGR_UNKNOWN;
NodeInfoList nodes = T_NODE_INFO_LIST_INITIALIZER; NodeInfoList nodes = T_NODE_INFO_LIST_INITIALIZER;
t_node_info node_record = T_NODE_INFO_INITIALIZER; t_node_info node_record = T_NODE_INFO_INITIALIZER;
RecordStatus record_status = RECORD_NOT_FOUND; RecordStatus record_status = RECORD_NOT_FOUND;
@@ -214,10 +215,21 @@ do_witness_register(void)
} }
} }
extension_status = get_repmgr_extension_status(witness_conn, NULL);
/* /*
* if repmgr.nodes contains entries, delete if -F/--force provided, * Check if the witness database already contains node records;
* otherwise exit with error * only do this if the extension is actually installed.
*/ */
if (extension_status == REPMGR_INSTALLED
|| extension_status == REPMGR_OLD_VERSION_INSTALLED)
{
/*
* if repmgr.nodes contains entries, exit with error unless
* -F/--force provided (which will cause the existing records
* to be overwritten)
*/
if (get_all_node_records(witness_conn, &nodes) == false) if (get_all_node_records(witness_conn, &nodes) == false)
{ {
/* get_all_node_records() will display the error */ /* get_all_node_records() will display the error */
@@ -241,6 +253,7 @@ do_witness_register(void)
} }
clear_node_info_list(&nodes); clear_node_info_list(&nodes);
}
if (runtime_options.dry_run == true) if (runtime_options.dry_run == true)
{ {