Sentinel采用Gossip的思想来做信息的同步,11年写了一篇文章
Gossip算法学习 ,有兴趣的同学可以看下
其核心思想如下:
1. 去中心化,各个节点之间完全对等,不需要任何的中心节点。
2. 每个参与者都有关于一个自己信息的表, 同时每一个参与者要知道所有其他参与者的信息, 即要维护一个全局的表
Sentinel本地维护了2个字典,包括其监控的各个master节点的信息,以及对应master所关联的sentinel和slave的信息
通过在Redis instance节点上运行“./redis-cli -p 6383 monitor” 可以看到sentinle和该instance的交互,如下:
1397099907.404663 [0 192.168.213.245:64000] "INFO"
1397099908.132342 [0 192.168.213.245:64000] "PING"
1397099908.482543 [0 192.168.213.245:64000] "PUBLISH" "__sentinel__:hello" "192.168.213.245,26381,ccae95dadb891b0f237c5271bd12c116eb6321da,2,node_3,10.1.110.77,6383,0"
其核心思想如下:
1. 去中心化,各个节点之间完全对等,不需要任何的中心节点。
2. 每个参与者都有关于一个自己信息的表, 同时每一个参与者要知道所有其他参与者的信息, 即要维护一个全局的表
Sentinel本地维护了2个字典,包括其监控的各个master节点的信息,以及对应master所关联的sentinel和slave的信息
struct sentinelState {
uint64_t current_epoch; //当前处在第几个世纪(每次fail over,current_epoch+1)
dict *masters; /* master实例字典(一个sentinle可监控多个master)*/
int tilt; /*是否在TITL模式中,后面详细介绍TITL模式*/
int running_scripts; /* 当前正在执行的脚本 */
mstime_t tilt_start_time; /* TITL模式开始的时间 */
mstime_t previous_time; /* 上次执行sentinel周期性执行任务的时间,用以判断是否进入TITL模式*/
list *scripts_queue; /* 待执行脚本队列 */
} sentinel;
typedef struct sentinelRedisInstance {
......
/* Master specific. */
dict *sentinels; /* 监控该master实例的其他sentinel结点字典*/
dict *slaves; /* 该master实例说包含的slave结点字典 */
......
} sentinelRedisInstance;
通过在Redis instance节点上运行“./redis-cli -p 6383 monitor” 可以看到sentinle和该instance的交互,如下:
1397099907.404663 [0 192.168.213.245:64000] "INFO"
1397099908.132342 [0 192.168.213.245:64000] "PING"
1397099908.482543 [0 192.168.213.245:64000] "PUBLISH" "__sentinel__:hello" "192.168.213.245,26381,ccae95dadb891b0f237c5271bd12c116eb6321da,2,node_3,10.1.110.77,6383,0"
信息包括:
INFO:获取该instance相关的信息
PING:获取该instance存活状态
PUBLISH:向“__sentinel__:hello”频道发布其本身信息,其它sentinel订阅“__sentinel__:hello”频道以获取这些信息
在sentinle获取到上述信息后,会更新本地字典,并会向探测到的其它sentinle发送PING命令以获取其存活状态。
通过上述获取信息方式,每个sentinel维护一张其能够连接到的整个redis集群的状态信息表
各个sentinel完全对等,新的sentinel可以方便的加入