Skip to content

Commit 4579f74

Browse files
committed
更新 sentinel.c 的注释
1 parent 9762bdc commit 4579f74

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/sentinel.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ void sentinelEvent(int level, char *type, sentinelRedisInstance *ri,
892892
* +monitor event for every configured master. The same events are also
893893
* generated when a master to monitor is added at runtime via the
894894
* SENTINEL MONITOR command. */
895+
// 在 Sentinel 启动时执行,用于创建并生成 +monitor 事件
895896
void sentinelGenerateInitialMonitorEvents(void) {
896897
dictIterator *di;
897898
dictEntry *de;
@@ -907,6 +908,7 @@ void sentinelGenerateInitialMonitorEvents(void) {
907908
/* ============================ script execution ============================ */
908909

909910
/* Release a script job structure and all the associated data. */
911+
// 释放一个脚本任务结构,以及该任务的相关数据。
910912
void sentinelReleaseScriptJob(sentinelScriptJob *sj) {
911913
int j = 0;
912914

@@ -2277,6 +2279,7 @@ void sentinelSendAuthIfNeeded(sentinelRedisInstance *ri, redisAsyncContext *c) {
22772279
*
22782280
* This makes it possible to list all the sentinel instances connected
22792281
* to a Redis servewr with CLIENT LIST, grepping for a specific name format. */
2282+
// 使用 CLIENT SETNAME 命令,为给定的客户端设置名字。
22802283
void sentinelSetClientName(sentinelRedisInstance *ri, redisAsyncContext *c, char *type) {
22812284
char name[64];
22822285

@@ -2361,6 +2364,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
23612364
// 发送 AUTH 命令,验证身份
23622365
sentinelSendAuthIfNeeded(ri,ri->pc);
23632366

2367+
// 为客户但设置名字 "pubsub"
23642368
sentinelSetClientName(ri,ri->pc,"pubsub");
23652369

23662370
/* Now we subscribe to the Sentinels "Hello" channel. */
@@ -2579,6 +2583,7 @@ void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) {
25792583

25802584
/* None of the following conditions are processed when in tilt mode, so
25812585
* return asap. */
2586+
// 如果 Sentinel 正处于 TILT 模式,那么它不能执行以下的语句。
25822587
if (sentinel.tilt) return;
25832588

25842589
/* Handle master -> slave role switch. */
@@ -2811,8 +2816,14 @@ void sentinelPublishReplyCallback(redisAsyncContext *c, void *reply, void *privd
28112816
/* Process an hello message received via Pub/Sub in master or slave instance,
28122817
* or sent directly to this sentinel via the (fake) PUBLISH command of Sentinel.
28132818
*
2819+
* 处理从 Pub/Sub 连接得来的,来自主服务器或者从服务器的 hello 消息。
2820+
* hello 消息也可能是另一个 Sentinel 通过 PUBLISH 命令发送过来的。
2821+
*
28142822
* If the master name specified in the message is not known, the message is
2815-
* discareded. */
2823+
* discareded.
2824+
*
2825+
* 如果消息里面指定的主服务器的名字是未知的,那么这条消息将被丢弃。
2826+
*/
28162827
void sentinelProcessHelloMessage(char *hello, int hello_len) {
28172828
/* Format is composed of 8 tokens:
28182829
* 0=ip,1=port,2=runid,3=current_epoch,4=master_name,
@@ -2824,10 +2835,12 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) {
28242835

28252836
if (numtokens == 8) {
28262837
/* Obtain a reference to the master this hello message is about */
2838+
// 获取主服务器的名字,并丢弃和未知主服务器相关的消息。
28272839
master = sentinelGetMasterByName(token[4]);
28282840
if (!master) goto cleanup; /* Unknown master, skip the message. */
28292841

28302842
/* First, try to see if we already have this sentinel. */
2843+
// 看这个 Sentinel 是否已经认识发送消息的 Sentinel
28312844
port = atoi(token[1]);
28322845
master_port = atoi(token[6]);
28332846
si = getSentinelRedisInstanceByAddrAndRunID(
@@ -2836,6 +2849,10 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) {
28362849
master_config_epoch = strtoull(token[7],NULL,10);
28372850

28382851
if (!si) {
2852+
2853+
// 这个 Sentinel 不认识发送消息的 Sentinel
2854+
// 将对方加入到 Sentinel 列表中
2855+
28392856
/* If not, remove all the sentinels that have the same runid
28402857
* OR the same ip/port, because it's either a restart or a
28412858
* network topology change. */
@@ -2861,6 +2878,7 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) {
28612878
}
28622879

28632880
/* Update local current_epoch if received current_epoch is greater.*/
2881+
// 如果消息中记录的纪元比 Sentinel 当前的纪元要高,那么更新纪元
28642882
if (current_epoch > sentinel.current_epoch) {
28652883
sentinel.current_epoch = current_epoch;
28662884
sentinelFlushConfig();
@@ -2869,6 +2887,7 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) {
28692887
}
28702888

28712889
/* Update master info if received configuration is newer. */
2890+
// 如果消息中记录的配置信息更新,那么对主服务器的信息进行更新
28722891
if (master->config_epoch < master_config_epoch) {
28732892
master->config_epoch = master_config_epoch;
28742893
if (master_port != master->addr->port ||
@@ -2893,6 +2912,7 @@ void sentinelProcessHelloMessage(char *hello, int hello_len) {
28932912
}
28942913

28952914
/* Update the state of the Sentinel. */
2915+
// 更新我方 Sentinel 记录的对方 Sentinel 的信息。
28962916
if (si) si->last_hello_time = mstime();
28972917
}
28982918

@@ -3003,6 +3023,7 @@ int sentinelSendHello(sentinelRedisInstance *ri) {
30033023
*
30043024
* On error zero is returned, and we can't consider the PING command
30053025
* queued in the connection. */
3026+
// 向指定的 Sentinel 发送 PING 命令。
30063027
int sentinelSendPing(sentinelRedisInstance *ri) {
30073028
int retval = redisAsyncCommand(ri->cc,
30083029
sentinelPingReplyCallback, NULL, "PING");

0 commit comments

Comments
 (0)