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

Function clusterManagerCommandImport

src/redis-cli.c:5602–5758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5600}
5601
5602static int clusterManagerCommandImport(int argc, char **argv) {
5603 int success = 1;
5604 int port = 0, src_port = 0;
5605 char *ip = NULL, *src_ip = NULL;
5606 char *invalid_args_msg = NULL;
5607 sds cmdfmt = NULL;
5608 if (!getClusterHostFromCmdArgs(argc, argv, &ip, &port)) {
5609 invalid_args_msg = CLUSTER_MANAGER_INVALID_HOST_ARG;
5610 goto invalid_args;
5611 }
5612 if (config.cluster_manager_command.from == NULL) {
5613 invalid_args_msg = "[ERR] Option '--cluster-from' is required for "
5614 "subcommand 'import'.\n";
5615 goto invalid_args;
5616 }
5617 char *src_host[] = {config.cluster_manager_command.from};
5618 if (!getClusterHostFromCmdArgs(1, src_host, &src_ip, &src_port)) {
5619 invalid_args_msg = "[ERR] Invalid --cluster-from host. You need to "
5620 "pass a valid address (ie. 120.0.0.1:7000).\n";
5621 goto invalid_args;
5622 }
5623 clusterManagerLogInfo(">>> Importing data from %s:%d to cluster %s:%d\n",
5624 src_ip, src_port, ip, port);
5625
5626 clusterManagerNode *refnode = clusterManagerNewNode(ip, port);
5627 if (!clusterManagerLoadInfoFromNode(refnode, 0)) return 0;
5628 if (!clusterManagerCheckCluster(0)) return 0;
5629 char *reply_err = NULL;
5630 redisReply *src_reply = NULL;
5631 // Connect to the source node.
5632 struct timeval tv;
5633 tv.tv_sec = config.cluster_manager_command.timeout / 1000;
5634 tv.tv_usec = (config.cluster_manager_command.timeout % 1000) * 1000;
5635 redisContext *src_ctx = redisConnectWithTimeout(src_ip, src_port, tv);
5636 if (src_ctx->err) {
5637 success = 0;
5638 fprintf(stderr,"Could not connect to KeyDB at %s:%d: %s.\n", src_ip,
5639 src_port, src_ctx->errstr);
5640 goto cleanup;
5641 }
5642 // Auth for the source node.
5643 char *from_user = config.cluster_manager_command.from_user;
5644 char *from_pass = config.cluster_manager_command.from_pass;
5645 if (cliAuth(src_ctx, from_user, from_pass) == REDIS_ERR) {
5646 success = 0;
5647 goto cleanup;
5648 }
5649
5650 src_reply = reconnectingRedisCommand(src_ctx, "INFO");
5651 if (!src_reply || src_reply->type == REDIS_REPLY_ERROR) {
5652 if (src_reply && src_reply->str) reply_err = src_reply->str;
5653 success = 0;
5654 goto cleanup;
5655 }
5656 if (getLongInfoField(src_reply->str, "cluster_enabled")) {
5657 clusterManagerLogErr("[ERR] The source node should not be a "
5658 "cluster node.\n");
5659 success = 0;

Callers

nothing calls this directly

Calls 15

clusterManagerNewNodeFunction · 0.85
redisConnectWithTimeoutFunction · 0.85
cliAuthFunction · 0.85
reconnectingRedisCommandFunction · 0.85
getLongInfoFieldFunction · 0.85
freeReplyObjectFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
sdsnewFunction · 0.85

Tested by

no test coverage detected