From 5fc4a0382f522625e7c505a1354ebc469519ae77 Mon Sep 17 00:00:00 2001 From: Christian Kruse Date: Fri, 17 Jan 2014 13:50:12 +0100 Subject: [PATCH] added config options sleep_delay and sleep_monitor sleep_monitor replaces the old SLEEP_MONITOR define and makes it configurable; this is the interval in which we monitor sleep_delay replaces the old sleep(300) when waiting for the master to recover. --- config.c | 7 +++++++ config.h | 4 +++- repmgr.conf.sample | 12 ++++++++++++ repmgr.h | 2 -- repmgrd.c | 14 ++++++++------ 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/config.c b/config.c index 16f5b23f..88bad689 100644 --- a/config.c +++ b/config.c @@ -52,6 +52,9 @@ parse_config(const char *config_file, t_configuration_options *options) options->reconnect_attempts = 6; options->reconnect_intvl = 10; + options->sleep_monitor = 2; + options->sleep_delay = 300; + /* * Since some commands don't require a config file at all, not * having one isn't necessarily a problem. @@ -122,6 +125,10 @@ parse_config(const char *config_file, t_configuration_options *options) strncpy (options->pgctl_options, value, MAXLEN); else if (strcmp(name, "logfile") == 0) strncpy(options->logfile, value, MAXLEN); + else if (strcmp(name, "sleep_monitor") == 0) + options->sleep_monitor = atoi(value); + else if (strcmp(name, "sleep_delay") == 0) + options->sleep_delay = atoi(value); else log_warning(_("%s/%s: Unknown name/value pair!\n"), name, value); } diff --git a/config.h b/config.h index 611672ed..2e7cb39e 100644 --- a/config.h +++ b/config.h @@ -43,9 +43,11 @@ typedef struct char pg_bindir[MAXLEN]; char pgctl_options[MAXLEN]; char logfile[MAXLEN]; + int sleep_monitor; + int sleep_delay; } t_configuration_options; -#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "", "" } +#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "", "", 0, 0 } void parse_config(const char *config_file, t_configuration_options *options); void parse_line(char *buff, char *name, char *value); diff --git a/repmgr.conf.sample b/repmgr.conf.sample index 8aa8d63b..1dc0e597 100644 --- a/repmgr.conf.sample +++ b/repmgr.conf.sample @@ -47,3 +47,15 @@ pg_bindir=/usr/bin/ # redirect stderr to a logfile # # logfile='/var/log/repmgr.log' + +# +# change monitoring interval; default is 2s +# +# sleep_monitor=2 + +# +# change wait time for master; before we bail out and exit when the +# master disappears, we wait 6 * sleep_delay seconds; by default this +# would be half an hour (since sleep_delay default value is 300) +# +# sleep_delay=300 diff --git a/repmgr.h b/repmgr.h index a2a0ac8e..8816697e 100644 --- a/repmgr.h +++ b/repmgr.h @@ -71,6 +71,4 @@ typedef struct #define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, "", "", 0 } -#define SLEEP_MONITOR 2 - #endif diff --git a/repmgrd.c b/repmgrd.c index 2322764d..8f2177ce 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -358,7 +358,7 @@ main(int argc, char **argv) /* Check that primary is still alive, and standbies are sending info */ /* - * Every SLEEP_MONITOR seconds, do master checks + * Every local_options.sleep_monitor seconds, do master checks * XXX * Check that standbies are sending info */ @@ -370,7 +370,7 @@ main(int argc, char **argv) CheckActiveStandbiesConnections(); CheckInactiveStandbies(); */ - sleep(SLEEP_MONITOR); + sleep(local_options.sleep_monitor); } else { @@ -424,7 +424,7 @@ main(int argc, char **argv) } /* - * Every SLEEP_MONITOR seconds, do checks + * Every local_options.sleep_monitor seconds, do checks */ if (myLocalMode == WITNESS_MODE) { @@ -441,7 +441,7 @@ main(int argc, char **argv) WitnessMonitor(); else if (myLocalMode == STANDBY_MODE) StandbyMonitor(); - sleep(SLEEP_MONITOR); + sleep(local_options.sleep_monitor); if (got_SIGHUP) { @@ -600,8 +600,10 @@ StandbyMonitor(void) else { log_err(_("We haven't found a new master, waiting before retry...\n")); - /* wait 5 minutes before retries, after 6 failures (30 minutes) we stop trying */ - sleep(300); + /* wait local_options.sleep_delay minutes before retries, + * after 6 failures (6 * local_options.sleep_monitor + * seconds) we stop trying */ + sleep(local_options.sleep_delay); } }