From 63a11f8926886ffaf0bbbb8f8113c4227e210afe Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 27 Feb 2018 10:04:58 +0900 Subject: [PATCH] "standby promote": make timeout values configurable This introduces following new configuration file parameters, which were previously hard-coded values: - promote_check_timeout - promote_check_interval Implements GitHub #387. --- configfile.c | 16 +++++++++++++++- configfile.h | 8 +++++++- doc/repmgr-standby-promote.sgml | 7 +++++++ doc/repmgr-standby-unregister.sgml | 16 ++++++++++++++++ repmgr-action-standby.c | 12 +++++------- repmgr.conf.sample | 16 +++++++++++++++- 6 files changed, 65 insertions(+), 10 deletions(-) diff --git a/configfile.c b/configfile.c index 1954d731..b040b78a 100644 --- a/configfile.c +++ b/configfile.c @@ -303,7 +303,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * options->log_status_interval = DEFAULT_LOG_STATUS_INTERVAL; /*----------------------- - * standby action settings + * standby clone settings *------------------------ */ options->use_replication_slots = false; @@ -317,6 +317,13 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * options->use_primary_conninfo_password = false; memset(options->passfile, 0, sizeof(options->passfile)); + /*----------------------- + * standby promote settings + *------------------------ + */ + options->promote_check_timeout = DEFAULT_PROMOTE_CHECK_TIMEOUT; + options->promote_check_interval = DEFAULT_PROMOTE_CHECK_INTERVAL; + /*----------------- * repmgrd settings *----------------- @@ -506,6 +513,13 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList * else if (strcmp(name, "passfile") == 0) strncpy(options->passfile, value, sizeof(options->passfile)); + /* standby promote settings */ + else if (strcmp(name, "promote_check_timeout") == 0) + options->promote_check_timeout = repmgr_atoi(value, name, error_list, 1); + + else if (strcmp(name, "promote_check_interval") == 0) + options->promote_check_interval = repmgr_atoi(value, name, error_list, 1); + /* node check settings */ else if (strcmp(name, "archive_ready_warning") == 0) options->archive_ready_warning = repmgr_atoi(value, name, error_list, 1); diff --git a/configfile.h b/configfile.h index ca2e982c..873caa40 100644 --- a/configfile.h +++ b/configfile.h @@ -82,7 +82,7 @@ typedef struct char log_file[MAXLEN]; int log_status_interval; - /* standby action settings */ + /* standby clone settings */ bool use_replication_slots; char pg_basebackup_options[MAXLEN]; char restore_command[MAXLEN]; @@ -92,6 +92,10 @@ typedef struct bool use_primary_conninfo_password; char passfile[MAXPGPATH]; + /* standby promote settings */ + int promote_check_timeout; + int promote_check_interval; + /* node check settings */ int archive_ready_warning; int archive_ready_critical; @@ -159,6 +163,8 @@ typedef struct "", "", "", DEFAULT_LOG_STATUS_INTERVAL, \ /* standby action settings */ \ false, "", "", { NULL, NULL }, "", false, false, "", \ + /* standby promote settings */ \ + DEFAULT_PROMOTE_CHECK_TIMEOUT, DEFAULT_PROMOTE_CHECK_INTERVAL, \ /* node check settings */ \ DEFAULT_ARCHIVE_READY_WARNING, DEFAULT_ARCHIVE_READY_CRITICAL, \ DEFAULT_REPLICATION_LAG_WARNING, DEFAULT_REPLICATION_LAG_CRITICAL, \ diff --git a/doc/repmgr-standby-promote.sgml b/doc/repmgr-standby-promote.sgml index 4515195e..4a80fb42 100644 --- a/doc/repmgr-standby-promote.sgml +++ b/doc/repmgr-standby-promote.sgml @@ -26,6 +26,12 @@ by using ; if repmgrd is active, it will handle this automatically. + + Note that &repmgr; will wait for up to promote_check_timeout seconds + (default: 60 seconds) to verify that the standby has been promoted, and will + check the promotion every promote_check_interval seconds (default: 1 second) + (both values can be defined in repmgr.conf). + @@ -42,6 +48,7 @@ + Event notifications diff --git a/doc/repmgr-standby-unregister.sgml b/doc/repmgr-standby-unregister.sgml index 2294391b..50c37ec5 100644 --- a/doc/repmgr-standby-unregister.sgml +++ b/doc/repmgr-standby-unregister.sgml @@ -43,6 +43,22 @@ + + Options + + + + + + + node_id of the node to unregister (optional) + + + + + + + Event notifications diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 9b1ce60a..dec9d79f 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -1877,10 +1877,8 @@ static void _do_standby_promote_internal(PGconn *conn, const char *data_dir) { char script[MAXLEN]; - int r; - int i, - promote_check_timeout = 60, - promote_check_interval = 2; + int r, + i; bool promote_success = false; PQExpBufferData details; @@ -1927,8 +1925,7 @@ _do_standby_promote_internal(PGconn *conn, const char *data_dir) exit(ERR_PROMOTION_FAIL); } - /* TODO: make these values configurable */ - for (i = 0; i < promote_check_timeout; i += promote_check_interval) + for (i = 0; i < config_file_options.promote_check_timeout; i += config_file_options.promote_check_interval) { recovery_type = get_recovery_type(conn); @@ -1937,7 +1934,7 @@ _do_standby_promote_internal(PGconn *conn, const char *data_dir) promote_success = true; break; } - sleep(promote_check_interval); + sleep(config_file_options.promote_check_interval); } if (promote_success == false) @@ -1956,6 +1953,7 @@ _do_standby_promote_internal(PGconn *conn, const char *data_dir) } } + log_verbose(LOG_INFO, _("standby promoted to primary after %i second(s)"), i); /* update node information to reflect new status */ if (update_node_record_set_primary(conn, config_file_options.node_id) == false) diff --git a/repmgr.conf.sample b/repmgr.conf.sample index bac15306..84274c59 100644 --- a/repmgr.conf.sample +++ b/repmgr.conf.sample @@ -161,7 +161,7 @@ ssh_options='-q -o ConnectTimeout=10' # Options to append to "ssh" #------------------------------------------------------------------------------ -# Standby clone settings +# "standby clone" settings #------------------------------------------------------------------------------ # # These settings apply when cloning a standby ("repmgr standby clone"). @@ -178,6 +178,20 @@ ssh_options='-q -o ConnectTimeout=10' # Options to append to "ssh" #restore_command='' # This will be placed in the recovery.conf # file generated by repmgr + +#------------------------------------------------------------------------------ +# "standby promote" settings +#------------------------------------------------------------------------------ + +# These settings apply when instructing a standby to promote itself to the +# new primary ("repmgr standby promote"). + +#promote_check_timeout=60 # The length of time (in seconds) to wait + # for the new primary to finish promoting +#promote_check_interval=1 # The interval (in seconds) to check whether + # the new primary has finished promoting + + #------------------------------------------------------------------------------ # Standby follow settings #------------------------------------------------------------------------------