From dcf5617fc5ab7d54e138364e722eaabc1ab8a2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Thu, 13 Jun 2024 10:38:01 +0200 Subject: [PATCH] Remove parsing of unused cluster slot information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently there is no usage of the parsed "importing" and "migrating" information, which is only provided by CLUSTER NODES. Let's remove this superfluous code since we rely on ASK redirections, which will be emitted when a slot is in "migrating" state. Signed-off-by: Björn Svensson --- src/valkeycluster.c | 135 -------------------------------------------- src/valkeycluster.h | 13 ----- 2 files changed, 148 deletions(-) diff --git a/src/valkeycluster.c b/src/valkeycluster.c index 0977a218..6184bdcc 100644 --- a/src/valkeycluster.c +++ b/src/valkeycluster.c @@ -96,7 +96,6 @@ typedef enum CLUSTER_ERR_TYPE { static void freeValkeyClusterNode(valkeyClusterNode *node); static void cluster_slot_destroy(cluster_slot *slot); -static void cluster_open_slot_destroy(copen_slot *oslot); static int updateNodesAndSlotmap(valkeyClusterContext *cc, dict *nodes); static int updateSlotMapAsync(valkeyClusterAsyncContext *acc, valkeyAsyncContext *ac); @@ -279,22 +278,6 @@ static void freeValkeyClusterNode(valkeyClusterNode *node) { if (node->slaves != NULL) { listRelease(node->slaves); } - - copen_slot **oslot; - if (node->migrating) { - while (vkarray_n(node->migrating)) { - oslot = vkarray_pop(node->migrating); - cluster_open_slot_destroy(*oslot); - } - vkarray_destroy(node->migrating); - } - if (node->importing) { - while (vkarray_n(node->importing)) { - oslot = vkarray_pop(node->importing); - cluster_open_slot_destroy(*oslot); - } - vkarray_destroy(node->importing); - } vk_free(node); } @@ -362,37 +345,6 @@ static void cluster_slot_destroy(cluster_slot *slot) { vk_free(slot); } -static copen_slot *cluster_open_slot_create(uint32_t slot_num, int migrate, - sds remote_name, - valkeyClusterNode *node) { - copen_slot *oslot; - - oslot = vk_calloc(1, sizeof(*oslot)); - if (oslot == NULL) { - return NULL; - } - - oslot->slot_num = slot_num; - oslot->migrate = migrate; - oslot->node = node; - oslot->remote_name = sdsdup(remote_name); - if (oslot->remote_name == NULL) { - vk_free(oslot); - return NULL; - } - - return oslot; -} - -static void cluster_open_slot_destroy(copen_slot *oslot) { - oslot->slot_num = 0; - oslot->migrate = 0; - oslot->node = NULL; - sdsfree(oslot->remote_name); - oslot->remote_name = NULL; - vk_free(oslot); -} - /** * Handle password authentication in the synchronous API */ @@ -1031,85 +983,9 @@ dict *parse_cluster_nodes(valkeyClusterContext *cc, char *str, int str_len, } else if (count_slot_start_end == 2) { slot_start = vk_atoi(slot_start_end[0], sdslen(slot_start_end[0])); - ; slot_end = vk_atoi(slot_start_end[1], sdslen(slot_start_end[1])); - ; } else { - // add open slot for master - if (flags & VALKEYCLUSTER_FLAG_ADD_OPENSLOT && - count_slot_start_end == 3 && - sdslen(slot_start_end[0]) > 1 && - sdslen(slot_start_end[1]) == 1 && - sdslen(slot_start_end[2]) > 1 && - slot_start_end[0][0] == '[' && - slot_start_end[2][sdslen(slot_start_end[2]) - 1] == - ']') { - - copen_slot *oslot, **oslot_elem; - - sdsrange(slot_start_end[0], 1, -1); - sdsrange(slot_start_end[2], 0, -2); - - if (slot_start_end[1][0] == '>') { - oslot = cluster_open_slot_create( - vk_atoi(slot_start_end[0], - sdslen(slot_start_end[0])), - 1, slot_start_end[2], master); - if (oslot == NULL) { - __valkeyClusterSetError( - cc, VALKEY_ERR_OTHER, - "create open slot error"); - goto error; - } - - if (master->migrating == NULL) { - master->migrating = - vkarray_create(1, sizeof(oslot)); - if (master->migrating == NULL) { - cluster_open_slot_destroy(oslot); - goto oom; - } - } - - oslot_elem = vkarray_push(master->migrating); - if (oslot_elem == NULL) { - cluster_open_slot_destroy(oslot); - goto oom; - } - - *oslot_elem = oslot; - } else if (slot_start_end[1][0] == '<') { - oslot = cluster_open_slot_create( - vk_atoi(slot_start_end[0], - sdslen(slot_start_end[0])), - 0, slot_start_end[2], master); - if (oslot == NULL) { - __valkeyClusterSetError( - cc, VALKEY_ERR_OTHER, - "create open slot error"); - goto error; - } - - if (master->importing == NULL) { - master->importing = - vkarray_create(1, sizeof(oslot)); - if (master->importing == NULL) { - cluster_open_slot_destroy(oslot); - goto oom; - } - } - - oslot_elem = vkarray_push(master->importing); - if (oslot_elem == NULL) { - cluster_open_slot_destroy(oslot); - goto oom; - } - - *oslot_elem = oslot; - } - } - slot_start = -1; slot_end = -1; } @@ -1837,17 +1713,6 @@ int valkeyClusterSetOptionParseSlaves(valkeyClusterContext *cc) { return VALKEY_OK; } -int valkeyClusterSetOptionParseOpenSlots(valkeyClusterContext *cc) { - - if (cc == NULL) { - return VALKEY_ERR; - } - - cc->flags |= VALKEYCLUSTER_FLAG_ADD_OPENSLOT; - - return VALKEY_OK; -} - int valkeyClusterSetOptionRouteUseSlots(valkeyClusterContext *cc) { if (cc == NULL) { diff --git a/src/valkeycluster.h b/src/valkeycluster.h index e3d40503..0eef6c03 100644 --- a/src/valkeycluster.h +++ b/src/valkeycluster.h @@ -55,9 +55,6 @@ /* Flag to enable parsing of slave nodes. Currently not used, but the information is added to its master node structure. */ #define VALKEYCLUSTER_FLAG_ADD_SLAVE 0x1000 -/* Flag to enable parsing of importing/migrating slots for master nodes. - * Only applicable when 'cluster nodes' command is used for route updates. */ -#define VALKEYCLUSTER_FLAG_ADD_OPENSLOT 0x2000 /* Flag to enable routing table updates using the command 'cluster slots'. * Default is the 'cluster nodes' command. */ #define VALKEYCLUSTER_FLAG_ROUTE_USE_SLOTS 0x4000 @@ -92,8 +89,6 @@ typedef struct valkeyClusterNode { int64_t lastConnectionAttempt; /* Timestamp */ struct hilist *slots; struct hilist *slaves; - struct vkarray *migrating; /* copen_slot[] */ - struct vkarray *importing; /* copen_slot[] */ } valkeyClusterNode; typedef struct cluster_slot { @@ -102,13 +97,6 @@ typedef struct cluster_slot { valkeyClusterNode *node; /* master that this slot region belong to */ } cluster_slot; -typedef struct copen_slot { - uint32_t slot_num; /* slot number */ - int migrate; /* migrating or importing? */ - sds remote_name; /* name of node this slot migrating to/importing from */ - valkeyClusterNode *node; /* master that this slot belong to */ -} copen_slot; - /* Context for accessing a Valkey Cluster */ typedef struct valkeyClusterContext { int err; /* Error flags, 0 when there is no error */ @@ -195,7 +183,6 @@ int valkeyClusterSetOptionUsername(valkeyClusterContext *cc, int valkeyClusterSetOptionPassword(valkeyClusterContext *cc, const char *password); int valkeyClusterSetOptionParseSlaves(valkeyClusterContext *cc); -int valkeyClusterSetOptionParseOpenSlots(valkeyClusterContext *cc); int valkeyClusterSetOptionRouteUseSlots(valkeyClusterContext *cc); int valkeyClusterSetOptionConnectTimeout(valkeyClusterContext *cc, const struct timeval tv);