summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryura <funny.falcon@gmail.com>2018-08-22 17:56:13 +0300
committeryura <funny.falcon@gmail.com>2018-12-07 14:14:11 +0300
commit74f942cfa5386b501c0b23733d97ee9a69ad8888 (patch)
treecc1f6bde1f4b7c3643df9994e6d81ba4470f2356
parent9f87ef93993b386c22ea673c8f2f1f298f0d8bc9 (diff)
downloadredis-74f942cfa5386b501c0b23733d97ee9a69ad8888.tar.gz
redis-cli reshard/rebalance: ability to force replacement on existing keys
-rw-r--r--src/redis-cli.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 0ae96f564..7e558a306 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -2826,8 +2826,8 @@ static int clusterManagerMigrateKeysInSlot(clusterManagerNode *source,
char **err)
{
int success = 1;
- int do_fix = (config.cluster_manager_command.flags &
- CLUSTER_MANAGER_CMD_FLAG_FIX);
+ int replace_existing_keys = (config.cluster_manager_command.flags &
+ (CLUSTER_MANAGER_CMD_FLAG_FIX | CLUSTER_MANAGER_CMD_FLAG_REPLACE));
while (1) {
char *dots = NULL;
redisReply *reply = NULL, *migrate_reply = NULL;
@@ -2858,13 +2858,14 @@ static int clusterManagerMigrateKeysInSlot(clusterManagerNode *source,
dots);
if (migrate_reply == NULL) goto next;
if (migrate_reply->type == REDIS_REPLY_ERROR) {
- if (do_fix && strstr(migrate_reply->str, "BUSYKEY")) {
+ int is_busy = strstr(migrate_reply->str, "BUSYKEY") != NULL;
+ int not_served = strstr(migrate_reply->str, "slot not served") != NULL;
+ if (replace_existing_keys && (is_busy || not_served)) {
/* If the key already exists, try to migrate keys
* adding REPLACE option.
* If the key's slot is not served, try to assign slot
* to the target node. */
- int is_busy = (strstr(migrate_reply->str, "BUSYKEY") != NULL);
- if (strstr(migrate_reply->str, "slot not served") != NULL)
+ if (not_served)
clusterManagerSetSlot(source, target, slot, "node", NULL);
clusterManagerLogWarn("*** Target key exists. "
"Replacing it for FIX.\n");