---------------- Failover state machine implementation ------------------- */
| 4747 | |
| 4748 | /* ---------------- Failover state machine implementation ------------------- */ |
| 4749 | void sentinelFailoverWaitStart(sentinelRedisInstance *ri) { |
| 4750 | char *leader; |
| 4751 | int isleader; |
| 4752 | |
| 4753 | /* Check if we are the leader for the failover epoch. */ |
| 4754 | leader = sentinelGetLeader(ri, ri->failover_epoch); |
| 4755 | isleader = leader && strcasecmp(leader,sentinel.myid) == 0; |
| 4756 | sdsfree(leader); |
| 4757 | |
| 4758 | /* If I'm not the leader, and it is not a forced failover via |
| 4759 | * SENTINEL FAILOVER, then I can't continue with the failover. */ |
| 4760 | if (!isleader && !(ri->flags & SRI_FORCE_FAILOVER)) { |
| 4761 | int election_timeout = SENTINEL_ELECTION_TIMEOUT; |
| 4762 | |
| 4763 | /* The election timeout is the MIN between SENTINEL_ELECTION_TIMEOUT |
| 4764 | * and the configured failover timeout. */ |
| 4765 | if (election_timeout > ri->failover_timeout) |
| 4766 | election_timeout = ri->failover_timeout; |
| 4767 | /* Abort the failover if I'm not the leader after some time. */ |
| 4768 | if (mstime() - ri->failover_start_time > election_timeout) { |
| 4769 | sentinelEvent(LL_WARNING,"-failover-abort-not-elected",ri,"%@"); |
| 4770 | sentinelAbortFailover(ri); |
| 4771 | } |
| 4772 | return; |
| 4773 | } |
| 4774 | sentinelEvent(LL_WARNING,"+elected-leader",ri,"%@"); |
| 4775 | if (sentinel.simfailure_flags & SENTINEL_SIMFAILURE_CRASH_AFTER_ELECTION) |
| 4776 | sentinelSimFailureCrash(); |
| 4777 | ri->failover_state = SENTINEL_FAILOVER_STATE_SELECT_SLAVE; |
| 4778 | ri->failover_state_change_time = mstime(); |
| 4779 | sentinelEvent(LL_WARNING,"+failover-state-select-slave",ri,"%@"); |
| 4780 | } |
| 4781 | |
| 4782 | void sentinelFailoverSelectSlave(sentinelRedisInstance *ri) { |
| 4783 | serverAssert(GlobalLocksAcquired()); |
no test coverage detected