Skip to content

Commit 69b4f00

Browse files
committed
More correct wanted / maxiterations values in clusterSendPing().
1 parent 6b1c633 commit 69b4f00

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/cluster.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <sys/socket.h>
4141
#include <sys/stat.h>
4242
#include <sys/file.h>
43+
#include <math.h>
4344

4445
/* A global reference to myself is handy to make code more clear.
4546
* Myself always points to server.cluster->myself, that is, the clusterNode
@@ -2136,8 +2137,9 @@ void clusterSendPing(clusterLink *link, int type) {
21362137
* Since we have non-voting slaves that lower the probability of an entry
21372138
* to feature our node, we set the number of entires per packet as
21382139
* 10% of the total nodes we have. */
2139-
wanted = freshnodes/10;
2140+
wanted = floor(dictSize(server.cluster->nodes)/10);
21402141
if (wanted < 3) wanted = 3;
2142+
if (wanted > freshnodes) wanted = freshnodes;
21412143

21422144
/* Compute the maxium totlen to allocate our buffer. We'll fix the totlen
21432145
* later according to the number of gossip sections we really were able
@@ -2156,7 +2158,7 @@ void clusterSendPing(clusterLink *link, int type) {
21562158
clusterBuildMessageHdr(hdr,type);
21572159

21582160
/* Populate the gossip fields */
2159-
int maxiterations = wanted+10;
2161+
int maxiterations = wanted*2;
21602162
while(freshnodes > 0 && gossipcount < wanted && maxiterations--) {
21612163
dictEntry *de = dictGetRandomKey(server.cluster->nodes);
21622164
clusterNode *this = dictGetVal(de);
@@ -2199,6 +2201,8 @@ void clusterSendPing(clusterLink *link, int type) {
21992201
gossip->notused2 = 0;
22002202
gossipcount++;
22012203
}
2204+
redisLog(REDIS_VERBOSE,"WANTED: %d, USED_ITER: %d, GOSSIPCOUNT: %d",
2205+
wanted, wanted*2-maxiterations, gossipcount);
22022206

22032207
/* Ready to send... fix the totlen fiend and queue the message in the
22042208
* output buffer. */

0 commit comments

Comments
 (0)