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

Function clusterManagerMigrateKeysInSlot

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

Migrate all keys in the given slot from source to target.*/

Source from the content-addressed store, hash-verified

3754
3755/* Migrate all keys in the given slot from source to target.*/
3756static int clusterManagerMigrateKeysInSlot(clusterManagerNode *source,
3757 clusterManagerNode *target,
3758 int slot, int timeout,
3759 int pipeline, int verbose,
3760 char **err)
3761{
3762 int success = 1;
3763 int do_fix = config.cluster_manager_command.flags &
3764 CLUSTER_MANAGER_CMD_FLAG_FIX;
3765 int do_replace = config.cluster_manager_command.flags &
3766 CLUSTER_MANAGER_CMD_FLAG_REPLACE;
3767 while (1) {
3768 char *dots = NULL;
3769 redisReply *reply = NULL, *migrate_reply = NULL;
3770 reply = CLUSTER_MANAGER_COMMAND(source, "CLUSTER "
3771 "GETKEYSINSLOT %d %d", slot,
3772 pipeline);
3773 success = (reply != NULL);
3774 if (!success) return 0;
3775 if (reply->type == REDIS_REPLY_ERROR) {
3776 success = 0;
3777 if (err != NULL) {
3778 *err = zmalloc((reply->len + 1) * sizeof(char));
3779 strcpy(*err, reply->str);
3780 CLUSTER_MANAGER_PRINT_REPLY_ERROR(source, *err);
3781 }
3782 goto next;
3783 }
3784 assert(reply->type == REDIS_REPLY_ARRAY);
3785 size_t count = reply->elements;
3786 if (count == 0) {
3787 freeReplyObject(reply);
3788 break;
3789 }
3790 if (verbose) dots = zmalloc((count+1) * sizeof(char));
3791 /* Calling MIGRATE command. */
3792 migrate_reply = clusterManagerMigrateKeysInReply(source, target,
3793 reply, 0, timeout,
3794 dots);
3795 if (migrate_reply == NULL) goto next;
3796 if (migrate_reply->type == REDIS_REPLY_ERROR) {
3797 int is_busy = strstr(migrate_reply->str, "BUSYKEY") != NULL;
3798 int not_served = 0;
3799 if (!is_busy) {
3800 /* Check if the slot is unassigned (not served) in the
3801 * source node's configuration. */
3802 char *get_owner_err = NULL;
3803 clusterManagerNode *served_by =
3804 clusterManagerGetSlotOwner(source, slot, &get_owner_err);
3805 if (!served_by) {
3806 if (get_owner_err == NULL) not_served = 1;
3807 else {
3808 CLUSTER_MANAGER_PRINT_REPLY_ERROR(source,
3809 get_owner_err);
3810 zfree(get_owner_err);
3811 }
3812 }
3813 }

Callers 1

clusterManagerMoveSlotFunction · 0.85

Calls 13

zmallocFunction · 0.85
freeReplyObjectFunction · 0.85
strstrFunction · 0.85
clusterManagerSetSlotFunction · 0.85
listCreateFunction · 0.85
listReleaseFunction · 0.85
listRewindFunction · 0.85
listNextFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected