Skip to content

Commit 908e10e

Browse files
committed
Bound the number of nodes in gossip section
Signed-off-by: Harkrishn Patro <[email protected]>
1 parent 981b8fe commit 908e10e

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/cluster_legacy.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4600,13 +4600,26 @@ void clusterSendPing(clusterLink *link, int type) {
46004600
* Since we have non-voting replicas that lower the probability of an entry
46014601
* to feature our node, we set the number of entries per packet as
46024602
* 10% of the total nodes we have. */
4603-
wanted = floor(dictSize(server.cluster->nodes) / 10);
4604-
if (wanted < 3) wanted = 3;
4605-
if (wanted > freshnodes) wanted = freshnodes;
4603+
int overall = server.cluster_ping_message_gossip_max_count;
4604+
if (!overall) {
4605+
overall = floor(dictSize(server.cluster->nodes) / 10);
4606+
if (overall < 3) overall = 3;
4607+
}
46064608

4607-
/* Include all the nodes in PFAIL state, so that failure reports are
4608-
* faster to propagate to go from PFAIL to FAIL state. */
4609+
/* Prioritize pfail nodes over other nodes.
4610+
* Healthy nodes can communicate through direct ping/pong if required and failed node
4611+
* information would be broadcasted. */
46094612
int pfail_wanted = server.cluster->stats_pfail_nodes;
4613+
if (pfail_wanted >= overall) {
4614+
pfail_wanted = overall - 1;
4615+
wanted = 1;
4616+
} else {
4617+
wanted = overall - pfail_wanted;
4618+
}
4619+
4620+
if (wanted > freshnodes) {
4621+
wanted = freshnodes;
4622+
}
46104623

46114624
/* Compute the maximum estlen to allocate our buffer. We'll fix the estlen
46124625
* later according to the number of gossip sections we really were able

src/config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,6 +3357,8 @@ standardConfig static_configs[] = {
33573357
createUIntConfig("socket-mark-id", NULL, IMMUTABLE_CONFIG, 0, UINT_MAX, server.socket_mark_id, 0, INTEGER_CONFIG, NULL, NULL),
33583358
createUIntConfig("max-new-connections-per-cycle", NULL, MODIFIABLE_CONFIG, 1, 1000, server.max_new_conns_per_cycle, 10, INTEGER_CONFIG, NULL, NULL),
33593359
createUIntConfig("max-new-tls-connections-per-cycle", NULL, MODIFIABLE_CONFIG, 1, 1000, server.max_new_tls_conns_per_cycle, 1, INTEGER_CONFIG, NULL, NULL),
3360+
createUIntConfig("cluster-ping-message-gossip-max-count", NULL, MODIFIABLE_CONFIG, 0, UINT_MAX, server.cluster_ping_message_gossip_max_count, 0, INTEGER_CONFIG, NULL, NULL),
3361+
33603362
#ifdef LOG_REQ_RES
33613363
createUIntConfig("client-default-resp", NULL, IMMUTABLE_CONFIG | HIDDEN_CONFIG, 2, 3, server.client_default_resp, 2, INTEGER_CONFIG, NULL, NULL),
33623364
#endif

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,7 @@ struct valkeyServer {
21822182
int cluster_port; /* Set the cluster port for a node. */
21832183
mstime_t cluster_node_timeout; /* Cluster node timeout. */
21842184
mstime_t cluster_ping_interval; /* A debug configuration for setting how often cluster nodes send ping messages. */
2185+
int cluster_ping_message_gossip_max_count; /* A configuration for setting how many peer node information to be gossiped in ping/pong messages. */
21852186
char *cluster_configfile; /* Cluster auto-generated config file name. */
21862187
struct clusterState *cluster; /* State of the cluster */
21872188
int cluster_migration_barrier; /* Cluster replicas migration barrier. */

valkey.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,12 @@ aof-timestamp-enabled no
20042004
# In order to setup your cluster make sure to read the documentation
20052005
# available at https://valkey.io web site.
20062006

2007+
# Cluster nodes communicate with each other via PING/PONG message type. Each message carries a gossip section i.e.
2008+
# information about peer nodes. This configuration caps the maximum number of gossip information to carry in each message.
2009+
#
2010+
# Default value is set to 0 which implies the maximum count to be gossiped is set to 10% of all node count.
2011+
# cluster-ping-message-gossip-max-count 0
2012+
20072013
########################## CLUSTER DOCKER/NAT support ########################
20082014

20092015
# In certain deployments, cluster node's address discovery fails, because

0 commit comments

Comments
 (0)