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

Function clusterManagerAddSlots

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

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

Source from the content-addressed store, hash-verified

3395
3396/* Flush dirty slots configuration of the node by calling CLUSTER ADDSLOTS */
3397static int clusterManagerAddSlots(clusterManagerNode *node, char**err)
3398{
3399 redisReply *reply = NULL;
3400 void *_reply = NULL;
3401 int success = 1;
3402 /* First two args are used for the command itself. */
3403 int argc = node->slots_count + 2;
3404 sds *argv = zmalloc(argc * sizeof(*argv));
3405 size_t *argvlen = zmalloc(argc * sizeof(*argvlen));
3406 argv[0] = "CLUSTER";
3407 argv[1] = "ADDSLOTS";
3408 argvlen[0] = 7;
3409 argvlen[1] = 8;
3410 *err = NULL;
3411 int i, argv_idx = 2;
3412 for (i = 0; i < CLUSTER_MANAGER_SLOTS; i++) {
3413 if (argv_idx >= argc) break;
3414 if (node->slots[i]) {
3415 argv[argv_idx] = sdsfromlonglong((long long) i);
3416 argvlen[argv_idx] = sdslen(argv[argv_idx]);
3417 argv_idx++;
3418 }
3419 }
3420 if (!argv_idx) {
3421 success = 0;
3422 goto cleanup;
3423 }
3424 redisAppendCommandArgv(node->context,argc,(const char**)argv,argvlen);
3425 if (redisGetReply(node->context, &_reply) != REDIS_OK) {
3426 success = 0;
3427 goto cleanup;
3428 }
3429 reply = (redisReply*) _reply;
3430 success = clusterManagerCheckRedisReply(node, reply, err);
3431cleanup:
3432 zfree(argvlen);
3433 if (argv != NULL) {
3434 for (i = 2; i < argc; i++) sdsfree(argv[i]);
3435 zfree(argv);
3436 }
3437 if (reply != NULL) freeReplyObject(reply);
3438 return success;
3439}
3440
3441/* Get the node the slot is assigned to from the point of view of node *n.
3442 * 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
sdsfreeFunction · 0.85
freeReplyObjectFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected