| 496 | } |
| 497 | |
| 498 | list *clusterManagerGetDisconnectedLinks(clusterManagerNode *node) { |
| 499 | list *links = NULL; |
| 500 | char *lines = NULL, *p, *line; |
| 501 | redisReply *reply = (redisReply*)CLUSTER_MANAGER_COMMAND(node, "CLUSTER NODES"); |
| 502 | if (!clusterManagerCheckRedisReply(node, reply, NULL)) goto cleanup; |
| 503 | links = listCreate(); |
| 504 | lines = reply->str; |
| 505 | while ((p = strstr(lines, "\n")) != NULL) { |
| 506 | int i = 0; |
| 507 | *p = '\0'; |
| 508 | line = lines; |
| 509 | lines = p + 1; |
| 510 | char *nodename = NULL, *addr = NULL, *flags = NULL, *link_status = NULL; |
| 511 | while ((p = strchr(line, ' ')) != NULL) { |
| 512 | *p = '\0'; |
| 513 | char *token = line; |
| 514 | line = p + 1; |
| 515 | if (i == 0) nodename = token; |
| 516 | else if (i == 1) addr = token; |
| 517 | else if (i == 2) flags = token; |
| 518 | else if (i == 7) link_status = token; |
| 519 | else if (i == 8) break; |
| 520 | i++; |
| 521 | } |
| 522 | if (i == 7) link_status = line; |
| 523 | if (nodename == NULL || addr == NULL || flags == NULL || |
| 524 | link_status == NULL) continue; |
| 525 | if (strstr(flags, "myself") != NULL) continue; |
| 526 | int disconnected = ((strstr(flags, "disconnected") != NULL) || |
| 527 | (strstr(link_status, "disconnected"))); |
| 528 | int handshaking = (strstr(flags, "handshake") != NULL); |
| 529 | if (disconnected || handshaking) { |
| 530 | clusterManagerLink *link = (clusterManagerLink*)zmalloc(sizeof(*link), MALLOC_LOCAL); |
| 531 | link->node_name = sdsnew(nodename); |
| 532 | link->node_addr = sdsnew(addr); |
| 533 | link->connected = 0; |
| 534 | link->handshaking = handshaking; |
| 535 | listAddNodeTail(links, link); |
| 536 | } |
| 537 | } |
| 538 | cleanup: |
| 539 | if (reply != NULL) freeReplyObject(reply); |
| 540 | return links; |
| 541 | } |
| 542 | |
| 543 | /* Check for disconnected cluster links. It returns a dict whose keys |
| 544 | * are the unreachable node addresses and the values are lists of |
no test coverage detected