MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterManagerLoadInfoFromNode

Function clusterManagerLoadInfoFromNode

app/redis-6.2.6/src/redis-cli.c:4256–4333  ·  view source on GitHub ↗

Retrieves info about the cluster using argument 'node' as the starting * point. All nodes will be loaded inside the cluster_manager.nodes list. * Warning: if something goes wrong, it will free the starting node before * returning 0. */

Source from the content-addressed store, hash-verified

4254 * Warning: if something goes wrong, it will free the starting node before
4255 * returning 0. */
4256static int clusterManagerLoadInfoFromNode(clusterManagerNode *node, int opts) {
4257 if (node->context == NULL && !clusterManagerNodeConnect(node)) {
4258 freeClusterManagerNode(node);
4259 return 0;
4260 }
4261 opts |= CLUSTER_MANAGER_OPT_GETFRIENDS;
4262 char *e = NULL;
4263 if (!clusterManagerNodeIsCluster(node, &e)) {
4264 clusterManagerPrintNotClusterNodeError(node, e);
4265 if (e) zfree(e);
4266 freeClusterManagerNode(node);
4267 return 0;
4268 }
4269 e = NULL;
4270 if (!clusterManagerNodeLoadInfo(node, opts, &e)) {
4271 if (e) {
4272 CLUSTER_MANAGER_PRINT_REPLY_ERROR(node, e);
4273 zfree(e);
4274 }
4275 freeClusterManagerNode(node);
4276 return 0;
4277 }
4278 listIter li;
4279 listNode *ln;
4280 if (cluster_manager.nodes != NULL) {
4281 listRewind(cluster_manager.nodes, &li);
4282 while ((ln = listNext(&li)) != NULL)
4283 freeClusterManagerNode((clusterManagerNode *) ln->value);
4284 listRelease(cluster_manager.nodes);
4285 }
4286 cluster_manager.nodes = listCreate();
4287 listAddNodeTail(cluster_manager.nodes, node);
4288 if (node->friends != NULL) {
4289 listRewind(node->friends, &li);
4290 while ((ln = listNext(&li)) != NULL) {
4291 clusterManagerNode *friend = ln->value;
4292 if (!friend->ip || !friend->port) goto invalid_friend;
4293 if (!friend->context && !clusterManagerNodeConnect(friend))
4294 goto invalid_friend;
4295 e = NULL;
4296 if (clusterManagerNodeLoadInfo(friend, 0, &e)) {
4297 if (friend->flags & (CLUSTER_MANAGER_FLAG_NOADDR |
4298 CLUSTER_MANAGER_FLAG_DISCONNECT |
4299 CLUSTER_MANAGER_FLAG_FAIL))
4300 {
4301 goto invalid_friend;
4302 }
4303 listAddNodeTail(cluster_manager.nodes, friend);
4304 } else {
4305 clusterManagerLogErr("[ERR] Unable to load info for "
4306 "node %s:%d\n",
4307 friend->ip, friend->port);
4308 goto invalid_friend;
4309 }
4310 continue;
4311invalid_friend:
4312 if (!(friend->flags & CLUSTER_MANAGER_FLAG_SLAVE))
4313 cluster_manager.unreachable_masters++;

Calls 12

freeClusterManagerNodeFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
listReleaseFunction · 0.85
listCreateFunction · 0.85
listAddNodeTailFunction · 0.85
clusterManagerNodeByNameFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected