Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove parsing of unused cluster slot information #25

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions include/valkey/valkeycluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
135 changes: 0 additions & 135 deletions src/valkeycluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading