| 5166 | } |
| 5167 | |
| 5168 | static int clusterManagerCommandReshard(int argc, char **argv) { |
| 5169 | int port = 0; |
| 5170 | char *ip = NULL; |
| 5171 | if (!getClusterHostFromCmdArgs(argc, argv, &ip, &port)) goto invalid_args; |
| 5172 | clusterManagerNode *node = clusterManagerNewNode(ip, port); |
| 5173 | if (!clusterManagerLoadInfoFromNode(node, 0)) return 0; |
| 5174 | clusterManagerCheckCluster(0); |
| 5175 | if (cluster_manager.errors && listLength(cluster_manager.errors) > 0 && !config.force_mode) { |
| 5176 | fflush(stdout); |
| 5177 | fprintf(stderr, |
| 5178 | "*** Please fix your cluster problems before resharding\n"); |
| 5179 | return 0; |
| 5180 | } |
| 5181 | int slots = config.cluster_manager_command.slots; |
| 5182 | if (!slots) { |
| 5183 | while (slots <= 0 || slots > CLUSTER_MANAGER_SLOTS) { |
| 5184 | printf("How many slots do you want to move (from 1 to %d)? ", |
| 5185 | CLUSTER_MANAGER_SLOTS); |
| 5186 | fflush(stdout); |
| 5187 | char buf[6]; |
| 5188 | int nread = read(fileno(stdin),buf,6); |
| 5189 | if (nread <= 0) continue; |
| 5190 | int last_idx = nread - 1; |
| 5191 | if (buf[last_idx] != '\n') { |
| 5192 | int ch; |
| 5193 | while ((ch = getchar()) != '\n' && ch != EOF) {} |
| 5194 | } |
| 5195 | buf[last_idx] = '\0'; |
| 5196 | slots = atoi(buf); |
| 5197 | } |
| 5198 | } |
| 5199 | char buf[255]; |
| 5200 | char *to = config.cluster_manager_command.to, |
| 5201 | *from = config.cluster_manager_command.from; |
| 5202 | while (to == NULL) { |
| 5203 | printf("What is the receiving node ID? "); |
| 5204 | fflush(stdout); |
| 5205 | int nread = read(fileno(stdin),buf,255); |
| 5206 | if (nread <= 0) continue; |
| 5207 | int last_idx = nread - 1; |
| 5208 | if (buf[last_idx] != '\n') { |
| 5209 | int ch; |
| 5210 | while ((ch = getchar()) != '\n' && ch != EOF) {} |
| 5211 | } |
| 5212 | buf[last_idx] = '\0'; |
| 5213 | if (strlen(buf) > 0) to = buf; |
| 5214 | } |
| 5215 | int raise_err = 0; |
| 5216 | clusterManagerNode *target = clusterNodeForResharding(to, NULL, &raise_err); |
| 5217 | if (target == NULL) return 0; |
| 5218 | list *sources = listCreate(); |
| 5219 | list *table = NULL; |
| 5220 | int all = 0, result = 1; |
| 5221 | if (from == NULL) { |
| 5222 | printf("Please enter all the source node IDs.\n"); |
| 5223 | printf(" Type 'all' to use all the nodes as source nodes for " |
| 5224 | "the hash slots.\n"); |
| 5225 | printf(" Type 'done' once you entered all the source nodes IDs.\n"); |
nothing calls this directly
no test coverage detected