1.监控阶段
sentinel(哨兵1)----->向master(主)和slave(从)发起info,拿到全信息。
sentinel(哨兵2)----->向master(主)发起info,就知道已经存在的sentinel(哨兵1)的信息,并且连接slave(从)。
sentinel(哨兵2)----->向sentinel(哨兵1)发起subscribe(订阅)。
2.通知阶段
sentinel不断的向master和slave发起通知,收集信息。
3.故障转移阶段
通知阶段sentinel发送的通知没得到master的回应,就会把master标记为SRI_S_DOWN,并且把master的状态发给各个sentinel
其他sentinel听到master挂了,说我不信,我也去看看,并把结果共享给各个sentinel,当有一半的sentinel都认为master挂了的时候,就会把master标记为SRI_0_DOWN
这时就要把master给换掉了。然后哪个sentinel发起这个通知呢?sentinel之间会发起投票,每个sentinel都会向其他的sentinel发起通知,说我要参加竞选,然后的票过半的sentinel会当选.
投票方式: 自己最先接到哪个sentinel的竞选通知就会把票投给它。(a b都向c发通知说我要竞选,c先接到b的通知,c就投b一票)。如果一轮下来,谁的票数都没过半,那就再来一轮(竞选次数+1)
钦差大臣出来了,这下要思考这莫多slave谁当master呢?
剔除一下情况的slave:
1.不在线的
2.响应慢的
3.与原来的master断开的时间久的
4.优先原则
4.1优先级 4.2offset(偏移量) 4.3 runid(剔除大的)
选出新皇后,向新的master发送slaveof no one , 昭告天下,通知其他slave新皇master的IP端口。
感谢黑马程序员提供的视频和PPT。