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. */
| 4074 | * and node already knows other nodes, the node's friends list is populated |
| 4075 | * with the other nodes info. */ |
| 4076 | static int clusterManagerNodeLoadInfo(clusterManagerNode *node, int opts, |
| 4077 | char **err) |
| 4078 | { |
| 4079 | redisReply *reply = CLUSTER_MANAGER_COMMAND(node, "CLUSTER NODES"); |
| 4080 | int success = 1; |
| 4081 | *err = NULL; |
| 4082 | if (!clusterManagerCheckRedisReply(node, reply, err)) { |
| 4083 | success = 0; |
| 4084 | goto cleanup; |
| 4085 | } |
| 4086 | int getfriends = (opts & CLUSTER_MANAGER_OPT_GETFRIENDS); |
| 4087 | char *lines = reply->str, *p, *line; |
| 4088 | while ((p = strstr(lines, "\n")) != NULL) { |
| 4089 | *p = '\0'; |
| 4090 | line = lines; |
| 4091 | lines = p + 1; |
| 4092 | char *name = NULL, *addr = NULL, *flags = NULL, *master_id = NULL, |
| 4093 | *ping_sent = NULL, *ping_recv = NULL, *config_epoch = NULL, |
| 4094 | *link_status = NULL; |
| 4095 | UNUSED(link_status); |
| 4096 | int i = 0; |
| 4097 | while ((p = strchr(line, ' ')) != NULL) { |
| 4098 | *p = '\0'; |
| 4099 | char *token = line; |
| 4100 | line = p + 1; |
| 4101 | switch(i++){ |
| 4102 | case 0: name = token; break; |
| 4103 | case 1: addr = token; break; |
| 4104 | case 2: flags = token; break; |
| 4105 | case 3: master_id = token; break; |
| 4106 | case 4: ping_sent = token; break; |
| 4107 | case 5: ping_recv = token; break; |
| 4108 | case 6: config_epoch = token; break; |
| 4109 | case 7: link_status = token; break; |
| 4110 | } |
| 4111 | if (i == 8) break; // Slots |
| 4112 | } |
| 4113 | if (!flags) { |
| 4114 | success = 0; |
| 4115 | goto cleanup; |
| 4116 | } |
| 4117 | int myself = (strstr(flags, "myself") != NULL); |
| 4118 | clusterManagerNode *currentNode = NULL; |
| 4119 | if (myself) { |
| 4120 | node->flags |= CLUSTER_MANAGER_FLAG_MYSELF; |
| 4121 | currentNode = node; |
| 4122 | clusterManagerNodeResetSlots(node); |
| 4123 | if (i == 8) { |
| 4124 | int remaining = strlen(line); |
| 4125 | while (remaining > 0) { |
| 4126 | p = strchr(line, ' '); |
| 4127 | if (p == NULL) p = line + remaining; |
| 4128 | remaining -= (p - line); |
| 4129 | |
| 4130 | char *slotsdef = line; |
| 4131 | *p = '\0'; |
| 4132 | if (remaining) { |
| 4133 | line = p + 1; |
no test coverage detected