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

Function clusterManagerCommandCall

src/redis-cli.c:5760–5802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5758}
5759
5760static int clusterManagerCommandCall(int argc, char **argv) {
5761 int port = 0, i;
5762 char *ip = NULL;
5763 if (!getClusterHostFromCmdArgs(1, argv, &ip, &port)) goto invalid_args;
5764 clusterManagerNode *refnode = clusterManagerNewNode(ip, port);
5765 if (!clusterManagerLoadInfoFromNode(refnode, 0)) return 0;
5766 argc--;
5767 argv++;
5768 size_t *argvlen = zmalloc(argc*sizeof(size_t), MALLOC_LOCAL);
5769 clusterManagerLogInfo(">>> Calling");
5770 for (i = 0; i < argc; i++) {
5771 argvlen[i] = strlen(argv[i]);
5772 printf(" %s", argv[i]);
5773 }
5774 printf("\n");
5775 listIter li;
5776 listNode *ln;
5777 listRewind(cluster_manager.nodes, &li);
5778 while ((ln = listNext(&li)) != NULL) {
5779 clusterManagerNode *n = ln->value;
5780 if ((config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_MASTERS_ONLY)
5781 && (n->replicate != NULL)) continue; // continue if node is slave
5782 if ((config.cluster_manager_command.flags & CLUSTER_MANAGER_CMD_FLAG_SLAVES_ONLY)
5783 && (n->replicate == NULL)) continue; // continue if node is master
5784 if (!n->context && !clusterManagerNodeConnect(n)) continue;
5785 redisReply *reply = NULL;
5786 redisAppendCommandArgv(n->context, argc, (const char **) argv, argvlen);
5787 int status = redisGetReply(n->context, (void **)(&reply));
5788 if (status != REDIS_OK || reply == NULL )
5789 printf("%s:%d: Failed!\n", n->ip, n->port);
5790 else {
5791 sds formatted_reply = cliFormatReplyRaw(reply);
5792 printf("%s:%d: %s\n", n->ip, n->port, (char *) formatted_reply);
5793 sdsfree(formatted_reply);
5794 }
5795 if (reply != NULL) freeReplyObject(reply);
5796 }
5797 zfree(argvlen);
5798 return 1;
5799invalid_args:
5800 fprintf(stderr, CLUSTER_MANAGER_INVALID_HOST_ARG);
5801 return 0;
5802}
5803
5804static int clusterManagerCommandBackup(int argc, char **argv) {
5805 UNUSED(argc);

Callers

nothing calls this directly

Calls 13

clusterManagerNewNodeFunction · 0.85
zmallocFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
redisAppendCommandArgvFunction · 0.85
redisGetReplyFunction · 0.85
cliFormatReplyRawFunction · 0.85
sdsfreeFunction · 0.85
freeReplyObjectFunction · 0.85

Tested by

no test coverage detected