diff --git a/src/sentinel.c b/src/sentinel.c index 3d7fbf55..bb4cfbfd 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -2733,12 +2733,9 @@ char *sentinelVoteLeader(sentinelRedisInstance *master, uint64_t req_epoch, char master->leader, (unsigned long long) master->leader_epoch); /* If we did not voted for ourselves, set the master failover start * time to now, in order to force a delay before we can start a - * failover for the same master. - * - * The random addition is useful to desynchronize a bit the slaves - * and reduce the chance that no slave gets majority. */ + * failover for the same master. */ if (strcasecmp(master->leader,server.runid)) - master->failover_start_time = mstime() + rand() % 2000; + master->failover_start_time = mstime(); } *leader_epoch = master->leader_epoch; @@ -3389,5 +3386,13 @@ void sentinelTimer(void) { sentinelRunPendingScripts(); sentinelCollectTerminatedScripts(); sentinelKillTimedoutScripts(); + + /* We continuously change the frequency of the Redis "timer interrupt" + * in order to desynchronize every Sentinel from every other. + * This non-determinism avoids that Sentinels started at the same time + * exactly continue to stay synchronized asking to be voted at the + * same time again and again (resulting in nobody likely winning the + * election because of split brain voting). */ + server.hz = REDIS_DEFAULT_HZ + rand() % REDIS_DEFAULT_HZ; }