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

Function clusterManagerAddSlots

src/redis-cli.c:3008–3050  ·  view source on GitHub ↗

Flush dirty slots configuration of the node by calling CLUSTER ADDSLOTS */

Source from the content-addressed store, hash-verified

3006
3007/* Flush dirty slots configuration of the node by calling CLUSTER ADDSLOTS */
3008static int clusterManagerAddSlots(clusterManagerNode *node, char**err)
3009{
3010 redisReply *reply = NULL;
3011 void *_reply = NULL;
3012 int success = 1;
3013 /* First two args are used for the command itself. */
3014 int argc = node->slots_count + 2;
3015 sds *argv = zmalloc(argc * sizeof(*argv), MALLOC_LOCAL);
3016 size_t *argvlen = zmalloc(argc * sizeof(*argvlen), MALLOC_LOCAL);
3017 argv[0] = "CLUSTER";
3018 argv[1] = "ADDSLOTS";
3019 argvlen[0] = 7;
3020 argvlen[1] = 8;
3021 *err = NULL;
3022 int i, argv_idx = 2;
3023 for (i = 0; i < CLUSTER_MANAGER_SLOTS; i++) {
3024 if (argv_idx >= argc) break;
3025 if (node->slots[i]) {
3026 argv[argv_idx] = sdsfromlonglong((long long) i);
3027 argvlen[argv_idx] = sdslen(argv[argv_idx]);
3028 argv_idx++;
3029 }
3030 }
3031 if (!argv_idx) {
3032 success = 0;
3033 goto cleanup;
3034 }
3035 redisAppendCommandArgv(node->context,argc,(const char**)argv,argvlen);
3036 if (redisGetReply(node->context, &_reply) != REDIS_OK) {
3037 success = 0;
3038 goto cleanup;
3039 }
3040 reply = (redisReply*) _reply;
3041 success = clusterManagerCheckRedisReply(node, reply, err);
3042cleanup:
3043 zfree(argvlen);
3044 if (argv != NULL) {
3045 for (i = 2; i < argc; i++) sdsfree(argv[i]);
3046 zfree(argv);
3047 }
3048 if (reply != NULL) freeReplyObject(reply);
3049 return success;
3050}
3051
3052/* Get the node the slot is assigned to from the point of view of node *n.
3053 * If the slot is unassigned or if the reply is an error, return NULL.

Callers 1

Calls 9

zmallocFunction · 0.85
sdsfromlonglongFunction · 0.85
sdslenFunction · 0.85
redisAppendCommandArgvFunction · 0.85
redisGetReplyFunction · 0.85
zfreeFunction · 0.85
sdsfreeFunction · 0.85
freeReplyObjectFunction · 0.85

Tested by

no test coverage detected