| 6079 | } |
| 6080 | |
| 6081 | static int clusterManagerCommandReshard(int argc, char **argv) { |
| 6082 | int port = 0; |
| 6083 | char *ip = NULL; |
| 6084 | if (!getClusterHostFromCmdArgs(argc, argv, &ip, &port)) goto invalid_args; |
| 6085 | clusterManagerNode *node = clusterManagerNewNode(ip, port); |
| 6086 | if (!clusterManagerLoadInfoFromNode(node, 0)) return 0; |
| 6087 | clusterManagerCheckCluster(0); |
| 6088 | if (cluster_manager.errors && listLength(cluster_manager.errors) > 0) { |
| 6089 | fflush(stdout); |
| 6090 | fprintf(stderr, |
| 6091 | "*** Please fix your cluster problems before resharding\n"); |
| 6092 | return 0; |
| 6093 | } |
| 6094 | int slots = config.cluster_manager_command.slots; |
| 6095 | if (!slots) { |
| 6096 | while (slots <= 0 || slots > CLUSTER_MANAGER_SLOTS) { |
| 6097 | printf("How many slots do you want to move (from 1 to %d)? ", |
| 6098 | CLUSTER_MANAGER_SLOTS); |
| 6099 | fflush(stdout); |
| 6100 | char buf[6]; |
| 6101 | int nread = read(fileno(stdin),buf,6); |
| 6102 | if (nread <= 0) continue; |
| 6103 | int last_idx = nread - 1; |
| 6104 | if (buf[last_idx] != '\n') { |
| 6105 | int ch; |
| 6106 | while ((ch = getchar()) != '\n' && ch != EOF) {} |
| 6107 | } |
| 6108 | buf[last_idx] = '\0'; |
| 6109 | slots = atoi(buf); |
| 6110 | } |
| 6111 | } |
| 6112 | char buf[255]; |
| 6113 | char *to = config.cluster_manager_command.to, |
| 6114 | *from = config.cluster_manager_command.from; |
| 6115 | while (to == NULL) { |
| 6116 | printf("What is the receiving node ID? "); |
| 6117 | fflush(stdout); |
| 6118 | int nread = read(fileno(stdin),buf,255); |
| 6119 | if (nread <= 0) continue; |
| 6120 | int last_idx = nread - 1; |
| 6121 | if (buf[last_idx] != '\n') { |
| 6122 | int ch; |
| 6123 | while ((ch = getchar()) != '\n' && ch != EOF) {} |
| 6124 | } |
| 6125 | buf[last_idx] = '\0'; |
| 6126 | if (strlen(buf) > 0) to = buf; |
| 6127 | } |
| 6128 | int raise_err = 0; |
| 6129 | clusterManagerNode *target = clusterNodeForResharding(to, NULL, &raise_err); |
| 6130 | if (target == NULL) return 0; |
| 6131 | list *sources = listCreate(); |
| 6132 | list *table = NULL; |
| 6133 | int all = 0, result = 1; |
| 6134 | if (from == NULL) { |
| 6135 | printf("Please enter all the source node IDs.\n"); |
| 6136 | printf(" Type 'all' to use all the nodes as source nodes for " |
| 6137 | "the hash slots.\n"); |
| 6138 | printf(" Type 'done' once you entered all the source nodes IDs.\n"); |
nothing calls this directly
no test coverage detected