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

Function clusterManagerCommandAddNode

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

Source from the content-addressed store, hash-verified

5884}
5885
5886static int clusterManagerCommandAddNode(int argc, char **argv) {
5887 int success = 1;
5888 redisReply *reply = NULL;
5889 char *ref_ip = NULL, *ip = NULL;
5890 int ref_port = 0, port = 0;
5891 if (!getClusterHostFromCmdArgs(argc - 1, argv + 1, &ref_ip, &ref_port))
5892 goto invalid_args;
5893 if (!getClusterHostFromCmdArgs(1, argv, &ip, &port))
5894 goto invalid_args;
5895 clusterManagerLogInfo(">>> Adding node %s:%d to cluster %s:%d\n", ip, port,
5896 ref_ip, ref_port);
5897 // Check the existing cluster
5898 clusterManagerNode *refnode = clusterManagerNewNode(ref_ip, ref_port);
5899 if (!clusterManagerLoadInfoFromNode(refnode, 0)) return 0;
5900 if (!clusterManagerCheckCluster(0)) return 0;
5901
5902 /* If --cluster-master-id was specified, try to resolve it now so that we
5903 * abort before starting with the node configuration. */
5904 clusterManagerNode *master_node = NULL;
5905 if (config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_SLAVE) {
5906 char *master_id = config.cluster_manager_command.master_id;
5907 if (master_id != NULL) {
5908 master_node = clusterManagerNodeByName(master_id);
5909 if (master_node == NULL) {
5910 clusterManagerLogErr("[ERR] No such master ID %s\n", master_id);
5911 return 0;
5912 }
5913 } else {
5914 master_node = clusterManagerNodeWithLeastReplicas();
5915 assert(master_node != NULL);
5916 printf("Automatically selected master %s:%d\n", master_node->ip,
5917 master_node->port);
5918 }
5919 }
5920
5921 // Add the new node
5922 clusterManagerNode *new_node = clusterManagerNewNode(ip, port);
5923 int added = 0;
5924 if (!clusterManagerNodeConnect(new_node)) {
5925 clusterManagerLogErr("[ERR] Sorry, can't connect to node %s:%d\n",
5926 ip, port);
5927 success = 0;
5928 goto cleanup;
5929 }
5930 char *err = NULL;
5931 if (!(success = clusterManagerNodeIsCluster(new_node, &err))) {
5932 clusterManagerPrintNotClusterNodeError(new_node, err);
5933 if (err) zfree(err);
5934 goto cleanup;
5935 }
5936 if (!clusterManagerNodeLoadInfo(new_node, 0, &err)) {
5937 if (err) {
5938 CLUSTER_MANAGER_PRINT_REPLY_ERROR(new_node, err);
5939 zfree(err);
5940 }
5941 success = 0;
5942 goto cleanup;
5943 }

Callers

nothing calls this directly

Tested by

no test coverage detected