| 4352 | } |
| 4353 | |
| 4354 | static sds clusterManagerGetConfigSignature(clusterManagerNode *node) { |
| 4355 | sds signature = NULL; |
| 4356 | int node_count = 0, i = 0, name_len = 0; |
| 4357 | char **node_configs = NULL; |
| 4358 | redisReply *reply = CLUSTER_MANAGER_COMMAND(node, "CLUSTER NODES"); |
| 4359 | if (reply == NULL || reply->type == REDIS_REPLY_ERROR) |
| 4360 | goto cleanup; |
| 4361 | char *lines = reply->str, *p, *line; |
| 4362 | while ((p = strstr(lines, "\n")) != NULL) { |
| 4363 | i = 0; |
| 4364 | *p = '\0'; |
| 4365 | line = lines; |
| 4366 | lines = p + 1; |
| 4367 | char *nodename = NULL; |
| 4368 | int tot_size = 0; |
| 4369 | while ((p = strchr(line, ' ')) != NULL) { |
| 4370 | *p = '\0'; |
| 4371 | char *token = line; |
| 4372 | line = p + 1; |
| 4373 | if (i == 0) { |
| 4374 | nodename = token; |
| 4375 | tot_size = (p - token); |
| 4376 | name_len = tot_size++; // Make room for ':' in tot_size |
| 4377 | } |
| 4378 | if (++i == 8) break; |
| 4379 | } |
| 4380 | if (i != 8) continue; |
| 4381 | if (nodename == NULL) continue; |
| 4382 | int remaining = strlen(line); |
| 4383 | if (remaining == 0) continue; |
| 4384 | char **slots = NULL; |
| 4385 | int c = 0; |
| 4386 | while (remaining > 0) { |
| 4387 | p = strchr(line, ' '); |
| 4388 | if (p == NULL) p = line + remaining; |
| 4389 | int size = (p - line); |
| 4390 | remaining -= size; |
| 4391 | tot_size += size; |
| 4392 | char *slotsdef = line; |
| 4393 | *p = '\0'; |
| 4394 | if (remaining) { |
| 4395 | line = p + 1; |
| 4396 | remaining--; |
| 4397 | } else line = p; |
| 4398 | if (slotsdef[0] != '[') { |
| 4399 | c++; |
| 4400 | slots = zrealloc(slots, (c * sizeof(char *))); |
| 4401 | slots[c - 1] = slotsdef; |
| 4402 | } |
| 4403 | } |
| 4404 | if (c > 0) { |
| 4405 | if (c > 1) |
| 4406 | qsort(slots, c, sizeof(char *), clusterManagerSlotCompare); |
| 4407 | node_count++; |
| 4408 | node_configs = |
| 4409 | zrealloc(node_configs, (node_count * sizeof(char *))); |
| 4410 | /* Make room for '|' separators. */ |
| 4411 | tot_size += (sizeof(char) * (c - 1)); |
no test coverage detected