summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/redis-cli.c20
-rw-r--r--tests/cluster/tests/12-replica-migration-2.tcl18
-rw-r--r--tests/cluster/tests/12.1-replica-migration-3.tcl14
-rw-r--r--tests/cluster/tests/includes/utils.tcl11
-rw-r--r--tests/instances.tcl7
5 files changed, 53 insertions, 17 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 14d17f8f5..31a2973c7 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -4069,13 +4069,17 @@ static int clusterManagerMoveSlot(clusterManagerNode *source,
slot, "node",
target->name);
success = (r != NULL);
- if (!success) return 0;
+ if (!success) {
+ if (err) *err = zstrdup("CLUSTER SETSLOT failed to run");
+ return 0;
+ }
if (r->type == REDIS_REPLY_ERROR) {
success = 0;
if (err != NULL) {
*err = zmalloc((r->len + 1) * sizeof(char));
strcpy(*err, r->str);
- CLUSTER_MANAGER_PRINT_REPLY_ERROR(n, *err);
+ } else {
+ CLUSTER_MANAGER_PRINT_REPLY_ERROR(n, r->str);
}
}
freeReplyObject(r);
@@ -6402,7 +6406,7 @@ static int clusterManagerCommandReshard(int argc, char **argv) {
opts, &err);
if (!result) {
if (err != NULL) {
- //clusterManagerLogErr("\n%s\n", err);
+ clusterManagerLogErr("clusterManagerMoveSlot failed: %s\n", err);
zfree(err);
}
goto cleanup;
@@ -6431,6 +6435,7 @@ static int clusterManagerCommandRebalance(int argc, char **argv) {
char *name = config.cluster_manager_command.weight[i];
char *p = strchr(name, '=');
if (p == NULL) {
+ clusterManagerLogErr("*** invalid input %s\n", name);
result = 0;
goto cleanup;
}
@@ -6576,11 +6581,16 @@ static int clusterManagerCommandRebalance(int argc, char **argv) {
listRewind(table, &li);
while ((ln = listNext(&li)) != NULL) {
clusterManagerReshardTableItem *item = ln->value;
+ char *err;
result = clusterManagerMoveSlot(item->source,
dst,
item->slot,
- opts, NULL);
- if (!result) goto end_move;
+ opts, &err);
+ if (!result) {
+ clusterManagerLogErr("*** clusterManagerMoveSlot: %s\n", err);
+ zfree(err);
+ goto end_move;
+ }
printf("#");
fflush(stdout);
}
diff --git a/tests/cluster/tests/12-replica-migration-2.tcl b/tests/cluster/tests/12-replica-migration-2.tcl
index aecae0429..679eaa3a4 100644
--- a/tests/cluster/tests/12-replica-migration-2.tcl
+++ b/tests/cluster/tests/12-replica-migration-2.tcl
@@ -6,6 +6,7 @@
source "../tests/includes/init-tests.tcl"
source "../../../tests/support/cli.tcl"
+source "../tests/includes/utils.tcl"
# Create a cluster with 5 master and 15 slaves, to make sure there are no
# empty masters and make rebalancing simpler to handle during the test.
@@ -29,6 +30,10 @@ test "Each master should have at least two replicas attached" {
}
}
+test "Wait cluster to be stable" {
+ wait_cluster_stable
+}
+
test "Set allow-replica-migration yes" {
foreach_redis_id id {
R $id CONFIG SET cluster-allow-replica-migration yes
@@ -53,10 +58,13 @@ test "Master #0 should lose its replicas" {
}
}
+# Wait for the cluster config to propagate before attempting a
+# new resharding.
+test "Wait cluster to be stable" {
+ wait_cluster_stable
+}
+
test "Resharding back some slot to master #0" {
- # Wait for the cluster config to propagate before attempting a
- # new resharding.
- after 10000
set output [exec \
../../../src/redis-cli --cluster rebalance \
127.0.0.1:[get_instance_attrib redis 0 port] \
@@ -65,6 +73,10 @@ test "Resharding back some slot to master #0" {
--cluster-use-empty-masters >@ stdout]
}
+test "Wait cluster to be stable" {
+ wait_cluster_stable
+}
+
test "Master #0 should re-acquire one or more replicas" {
wait_for_condition 1000 50 {
[llength [lindex [R 0 role] 2]] >= 1
diff --git a/tests/cluster/tests/12.1-replica-migration-3.tcl b/tests/cluster/tests/12.1-replica-migration-3.tcl
index 25d14a56e..1227fd71a 100644
--- a/tests/cluster/tests/12.1-replica-migration-3.tcl
+++ b/tests/cluster/tests/12.1-replica-migration-3.tcl
@@ -4,6 +4,7 @@
# migrate when master becomes empty.
source "../tests/includes/init-tests.tcl"
+source "../tests/includes/utils.tcl"
# Create a cluster with 5 master and 15 slaves, to make sure there are no
# empty masters and make rebalancing simpler to handle during the test.
@@ -33,6 +34,10 @@ test "Set allow-replica-migration no" {
}
}
+test "Wait cluster to be stable" {
+ wait_cluster_stable
+}
+
set master0_id [dict get [get_myself 0] id]
test "Resharding all the master #0 slots away from it" {
set output [exec \
@@ -43,14 +48,7 @@ test "Resharding all the master #0 slots away from it" {
}
test "Wait cluster to be stable" {
- wait_for_condition 1000 50 {
- [catch {exec ../../../src/redis-cli --cluster \
- check 127.0.0.1:[get_instance_attrib redis 0 port] \
- {*}[rediscli_tls_config "../../../tests"] \
- }] == 0
- } else {
- fail "Cluster doesn't stabilize"
- }
+ wait_cluster_stable
}
test "Master #0 still should have its replicas" {
diff --git a/tests/cluster/tests/includes/utils.tcl b/tests/cluster/tests/includes/utils.tcl
index 48c40a050..c1b0fe6b7 100644
--- a/tests/cluster/tests/includes/utils.tcl
+++ b/tests/cluster/tests/includes/utils.tcl
@@ -23,3 +23,14 @@ proc fix_cluster {addr} {
fail "Cluster could not settle with configuration"
}
}
+
+proc wait_cluster_stable {} {
+ wait_for_condition 1000 50 {
+ [catch {exec ../../../src/redis-cli --cluster \
+ check 127.0.0.1:[get_instance_attrib redis 0 port] \
+ {*}[rediscli_tls_config "../../../tests"] \
+ }] == 0
+ } else {
+ fail "Cluster doesn't stabilize"
+ }
+} \ No newline at end of file
diff --git a/tests/instances.tcl b/tests/instances.tcl
index 1d2cbed49..cf0e80f6c 100644
--- a/tests/instances.tcl
+++ b/tests/instances.tcl
@@ -446,7 +446,12 @@ proc run_tests {} {
}
if {[file isdirectory $test]} continue
puts [colorstr yellow "Testing unit: [lindex [file split $test] end]"]
- source $test
+ if {[catch { source $test } err]} {
+ puts "FAILED: caught an error in the test $err"
+ puts $::errorInfo
+ incr ::failed
+ # letting the tests resume, so we'll eventually reach the cleanup and report crashes
+ }
check_leaks {redis sentinel}
# Check if a leaked fds file was created and abort the test.