From 827e6cc6443e0727a0cfbf3fcf87303c9783dc78 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 13 May 2020 09:24:51 -0700 Subject: [PATCH 1/3] Redis-cli 6.0.1 `--cluster-yes` doesn't work (fix #7246) This make it so that all prompts for all redis-cli --cluster commands are automatically answered with a yes. --- src/redis-cli.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 208f7b35d..2624a528a 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1798,6 +1798,10 @@ static void usage(void) { } static int confirmWithYes(char *msg) { + if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_YES) { + return 1; + } + printf("%s (type 'yes' to accept): ", msg); fflush(stdout); char buf[4]; @@ -8084,7 +8088,7 @@ int main(int argc, char **argv) { if (cliConnect(0) == REDIS_ERR) exit(1); if (config.interval == 0) config.interval = 1000000; statMode(); - } +( } /* Scan mode */ if (config.scan_mode) { From db39b04d760eb3f1450184d0e4759db81de9500a Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 13 May 2020 09:32:27 -0700 Subject: [PATCH 2/3] fix typo ... --- src/redis-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 2624a528a..7f952a4c6 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -8088,7 +8088,7 @@ int main(int argc, char **argv) { if (cliConnect(0) == REDIS_ERR) exit(1); if (config.interval == 0) config.interval = 1000000; statMode(); -( } + } /* Scan mode */ if (config.scan_mode) { From f4d2abd3df760e370510c79d2d5e27c22aa1d1ce Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 14 May 2020 15:29:06 -0700 Subject: [PATCH 3/3] do not handle --cluster-yes for cluster fix mode --- src/redis-cli.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 7f952a4c6..75845f346 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1797,11 +1797,14 @@ static void usage(void) { exit(1); } -static int confirmWithYes(char *msg) { - if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_YES) { +static int confirmWithYes(char *msg, int force) { + /* if force is true and --cluster-yes option is on, + * do not prompt for an answer */ + if (force && + (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_YES)) { return 1; } - + printf("%s (type 'yes' to accept): ", msg); fflush(stdout); char buf[4]; @@ -4489,12 +4492,16 @@ static int clusterManagerFixSlotsCoverage(char *all_slots) { } dictReleaseIterator(iter); + /* we want explicit manual confirmation from users for all the fix cases */ + int force = 0; + /* Handle case "1": keys in no node. */ if (listLength(none) > 0) { printf("The following uncovered slots have no keys " "across the cluster:\n"); clusterManagerPrintSlotsList(none); - if (confirmWithYes("Fix these slots by covering with a random node?")){ + if (confirmWithYes("Fix these slots by covering with a random node?", + force)) { listIter li; listNode *ln; listRewind(none, &li); @@ -4520,7 +4527,8 @@ static int clusterManagerFixSlotsCoverage(char *all_slots) { if (listLength(single) > 0) { printf("The following uncovered slots have keys in just one node:\n"); clusterManagerPrintSlotsList(single); - if (confirmWithYes("Fix these slots by covering with those nodes?")){ + if (confirmWithYes("Fix these slots by covering with those nodes?", + force)) { listIter li; listNode *ln; listRewind(single, &li); @@ -4552,7 +4560,7 @@ static int clusterManagerFixSlotsCoverage(char *all_slots) { printf("The following uncovered slots have keys in multiple nodes:\n"); clusterManagerPrintSlotsList(multi); if (confirmWithYes("Fix these slots by moving keys " - "into a single node?")) { + "into a single node?", force)) { listIter li; listNode *ln; listRewind(multi, &li); @@ -5515,7 +5523,8 @@ assign_replicas: } clusterManagerOptimizeAntiAffinity(ip_nodes, ip_count); clusterManagerShowNodes(); - if (confirmWithYes("Can I set the above configuration?")) { + int force = 1; + if (confirmWithYes("Can I set the above configuration?", force)) { listRewind(cluster_manager.nodes, &li); while ((ln = listNext(&li)) != NULL) { clusterManagerNode *node = ln->value;