mirror of
https://github.com/fluencelabs/redis
synced 2025-04-02 15:51:05 +00:00
Sentinel: when leader in wait-start, sense another leader as race.
When we are in wait start, if another leader (or any other external entity) turns a slave into a master, abort the failover, and detect it as an observer. Note that the wait-start state is mainly there for this reason but the abort was yet not implemented. This adds a new sentinel event -failover-abort-race.
This commit is contained in:
parent
91c15ed1b5
commit
fd92b366b0
@ -1424,8 +1424,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
|
|||||||
} else if (ri->flags & SRI_PROMOTED) {
|
} else if (ri->flags & SRI_PROMOTED) {
|
||||||
/* If this is a promoted slave we can change state to the
|
/* If this is a promoted slave we can change state to the
|
||||||
* failover state machine. */
|
* failover state machine. */
|
||||||
if (ri->master &&
|
if ((ri->master->flags & SRI_FAILOVER_IN_PROGRESS) &&
|
||||||
(ri->master->flags & SRI_FAILOVER_IN_PROGRESS) &&
|
|
||||||
(ri->master->flags & SRI_I_AM_THE_LEADER) &&
|
(ri->master->flags & SRI_I_AM_THE_LEADER) &&
|
||||||
(ri->master->failover_state ==
|
(ri->master->failover_state ==
|
||||||
SENTINEL_FAILOVER_STATE_WAIT_PROMOTION))
|
SENTINEL_FAILOVER_STATE_WAIT_PROMOTION))
|
||||||
@ -1436,24 +1435,36 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
|
|||||||
sentinelEvent(REDIS_WARNING,"+failover-state-reconf-slaves",
|
sentinelEvent(REDIS_WARNING,"+failover-state-reconf-slaves",
|
||||||
ri->master,"%@");
|
ri->master,"%@");
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!(ri->master->flags & SRI_FAILOVER_IN_PROGRESS) ||
|
||||||
/* Otherwise we interpret this as the start of the failover. */
|
((ri->master->flags & SRI_FAILOVER_IN_PROGRESS) &&
|
||||||
if (ri->master &&
|
(ri->master->flags & SRI_I_AM_THE_LEADER) &&
|
||||||
(ri->master->flags & SRI_FAILOVER_IN_PROGRESS) == 0)
|
ri->master->failover_state ==
|
||||||
{
|
SENTINEL_FAILOVER_STATE_WAIT_START))
|
||||||
ri->master->flags |= SRI_FAILOVER_IN_PROGRESS;
|
{
|
||||||
sentinelEvent(REDIS_WARNING,"failover-detected",ri->master,"%@");
|
/* No failover in progress? Then it is the start of a failover
|
||||||
ri->master->failover_state = SENTINEL_FAILOVER_STATE_DETECT_END;
|
* and we are an observer.
|
||||||
ri->master->failover_state_change_time = mstime();
|
*
|
||||||
ri->master->promoted_slave = ri;
|
* We also do that if we are a leader doing a failover, in wait
|
||||||
ri->flags |= SRI_PROMOTED;
|
* start, but well, somebody else started before us. */
|
||||||
/* We are an observer, so we can only assume that the leader
|
|
||||||
* is reconfiguring the slave instances. For this reason we
|
if (ri->master->flags & SRI_FAILOVER_IN_PROGRESS) {
|
||||||
* set all the instances as RECONF_SENT waiting for progresses
|
sentinelEvent(REDIS_WARNING,"-failover-abort-race",
|
||||||
* on this side. */
|
ri->master, "%@");
|
||||||
sentinelAddFlagsToDictOfRedisInstances(ri->master->slaves,
|
sentinelAbortFailover(ri->master);
|
||||||
SRI_RECONF_SENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ri->master->flags |= SRI_FAILOVER_IN_PROGRESS;
|
||||||
|
sentinelEvent(REDIS_WARNING,"+failover-detected",ri->master,"%@");
|
||||||
|
ri->master->failover_state = SENTINEL_FAILOVER_STATE_DETECT_END;
|
||||||
|
ri->master->failover_state_change_time = mstime();
|
||||||
|
ri->master->promoted_slave = ri;
|
||||||
|
ri->flags |= SRI_PROMOTED;
|
||||||
|
/* We are an observer, so we can only assume that the leader
|
||||||
|
* is reconfiguring the slave instances. For this reason we
|
||||||
|
* set all the instances as RECONF_SENT waiting for progresses
|
||||||
|
* on this side. */
|
||||||
|
sentinelAddFlagsToDictOfRedisInstances(ri->master->slaves,
|
||||||
|
SRI_RECONF_SENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user