40
40
#include <sys/socket.h>
41
41
#include <sys/stat.h>
42
42
#include <sys/file.h>
43
+ #include <math.h>
43
44
44
45
/* A global reference to myself is handy to make code more clear.
45
46
* Myself always points to server.cluster->myself, that is, the clusterNode
@@ -2136,8 +2137,9 @@ void clusterSendPing(clusterLink *link, int type) {
2136
2137
* Since we have non-voting slaves that lower the probability of an entry
2137
2138
* to feature our node, we set the number of entires per packet as
2138
2139
* 10% of the total nodes we have. */
2139
- wanted = freshnodes /10 ;
2140
+ wanted = floor ( dictSize ( server . cluster -> nodes ) /10 ) ;
2140
2141
if (wanted < 3 ) wanted = 3 ;
2142
+ if (wanted > freshnodes ) wanted = freshnodes ;
2141
2143
2142
2144
/* Compute the maxium totlen to allocate our buffer. We'll fix the totlen
2143
2145
* later according to the number of gossip sections we really were able
@@ -2156,7 +2158,7 @@ void clusterSendPing(clusterLink *link, int type) {
2156
2158
clusterBuildMessageHdr (hdr ,type );
2157
2159
2158
2160
/* Populate the gossip fields */
2159
- int maxiterations = wanted + 10 ;
2161
+ int maxiterations = wanted * 2 ;
2160
2162
while (freshnodes > 0 && gossipcount < wanted && maxiterations -- ) {
2161
2163
dictEntry * de = dictGetRandomKey (server .cluster -> nodes );
2162
2164
clusterNode * this = dictGetVal (de );
@@ -2199,6 +2201,8 @@ void clusterSendPing(clusterLink *link, int type) {
2199
2201
gossip -> notused2 = 0 ;
2200
2202
gossipcount ++ ;
2201
2203
}
2204
+ redisLog (REDIS_VERBOSE ,"WANTED: %d, USED_ITER: %d, GOSSIPCOUNT: %d" ,
2205
+ wanted , wanted * 2 - maxiterations , gossipcount );
2202
2206
2203
2207
/* Ready to send... fix the totlen fiend and queue the message in the
2204
2208
* output buffer. */
0 commit comments