关于PING消息 用的集群节点个数的十分之一作为wanted值如课代表所说,但是在我阅读源码的时候发现,PING消息是先把wanted数量的实例放到消息体,然后再把所有当前nodes认为是PFAIL的实例放到消息体末尾,也就是说,新版的redis实例加速了 PFAIL->FAIL的判断,跟十分之一的关系已经不大了。
PS: 当时看这段代码的时候非常疑惑,看源码的注释也很疑惑...直到翻阅github上面的提交记录
https://github.com/redis/redis/commit/1e659a04cf19e4349c8dbba931d1606336970b8c#diff-55c2de0fa49d05f6ed8f0c13cacedc85fba5d5739c8360567743f9f740df3179
/* If there are PFAIL nodes, add them at the end. */
if (pfail_wanted) {
dictIterator *di;
dictEntry *de;
di = dictGetSafeIterator(server.cluster->nodes);
while((de = dictNext(di)) != NULL && pfail_wanted > 0) {
clusterNode *node = dictGetVal(de);
if (node->flags & CLUSTER_NODE_HANDSHAKE) continue;
if (node->flags & CLUSTER_NODE_NOADDR) continue;
if (!(node->flags & CLUSTER_NODE_PFAIL)) continue;
clusterSetGossipEntry(hdr,gossipcount,node);
freshnodes--;
gossipcount++;
/* We take the count of the slots we allocated, since the
* PFAIL stats may not match perfectly with the current number
* of PFAIL nodes. */
pfail_wanted--;
}
dictReleaseIterator(di);
}