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

Function clusterManagerCommandDeleteNode

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

Source from the content-addressed store, hash-verified

5981}
5982
5983static int clusterManagerCommandDeleteNode(int argc, char **argv) {
5984 UNUSED(argc);
5985 int success = 1;
5986 int port = 0;
5987 char *ip = NULL;
5988 if (!getClusterHostFromCmdArgs(1, argv, &ip, &port)) goto invalid_args;
5989 char *node_id = argv[1];
5990 clusterManagerLogInfo(">>> Removing node %s from cluster %s:%d\n",
5991 node_id, ip, port);
5992 clusterManagerNode *ref_node = clusterManagerNewNode(ip, port);
5993 clusterManagerNode *node = NULL;
5994
5995 // Load cluster information
5996 if (!clusterManagerLoadInfoFromNode(ref_node, 0)) return 0;
5997
5998 // Check if the node exists and is not empty
5999 node = clusterManagerNodeByName(node_id);
6000 if (node == NULL) {
6001 clusterManagerLogErr("[ERR] No such node ID %s\n", node_id);
6002 return 0;
6003 }
6004 if (node->slots_count != 0) {
6005 clusterManagerLogErr("[ERR] Node %s:%d is not empty! Reshard data "
6006 "away and try again.\n", node->ip, node->port);
6007 return 0;
6008 }
6009
6010 // Send CLUSTER FORGET to all the nodes but the node to remove
6011 clusterManagerLogInfo(">>> Sending CLUSTER FORGET messages to the "
6012 "cluster...\n");
6013 listIter li;
6014 listNode *ln;
6015 listRewind(cluster_manager.nodes, &li);
6016 while ((ln = listNext(&li)) != NULL) {
6017 clusterManagerNode *n = ln->value;
6018 if (n == node) continue;
6019 if (n->replicate && !strcasecmp(n->replicate, node_id)) {
6020 // Reconfigure the slave to replicate with some other node
6021 clusterManagerNode *master = clusterManagerNodeWithLeastReplicas();
6022 assert(master != NULL);
6023 clusterManagerLogInfo(">>> %s:%d as replica of %s:%d\n",
6024 n->ip, n->port, master->ip, master->port);
6025 redisReply *r = CLUSTER_MANAGER_COMMAND(n, "CLUSTER REPLICATE %s",
6026 master->name);
6027 success = clusterManagerCheckRedisReply(n, r, NULL);
6028 if (r) freeReplyObject(r);
6029 if (!success) return 0;
6030 }
6031 redisReply *r = CLUSTER_MANAGER_COMMAND(n, "CLUSTER FORGET %s",
6032 node_id);
6033 success = clusterManagerCheckRedisReply(n, r, NULL);
6034 if (r) freeReplyObject(r);
6035 if (!success) return 0;
6036 }
6037
6038 /* Finally send CLUSTER RESET to the node. */
6039 clusterManagerLogInfo(">>> Sending CLUSTER RESET SOFT to the "
6040 "deleted node.\n");

Callers

nothing calls this directly

Calls 11

clusterManagerNewNodeFunction · 0.85
clusterManagerNodeByNameFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
strcasecmpFunction · 0.85
freeReplyObjectFunction · 0.85
redisCommandClass · 0.70

Tested by

no test coverage detected