diff --git a/src/sentinel.c b/src/sentinel.c index 4f2c6c0f..027817d1 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -183,6 +183,8 @@ typedef struct sentinelRedisInstance { mstime_t failover_state_change_time; mstime_t failover_start_time; /* Last failover attempt start time. */ mstime_t failover_timeout; /* Max time to refresh failover state. */ + mstime_t failover_delay_logged; /* For what failover_start_time value we + logged the failover delay. */ struct sentinelRedisInstance *promoted_slave; /* Promoted slave instance. */ /* Scripts executed to notify admin or reconfigure clients: when they * are set to NULL no script is executed. */ @@ -967,6 +969,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char * ri->failover_state_change_time = 0; ri->failover_start_time = 0; ri->failover_timeout = SENTINEL_DEFAULT_FAILOVER_TIMEOUT; + ri->failover_delay_logged = 0; ri->promoted_slave = NULL; ri->notification_script = NULL; ri->client_reconfig_script = NULL; @@ -3252,7 +3255,22 @@ int sentinelStartFailoverIfNeeded(sentinelRedisInstance *master) { /* Last failover attempt started too little time ago? */ if (mstime() - master->failover_start_time < - master->failover_timeout*2) return 0; + master->failover_timeout*2) + { + if (master->failover_delay_logged != master->failover_start_time) { + time_t clock = (master->failover_start_time + + master->failover_timeout*2) / 1000; + char ctimebuf[26]; + + ctime_r(&clock,ctimebuf); + ctimebuf[24] = '\0'; /* Remove newline. */ + master->failover_delay_logged = master->failover_start_time; + redisLog(REDIS_WARNING, + "Next failover delay: I will not start a failover before %s", + ctimebuf); + } + return 0; + } sentinelStartFailover(master); return 1;