Skip to content

Commit 74934c5

Browse files
enjoy-binbinhpatro
authored andcommitted
Don't allow slot migration to myself node (valkey-io#2497)
This may result in meaningless slot migration job, we should return an error to user in advance to avoid operation error. Also `by myself` is not correct English grammar and `myself` is a internal code terminology, changed to `by this node`. Was introduced in valkey-io#1949. --------- Signed-off-by: Binbin <[email protected]> Signed-off-by: Harkrishn Patro <[email protected]>
1 parent 4ad9a2c commit 74934c5

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/cluster_migrateslots.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ void clusterCommandMigrateSlots(client *c) {
851851
goto cleanup;
852852
}
853853
if (source_node != server.cluster->myself) {
854-
addReplyErrorFormat(c, "Slots are not served by myself.");
854+
addReplyError(c, "Slots are not served by this node.");
855855
goto cleanup;
856856
}
857857

@@ -896,6 +896,10 @@ void clusterCommandMigrateSlots(client *c) {
896896
(sds)c->argv[curr_index]->ptr);
897897
goto cleanup;
898898
}
899+
if (target_node == server.cluster->myself) {
900+
addReplyError(c, "Target node can not be this node.");
901+
goto cleanup;
902+
}
899903
curr_index++;
900904

901905
slotMigrationJob *job = createSlotExportJob(target_node, slot_ranges);

tests/unit/cluster/cluster-migrateslots.tcl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ start_cluster 3 3 {tags {logreqres:skip external:skip cluster} overrides {cluste
200200
R 0 CLUSTER ADDSLOTS 0
201201

202202
assert_error "*Slot migration can only be used on primary nodes*" {R 3 CLUSTER MIGRATESLOTS SLOTSRANGE 0 0}
203-
assert_error "*Slots are not served by myself*" {R 2 CLUSTER MIGRATESLOTS SLOTSRANGE 0 0 NODE $node0_id}
203+
assert_error "*Slots are not served by this node*" {R 2 CLUSTER MIGRATESLOTS SLOTSRANGE 0 0 NODE $node0_id}
204+
assert_error "*Target node can not be this node*" {R 0 CLUSTER MIGRATESLOTS SLOTSRANGE 0 0 NODE $node0_id}
204205

205206
assert_error "*wrong number of arguments*" {R 0 CLUSTER CANCELSLOTMIGRATIONS ARG}
206207
assert_error "*No migrations ongoing*" {R 0 CLUSTER CANCELSLOTMIGRATIONS}

0 commit comments

Comments
 (0)