MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / sentinelStartFailoverIfNeeded

Function sentinelStartFailoverIfNeeded

src/sentinel.cpp:4614–4642  ·  view source on GitHub ↗

This function checks if there are the conditions to start the failover, * that is: * * 1) Master must be in ODOWN condition. * 2) No failover already in progress. * 3) No failover already attempted recently. * * We still don't know if we'll win the election so it is possible that we * start the failover but that we'll not be able to act. * * Return non-zero if a failover was started. */

Source from the content-addressed store, hash-verified

4612 *
4613 * Return non-zero if a failover was started. */
4614int sentinelStartFailoverIfNeeded(sentinelRedisInstance *master) {
4615 /* We can't failover if the master is not in O_DOWN state. */
4616 if (!(master->flags & SRI_O_DOWN)) return 0;
4617
4618 /* Failover already in progress? */
4619 if (master->flags & SRI_FAILOVER_IN_PROGRESS) return 0;
4620
4621 /* Last failover attempt started too little time ago? */
4622 if (mstime() - master->failover_start_time <
4623 master->failover_timeout*2)
4624 {
4625 if (master->failover_delay_logged != master->failover_start_time) {
4626 time_t clock = (master->failover_start_time +
4627 master->failover_timeout*2) / 1000;
4628 char ctimebuf[26];
4629
4630 ctime_r(&clock,ctimebuf);
4631 ctimebuf[24] = '\0'; /* Remove newline. */
4632 master->failover_delay_logged = master->failover_start_time;
4633 serverLog(LL_WARNING,
4634 "Next failover delay: I will not start a failover before %s",
4635 ctimebuf);
4636 }
4637 return 0;
4638 }
4639
4640 sentinelStartFailover(master);
4641 return 1;
4642}
4643
4644/* Select a suitable slave to promote. The current algorithm only uses
4645 * the following parameters:

Callers 1

Calls 3

serverLogFunction · 0.85
sentinelStartFailoverFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected