Redis cluster gossip

目录

一、通信节点选择

1.每0.1秒,如果发现有其他节点连不上,则尝试重连

2.每1秒,从5个随机节点中,选出一个其中最久没有通信的节点,进行ping

3.每0.1秒,如果发现有超过cluster-node-time/2没有通信成功的节点,则向这个节点发送ping  

二、gossip ping    所发送的信息

1.节点自身的信息

2.附带1/10的其他节点信息,如果1/10少于3,那么至少附带3个其他节点的信息


一、通信节点选择

通过clusterCron()  /* This is executed 10 times every second */

1.每0.1秒,如果发现有其他节点连不上,则尝试重连

/* Check if we have disconnected nodes and re-establish the connection. */
    di = dictGetSafeIterator(server.cluster->nodes);
    while((de = dictNext(di)) != NULL) {
        clusterNode *node = dictGetVal(de);
        ...
            link = createClusterLink(node);
            link->fd = fd;
            node->link = link;
            aeCreateFileEvent(server.el,link->fd,AE_READABLE,
                    clusterReadHandler,link);
            /* Queue a PING in the new connection ASAP: this is crucial
             * to avoid false positives in failure detection.
             *
             * If the node is flagged as MEET, we send a MEET message instead
             * of a PING one, to force the receiver to add us in its node
             * table. */
            old_ping_sent = node->ping_sent;
            clusterSendPing(link, node->flags & CLUSTER_NODE_MEET ?
                    CLUSTERMSG_TYPE_MEET : CLUSTERMSG_TYPE_PING);
            if (old_ping_sent) {
                /* If there was an active ping before the link was
                 * disconnected, we want to restore the ping time, otherwise
                 * replaced by the clusterSendPing() call. */
                node->ping_sent = old_ping_sent;
            }
            /* We can clear the flag after the first packet is sent.
             * If we'll never receive a PONG, we'll never send new packets
             * to this node. Instead after the PONG is received and we
             * are no longer in meet/handshake status, we want to send
             * normal PING packets. */
            node->flags &= ~CLUSTER_NODE_MEET;
            serverLog(LL_DEBUG,"Connecting with Node %.40s at %s:%d",
                    node->name, node->ip, node->port+CLUSTER_PORT_INCR);
        }
    }
    dictReleaseIterator(di);

例子:

可以看到每个0.1s都会去ping连不上的节点
76879:M 09 Jun 17:00:49.276 . Connecting with Node 64cdc10096644b5bc3624f41ade916983806c47c at 10.200.35.93:12222
76879:M 09 Jun 17:00:49.276 . I/O error reading from node link: Connection refused
76879:M 09 Jun 17:00:49.376 . Connecting with Node 64cdc10096644b5bc3624f41ade916983806c47c at 10.200.35.93:12222
76879:M 09 Jun 17:00:49.376 . I/O error reading from node link: Connection refused
76879:M 09 Jun 17:00:49.477 . Connecting with Node 64cdc10096644b5bc3624f41ade916983806c47c at 10.200.35.93:12222
76879:M 09 Jun 17:00:49.47
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值