MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterSendPing

Function clusterSendPing

app/redis-6.2.6/src/cluster.c:2536–2662  ·  view source on GitHub ↗

Send a PING or PONG packet to the specified node, making sure to add enough * gossip information. */

Source from the content-addressed store, hash-verified

2534/* Send a PING or PONG packet to the specified node, making sure to add enough
2535 * gossip information. */
2536void clusterSendPing(clusterLink *link, int type) {
2537 unsigned char *buf;
2538 clusterMsg *hdr;
2539 int gossipcount = 0; /* Number of gossip sections added so far. */
2540 int wanted; /* Number of gossip sections we want to append if possible. */
2541 int totlen; /* Total packet length. */
2542 /* freshnodes is the max number of nodes we can hope to append at all:
2543 * nodes available minus two (ourself and the node we are sending the
2544 * message to). However practically there may be less valid nodes since
2545 * nodes in handshake state, disconnected, are not considered. */
2546 int freshnodes = dictSize(server.cluster->nodes)-2;
2547
2548 /* How many gossip sections we want to add? 1/10 of the number of nodes
2549 * and anyway at least 3. Why 1/10?
2550 *
2551 * If we have N masters, with N/10 entries, and we consider that in
2552 * node_timeout we exchange with each other node at least 4 packets
2553 * (we ping in the worst case in node_timeout/2 time, and we also
2554 * receive two pings from the host), we have a total of 8 packets
2555 * in the node_timeout*2 failure reports validity time. So we have
2556 * that, for a single PFAIL node, we can expect to receive the following
2557 * number of failure reports (in the specified window of time):
2558 *
2559 * PROB * GOSSIP_ENTRIES_PER_PACKET * TOTAL_PACKETS:
2560 *
2561 * PROB = probability of being featured in a single gossip entry,
2562 * which is 1 / NUM_OF_NODES.
2563 * ENTRIES = 10.
2564 * TOTAL_PACKETS = 2 * 4 * NUM_OF_MASTERS.
2565 *
2566 * If we assume we have just masters (so num of nodes and num of masters
2567 * is the same), with 1/10 we always get over the majority, and specifically
2568 * 80% of the number of nodes, to account for many masters failing at the
2569 * same time.
2570 *
2571 * Since we have non-voting slaves that lower the probability of an entry
2572 * to feature our node, we set the number of entries per packet as
2573 * 10% of the total nodes we have. */
2574 wanted = floor(dictSize(server.cluster->nodes)/10);
2575 if (wanted < 3) wanted = 3;
2576 if (wanted > freshnodes) wanted = freshnodes;
2577
2578 /* Include all the nodes in PFAIL state, so that failure reports are
2579 * faster to propagate to go from PFAIL to FAIL state. */
2580 int pfail_wanted = server.cluster->stats_pfail_nodes;
2581
2582 /* Compute the maximum totlen to allocate our buffer. We'll fix the totlen
2583 * later according to the number of gossip sections we really were able
2584 * to put inside the packet. */
2585 totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
2586 totlen += (sizeof(clusterMsgDataGossip)*(wanted+pfail_wanted));
2587 /* Note: clusterBuildMessageHdr() expects the buffer to be always at least
2588 * sizeof(clusterMsg) or more. */
2589 if (totlen < (int)sizeof(clusterMsg)) totlen = sizeof(clusterMsg);
2590 buf = zcalloc(totlen);
2591 hdr = (clusterMsg*) buf;
2592
2593 /* Populate the header. */

Callers 4

clusterProcessPacketFunction · 0.85
clusterBroadcastPongFunction · 0.85
clusterCronFunction · 0.85

Calls 11

clusterBuildMessageHdrFunction · 0.85
dictGetRandomKeyFunction · 0.85
clusterSetGossipEntryFunction · 0.85
dictGetSafeIteratorFunction · 0.85
clusterSendMessageFunction · 0.85
zcallocFunction · 0.70
mstimeFunction · 0.70
dictNextFunction · 0.70
dictReleaseIteratorFunction · 0.70
zfreeFunction · 0.70

Tested by

no test coverage detected