diff --git a/configfile.c b/configfile.c index 85842238..0e5f93b0 100644 --- a/configfile.c +++ b/configfile.c @@ -364,11 +364,13 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * options->primary_visibility_consensus = false; memset(options->failover_validation_command, 0, sizeof(options->failover_validation_command)); options->election_rerun_interval = DEFAULT_ELECTION_RERUN_INTERVAL; + options->child_nodes_check_interval = DEFAULT_CHILD_NODES_CHECK_INTERVAL; - memset(options->child_nodes_disconnect_command, 0, sizeof(options->child_nodes_disconnect_command)); options->child_nodes_disconnect_min_count = DEFAULT_CHILD_NODES_DISCONNECT_MIN_COUNT; options->child_nodes_connected_min_count = DEFAULT_CHILD_NODES_CONNECTED_MIN_COUNT; + options->child_nodes_connected_include_witness = DEFAULT_CHILD_NODES_CONNECTED_INCLUDE_WITNESS; options->child_nodes_disconnect_timeout = DEFAULT_CHILD_NODES_DISCONNECT_TIMEOUT; + memset(options->child_nodes_disconnect_command, 0, sizeof(options->child_nodes_disconnect_command)); /*------------- * witness settings @@ -675,6 +677,8 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * options->child_nodes_disconnect_min_count = repmgr_atoi(value, name, error_list, -1); else if (strcmp(name, "child_nodes_connected_min_count") == 0) options->child_nodes_connected_min_count = repmgr_atoi(value, name, error_list, -1); + else if (strcmp(name, "child_nodes_connected_include_witness") == 0) + options->child_nodes_connected_include_witness = parse_bool(value, name, error_list); else if (strcmp(name, "child_nodes_disconnect_timeout") == 0) options->child_nodes_disconnect_timeout = repmgr_atoi(value, name, error_list, 0); @@ -1117,6 +1121,7 @@ parse_time_unit_parameter(const char *name, const char *value, char *dest, ItemL * - bdr_recovery_timeout * - child_nodes_check_interval * - child_nodes_connected_min_count + * - child_nodes_connected_include_witness * - child_nodes_disconnect_command * - child_nodes_disconnect_min_count * - child_nodes_disconnect_timeout @@ -1328,6 +1333,15 @@ reload_config(t_configuration_options *orig_options, t_server_type server_type) } } + /* child_nodes_connected_include_witness */ + if (orig_options->child_nodes_connected_include_witness != new_options.child_nodes_connected_include_witness) + { + orig_options->child_nodes_connected_include_witness = new_options.child_nodes_connected_include_witness; + log_info(_("\"child_nodes_connected_include_witness\" is now \"%i\""), new_options.child_nodes_connected_include_witness); + + config_changed = true; + } + /* child_nodes_disconnect_timeout */ if (orig_options->child_nodes_disconnect_timeout != new_options.child_nodes_disconnect_timeout) { diff --git a/configfile.h b/configfile.h index edbd833a..5759de7d 100644 --- a/configfile.h +++ b/configfile.h @@ -151,6 +151,7 @@ typedef struct int child_nodes_check_interval; int child_nodes_disconnect_min_count; int child_nodes_connected_min_count; + bool child_nodes_connected_include_witness; int child_nodes_disconnect_timeout; char child_nodes_disconnect_command[MAXPGPATH]; @@ -229,6 +230,7 @@ typedef struct DEFAULT_CHILD_NODES_CHECK_INTERVAL, \ DEFAULT_CHILD_NODES_DISCONNECT_MIN_COUNT, \ DEFAULT_CHILD_NODES_CONNECTED_MIN_COUNT, \ + DEFAULT_CHILD_NODES_CONNECTED_INCLUDE_WITNESS, \ DEFAULT_CHILD_NODES_DISCONNECT_TIMEOUT, "", \ /* BDR settings */ \ false, DEFAULT_BDR_RECOVERY_TIMEOUT, \ diff --git a/repmgr.h b/repmgr.h index fc386f02..23f3ec17 100644 --- a/repmgr.h +++ b/repmgr.h @@ -100,7 +100,7 @@ #define DEFAULT_CHILD_NODES_DISCONNECT_MIN_COUNT -1 #define DEFAULT_CHILD_NODES_CONNECTED_MIN_COUNT -1 #define DEFAULT_CHILD_NODES_DISCONNECT_TIMEOUT 30 /* seconds */ - +#define DEFAULT_CHILD_NODES_CONNECTED_INCLUDE_WITNESS false #define WALRECEIVER_DISABLE_TIMEOUT_VALUE 86400000 /* milliseconds */ diff --git a/repmgrd-physical.c b/repmgrd-physical.c index 731368bc..d736a697 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -1026,7 +1026,10 @@ check_primary_child_nodes(t_child_node_info_list *local_child_nodes) bool repmgrd_paused = repmgrd_is_paused(local_conn); if (repmgrd_paused == false) + { + /* check criteria for execution, and execute if criteria met */ execute_child_nodes_disconnect_command(&db_child_node_records, local_child_nodes); + } } clear_child_node_info_list(&disconnected_child_nodes); @@ -1060,14 +1063,34 @@ execute_child_nodes_disconnect_command(NodeInfoList *db_child_node_records, t_ch } else if (config_file_options.child_nodes_disconnect_min_count > 0) { + int child_node_count = db_child_node_records->node_count; + + if (config_file_options.child_nodes_connected_include_witness == false) + { + /* reduce total, if witness server in child node list */ + for (cell = db_child_node_records->head; cell; cell = cell->next) + { + if (cell->node_info->type == WITNESS) + { + child_node_count--; + break; + } + } + } + min_required_connected_count = - (db_child_node_records->node_count - config_file_options.child_nodes_disconnect_min_count) + (child_node_count - config_file_options.child_nodes_disconnect_min_count) + 1; } /* calculate number of connected child nodes */ for (cell = db_child_node_records->head; cell; cell = cell->next) { + /* exclude witness server from total, if necessay */ + if (config_file_options.child_nodes_connected_include_witness == false && + cell->node_info->type == WITNESS) + continue; + if (cell->node_info->attached == NODE_ATTACHED) connected_count ++; } @@ -1101,6 +1124,11 @@ execute_child_nodes_disconnect_command(NodeInfoList *db_child_node_records, t_ch instr_time current_time = current_time_base; int seconds_since_detached; + /* exclude witness server from calculatin if neccessary */ + if (config_file_options.child_nodes_connected_include_witness == false && + child_node_rec->type == WITNESS) + continue; + if (child_node_rec->attached != NODE_DETACHED) continue;