Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for cluster fully online in cluster_config_consistent #272

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,10 @@ int clusterNodeFailureReportsCount(clusterNode *node) {
return listLength(node->fail_reports);
}

static int clusterNodeNameComparator(const void *node1, const void *node2) {
return strncasecmp((*(clusterNode **)node1)->name, (*(clusterNode **)node2)->name, CLUSTER_NAMELEN);
}

int clusterNodeRemoveSlave(clusterNode *master, clusterNode *slave) {
int j;

Expand Down Expand Up @@ -1479,6 +1483,7 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) {
sizeof(clusterNode*)*(master->numslaves+1));
master->slaves[master->numslaves] = slave;
master->numslaves++;
qsort(master->slaves, master->numslaves, sizeof(clusterNode *), clusterNodeNameComparator);
master->flags |= CLUSTER_NODE_MIGRATE_TO;
return C_OK;
}
Expand Down
15 changes: 14 additions & 1 deletion tests/cluster/cluster.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,21 @@ proc cluster_write_test {id} {
}

# Check if cluster configuration is consistent.
# All the nodes in the cluster should show same slots configuration and have health
# state "online" to be considered as consistent.
proc cluster_config_consistent {} {
for {set j 0} {$j < $::cluster_master_nodes + $::cluster_replica_nodes} {incr j} {
# Check if all the nodes are online
set shards_cfg [R $j CLUSTER SHARDS]
foreach shard_cfg $shards_cfg {
set nodes [dict get $shard_cfg nodes]
foreach node $nodes {
if {[dict get $node health] ne "online"} {
return 0
}
}
}

if {$j == 0} {
set base_cfg [R $j cluster slots]
} else {
Expand All @@ -199,7 +212,7 @@ proc cluster_config_consistent {} {

# Wait for cluster configuration to propagate and be consistent across nodes.
proc wait_for_cluster_propagation {} {
wait_for_condition 50 100 {
wait_for_condition 1000 50 {
enjoy-binbin marked this conversation as resolved.
Show resolved Hide resolved
[cluster_config_consistent] eq 1
} else {
fail "cluster config did not reach a consistent state"
Expand Down
15 changes: 14 additions & 1 deletion tests/support/cluster_util.tcl
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# Cluster helper functions

# Check if cluster configuration is consistent.
# All the nodes in the cluster should show same slots configuration and have health
# state "online" to be considered as consistent.
proc cluster_config_consistent {} {
for {set j 0} {$j < [llength $::servers]} {incr j} {
# Check if all the nodes are online
set shards_cfg [R $j CLUSTER SHARDS]
foreach shard_cfg $shards_cfg {
set nodes [dict get $shard_cfg nodes]
foreach node $nodes {
if {[dict get $node health] ne "online"} {
return 0
}
}
}

if {$j == 0} {
set base_cfg [R $j cluster slots]
} else {
Expand All @@ -27,7 +40,7 @@ proc cluster_size_consistent {cluster_size} {

# Wait for cluster configuration to propagate and be consistent across nodes.
proc wait_for_cluster_propagation {} {
wait_for_condition 50 100 {
wait_for_condition 1000 50 {
[cluster_config_consistent] eq 1
} else {
fail "cluster config did not reach a consistent state"
Expand Down
Loading