Cluster Manager: more checks on --cluster-weight option.

This commit is contained in:
artix 2018-06-27 17:29:11 +02:00
parent d222eda9f0
commit d4182a0a0d

View File

@ -167,8 +167,8 @@ typedef struct clusterManagerCommand {
char *from; char *from;
char *to; char *to;
char **weight; char **weight;
char *master_id;
int weight_argc; int weight_argc;
char *master_id;
int slots; int slots;
int timeout; int timeout;
int pipeline; int pipeline;
@ -1337,11 +1337,20 @@ static int parseOptions(int argc, char **argv) {
} else if (!strcmp(argv[i],"--cluster-to") && !lastarg) { } else if (!strcmp(argv[i],"--cluster-to") && !lastarg) {
config.cluster_manager_command.to = argv[++i]; config.cluster_manager_command.to = argv[++i];
} else if (!strcmp(argv[i],"--cluster-weight") && !lastarg) { } else if (!strcmp(argv[i],"--cluster-weight") && !lastarg) {
if (config.cluster_manager_command.weight != NULL) {
fprintf(stderr, "WARNING: you cannot use --cluster-weight "
"more than once.\n"
"You can set more weights by adding them "
"as a space-separated list, ie:\n"
"--cluster-weight n1=w n2=w\n");
exit(1);
}
int widx = i + 1; int widx = i + 1;
char **weight = argv + widx; char **weight = argv + widx;
int wargc = 0; int wargc = 0;
for (; widx < argc; widx++) { for (; widx < argc; widx++) {
if (strstr(argv[widx], "--") == argv[widx]) break; if (strstr(argv[widx], "--") == argv[widx]) break;
if (strchr(argv[widx], '=') == NULL) break;
wargc++; wargc++;
} }
if (wargc > 0) { if (wargc > 0) {
@ -4899,7 +4908,7 @@ static int clusterManagerCommandRebalance(int argc, char **argv) {
clusterManagerCheckCluster(1); clusterManagerCheckCluster(1);
if (cluster_manager.errors && listLength(cluster_manager.errors) > 0) { if (cluster_manager.errors && listLength(cluster_manager.errors) > 0) {
clusterManagerLogErr("*** Please fix your cluster problems " clusterManagerLogErr("*** Please fix your cluster problems "
"before rebalancing" ); "before rebalancing\n");
result = 0; result = 0;
goto cleanup; goto cleanup;
} }
@ -6610,6 +6619,7 @@ int main(int argc, char **argv) {
config.cluster_manager_command.from = NULL; config.cluster_manager_command.from = NULL;
config.cluster_manager_command.to = NULL; config.cluster_manager_command.to = NULL;
config.cluster_manager_command.weight = NULL; config.cluster_manager_command.weight = NULL;
config.cluster_manager_command.weight_argc = 0;
config.cluster_manager_command.slots = 0; config.cluster_manager_command.slots = 0;
config.cluster_manager_command.timeout = CLUSTER_MANAGER_MIGRATE_TIMEOUT; config.cluster_manager_command.timeout = CLUSTER_MANAGER_MIGRATE_TIMEOUT;
config.cluster_manager_command.pipeline = CLUSTER_MANAGER_MIGRATE_PIPELINE; config.cluster_manager_command.pipeline = CLUSTER_MANAGER_MIGRATE_PIPELINE;