| 579 | } |
| 580 | |
| 581 | extern "C" int clusterManagerCheckCluster(int quiet) { |
| 582 | listNode *ln = listFirst(cluster_manager.nodes); |
| 583 | if (!ln) return 0; |
| 584 | clusterManagerNode *node = (clusterManagerNode*)ln->value; |
| 585 | clusterManagerLogInfo(">>> Performing Cluster Check (using node %s:%d)\n", |
| 586 | node->ip, node->port); |
| 587 | int result = 1, consistent = 0; |
| 588 | int do_fix = config.cluster_manager_command.flags & |
| 589 | CLUSTER_MANAGER_CMD_FLAG_FIX; |
| 590 | if (!quiet) clusterManagerShowNodes(); |
| 591 | consistent = clusterManagerIsConfigConsistent(1 /*fLog*/); |
| 592 | if (!consistent) { |
| 593 | sds err = sdsnew("[ERR] Nodes don't agree about configuration!"); |
| 594 | clusterManagerOnError(err); |
| 595 | result = 0; |
| 596 | } else { |
| 597 | clusterManagerLogOk("[OK] All nodes agree about slots " |
| 598 | "configuration.\n"); |
| 599 | } |
| 600 | /* Check open slots */ |
| 601 | clusterManagerLogInfo(">>> Check for open slots...\n"); |
| 602 | listIter li; |
| 603 | listRewind(cluster_manager.nodes, &li); |
| 604 | int i; |
| 605 | dict *open_slots = NULL; |
| 606 | while ((ln = listNext(&li)) != NULL) { |
| 607 | clusterManagerNode *n = (clusterManagerNode*)ln->value; |
| 608 | if (n->migrating != NULL) { |
| 609 | if (open_slots == NULL) |
| 610 | open_slots = dictCreate(&clusterManagerDictType, NULL); |
| 611 | sds errstr = sdsempty(); |
| 612 | errstr = sdscatprintf(errstr, |
| 613 | "[WARNING] Node %s:%d has slots in " |
| 614 | "migrating state ", |
| 615 | n->ip, |
| 616 | n->port); |
| 617 | for (i = 0; i < n->migrating_count; i += 2) { |
| 618 | sds slot = n->migrating[i]; |
| 619 | dictReplace(open_slots, slot, sdsdup(n->migrating[i + 1])); |
| 620 | const char *fmt = (i > 0 ? ",%S" : "%S"); |
| 621 | errstr = sdscatfmt(errstr, fmt, slot); |
| 622 | } |
| 623 | errstr = sdscat(errstr, "."); |
| 624 | clusterManagerOnError(errstr); |
| 625 | } |
| 626 | if (n->importing != NULL) { |
| 627 | if (open_slots == NULL) |
| 628 | open_slots = dictCreate(&clusterManagerDictType, NULL); |
| 629 | sds errstr = sdsempty(); |
| 630 | errstr = sdscatprintf(errstr, |
| 631 | "[WARNING] Node %s:%d has slots in " |
| 632 | "importing state ", |
| 633 | n->ip, |
| 634 | n->port); |
| 635 | for (i = 0; i < n->importing_count; i += 2) { |
| 636 | sds slot = n->importing[i]; |
| 637 | dictReplace(open_slots, slot, sdsdup(n->importing[i + 1])); |
| 638 | const char *fmt = (i > 0 ? ",%S" : "%S"); |
no test coverage detected