MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterManagerNodeLoadInfo

Function clusterManagerNodeLoadInfo

src/redis-cli.c:3631–3805  ·  view source on GitHub ↗

Load node's cluster configuration by calling "CLUSTER NODES" command. * Node's configuration (name, replicate, slots, ...) is then updated. * If CLUSTER_MANAGER_OPT_GETFRIENDS flag is set into 'opts' argument, * and node already knows other nodes, the node's friends list is populated * with the other nodes info. */

Source from the content-addressed store, hash-verified

3629 * and node already knows other nodes, the node's friends list is populated
3630 * with the other nodes info. */
3631static int clusterManagerNodeLoadInfo(clusterManagerNode *node, int opts,
3632 char **err)
3633{
3634 redisReply *reply = CLUSTER_MANAGER_COMMAND(node, "CLUSTER NODES");
3635 int success = 1;
3636 *err = NULL;
3637 if (!clusterManagerCheckRedisReply(node, reply, err)) {
3638 success = 0;
3639 goto cleanup;
3640 }
3641 int getfriends = (opts & CLUSTER_MANAGER_OPT_GETFRIENDS);
3642 char *lines = reply->str, *p, *line;
3643 while ((p = strstr(lines, "\n")) != NULL) {
3644 *p = '\0';
3645 line = lines;
3646 lines = p + 1;
3647 char *name = NULL, *addr = NULL, *flags = NULL, *master_id = NULL,
3648 *ping_sent = NULL, *ping_recv = NULL, *config_epoch = NULL,
3649 *link_status = NULL;
3650 UNUSED(link_status);
3651 int i = 0;
3652 while ((p = strchr(line, ' ')) != NULL) {
3653 *p = '\0';
3654 char *token = line;
3655 line = p + 1;
3656 switch(i++){
3657 case 0: name = token; break;
3658 case 1: addr = token; break;
3659 case 2: flags = token; break;
3660 case 3: master_id = token; break;
3661 case 4: ping_sent = token; break;
3662 case 5: ping_recv = token; break;
3663 case 6: config_epoch = token; break;
3664 case 7: link_status = token; break;
3665 }
3666 if (i == 8) break; // Slots
3667 }
3668 if (!flags) {
3669 success = 0;
3670 goto cleanup;
3671 }
3672 int myself = (strstr(flags, "myself") != NULL);
3673 clusterManagerNode *currentNode = NULL;
3674 if (myself) {
3675 node->flags |= CLUSTER_MANAGER_FLAG_MYSELF;
3676 currentNode = node;
3677 clusterManagerNodeResetSlots(node);
3678 if (i == 8) {
3679 int remaining = strlen(line);
3680 while (remaining > 0) {
3681 p = strchr(line, ' ');
3682 if (p == NULL) p = line + remaining;
3683 remaining -= (p - line);
3684
3685 char *slotsdef = line;
3686 *p = '\0';
3687 if (remaining) {
3688 line = p + 1;

Callers 3

Calls 10

sdsnewFunction · 0.85
zreallocFunction · 0.85
clusterManagerNewNodeFunction · 0.85
listCreateFunction · 0.85
listAddNodeTailFunction · 0.85
sdsfreeFunction · 0.85
freeReplyObjectFunction · 0.85

Tested by

no test coverage detected