| 4837 | } |
| 4838 | |
| 4839 | void sentinelFailoverDetectEnd(sentinelRedisInstance *master) { |
| 4840 | int not_reconfigured = 0, timeout = 0; |
| 4841 | dictIterator *di; |
| 4842 | dictEntry *de; |
| 4843 | mstime_t elapsed = mstime() - master->failover_state_change_time; |
| 4844 | |
| 4845 | /* We can't consider failover finished if the promoted slave is |
| 4846 | * not reachable. */ |
| 4847 | if (master->promoted_slave == NULL || |
| 4848 | master->promoted_slave->flags & SRI_S_DOWN) return; |
| 4849 | |
| 4850 | /* The failover terminates once all the reachable slaves are properly |
| 4851 | * configured. */ |
| 4852 | di = dictGetIterator(master->slaves); |
| 4853 | while((de = dictNext(di)) != NULL) { |
| 4854 | sentinelRedisInstance *slave = (sentinelRedisInstance*)dictGetVal(de); |
| 4855 | |
| 4856 | if (slave->flags & (SRI_PROMOTED|SRI_RECONF_DONE)) continue; |
| 4857 | if (slave->flags & SRI_S_DOWN) continue; |
| 4858 | not_reconfigured++; |
| 4859 | } |
| 4860 | dictReleaseIterator(di); |
| 4861 | |
| 4862 | /* Force end of failover on timeout. */ |
| 4863 | if (elapsed > master->failover_timeout) { |
| 4864 | not_reconfigured = 0; |
| 4865 | timeout = 1; |
| 4866 | sentinelEvent(LL_WARNING,"+failover-end-for-timeout",master,"%@"); |
| 4867 | } |
| 4868 | |
| 4869 | if (not_reconfigured == 0) { |
| 4870 | sentinelEvent(LL_WARNING,"+failover-end",master,"%@"); |
| 4871 | master->failover_state = SENTINEL_FAILOVER_STATE_UPDATE_CONFIG; |
| 4872 | master->failover_state_change_time = mstime(); |
| 4873 | } |
| 4874 | |
| 4875 | /* If I'm the leader it is a good idea to send a best effort SLAVEOF |
| 4876 | * command to all the slaves still not reconfigured to replicate with |
| 4877 | * the new master. */ |
| 4878 | if (timeout) { |
| 4879 | dictIterator *di; |
| 4880 | dictEntry *de; |
| 4881 | |
| 4882 | di = dictGetIterator(master->slaves); |
| 4883 | while((de = dictNext(di)) != NULL) { |
| 4884 | sentinelRedisInstance *slave = (sentinelRedisInstance*)dictGetVal(de); |
| 4885 | int retval; |
| 4886 | |
| 4887 | if (slave->flags & (SRI_PROMOTED|SRI_RECONF_DONE|SRI_RECONF_SENT)) continue; |
| 4888 | if (slave->link->disconnected) continue; |
| 4889 | |
| 4890 | retval = sentinelSendSlaveOf(slave,master->promoted_slave->addr); |
| 4891 | if (retval == C_OK) { |
| 4892 | sentinelEvent(LL_NOTICE,"+slave-reconf-sent-be",slave,"%@"); |
| 4893 | slave->flags |= SRI_RECONF_SENT; |
| 4894 | } |
| 4895 | } |
| 4896 | dictReleaseIterator(di); |
no test coverage detected