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

Rename and remove deprecated functions in the cluster API #38

Merged
merged 3 commits into from
Sep 3, 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
26 changes: 8 additions & 18 deletions include/valkey/valkeycluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
extern "C" {
#endif

struct dict;
struct hilist;
struct valkeyClusterAsyncContext;

Expand Down Expand Up @@ -172,10 +171,6 @@ void valkeyClusterFree(valkeyClusterContext *cc);
/* Configuration options */
int valkeyClusterSetOptionAddNode(valkeyClusterContext *cc, const char *addr);
int valkeyClusterSetOptionAddNodes(valkeyClusterContext *cc, const char *addrs);
/* Deprecated function, option has no effect. */
int valkeyClusterSetOptionConnectBlock(valkeyClusterContext *cc);
/* Deprecated function, option has no effect. */
int valkeyClusterSetOptionConnectNonBlock(valkeyClusterContext *cc);
int valkeyClusterSetOptionUsername(valkeyClusterContext *cc,
const char *username);
int valkeyClusterSetOptionPassword(valkeyClusterContext *cc,
Expand All @@ -188,9 +183,6 @@ int valkeyClusterSetOptionTimeout(valkeyClusterContext *cc,
const struct timeval tv);
int valkeyClusterSetOptionMaxRetry(valkeyClusterContext *cc,
int max_retry_count);
/* Deprecated function, replaced with valkeyClusterSetOptionMaxRetry() */
void valkeyClusterSetMaxRedirect(valkeyClusterContext *cc,
int max_redirect_count);
/* A hook for connect and reconnect attempts, e.g. for applying additional
* socket options. This is called just after connect, before TLS handshake and
* Valkey authentication.
Expand Down Expand Up @@ -267,13 +259,10 @@ void valkeyClusterReset(valkeyClusterContext *cc);
/* Update the slotmap by querying any node. */
int valkeyClusterUpdateSlotmap(valkeyClusterContext *cc);

/* Internal functions */
valkeyContext *ctx_get_by_node(valkeyClusterContext *cc,
valkeyClusterNode *node);
struct dict *parse_cluster_nodes(valkeyClusterContext *cc, char *str,
int str_len, int flags);
struct dict *parse_cluster_slots(valkeyClusterContext *cc, valkeyReply *reply,
int flags);
/* Get the valkeyContext used for communication with a given node.
* Connects or reconnects to the node if necessary. */
valkeyContext *valkeyClusterGetValkeyContext(valkeyClusterContext *cc,
valkeyClusterNode *node);

/*
* Asynchronous API
Expand Down Expand Up @@ -328,9 +317,10 @@ int valkeyClusterAsyncFormattedCommandToNode(valkeyClusterAsyncContext *acc,
void *privdata, char *cmd,
int len);

/* Internal functions */
valkeyAsyncContext *actx_get_by_node(valkeyClusterAsyncContext *acc,
valkeyClusterNode *node);
/* Get the valkeyAsyncContext used for communication with a given node.
* Connects or reconnects to the node if necessary. */
valkeyAsyncContext *valkeyClusterGetValkeyAsyncContext(valkeyClusterAsyncContext *acc,
valkeyClusterNode *node);

/* Cluster node iterator functions */
void valkeyClusterInitNodeIterator(valkeyClusterNodeIterator *iter,
Expand Down
69 changes: 22 additions & 47 deletions src/valkeycluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ static int cluster_master_slave_mapping_with_name(valkeyClusterContext *cc,
/**
* Parse the "cluster slots" command reply to nodes dict.
*/
dict *parse_cluster_slots(valkeyClusterContext *cc, valkeyReply *reply,
int flags) {
static dict *parse_cluster_slots(valkeyClusterContext *cc, valkeyReply *reply,
int flags) {
int ret;
cluster_slot *slot = NULL;
dict *nodes = NULL;
Expand Down Expand Up @@ -866,8 +866,8 @@ dict *parse_cluster_slots(valkeyClusterContext *cc, valkeyReply *reply,
/**
* Parse the "cluster nodes" command reply to nodes dict.
*/
dict *parse_cluster_nodes(valkeyClusterContext *cc, char *str, int str_len,
int flags) {
static dict *parse_cluster_nodes(valkeyClusterContext *cc, char *str, int str_len,
int flags) {
int ret;
dict *nodes = NULL;
dict *nodes_name = NULL;
Expand Down Expand Up @@ -1601,22 +1601,6 @@ int valkeyClusterSetOptionAddNodes(valkeyClusterContext *cc,
return VALKEY_OK;
}

/* Deprecated function, option has no effect. */
int valkeyClusterSetOptionConnectBlock(valkeyClusterContext *cc) {
if (cc == NULL) {
return VALKEY_ERR;
}
return VALKEY_OK;
}

/* Deprecated function, option has no effect. */
int valkeyClusterSetOptionConnectNonBlock(valkeyClusterContext *cc) {
if (cc == NULL) {
return VALKEY_ERR;
}
return VALKEY_OK;
}

/**
* Configure a username used during authentication, see
* the Valkey AUTH command.
Expand Down Expand Up @@ -1804,8 +1788,8 @@ int valkeyClusterConnect2(valkeyClusterContext *cc) {
return valkeyClusterUpdateSlotmap(cc);
}

valkeyContext *ctx_get_by_node(valkeyClusterContext *cc,
valkeyClusterNode *node) {
valkeyContext *valkeyClusterGetValkeyContext(valkeyClusterContext *cc,
valkeyClusterNode *node) {
valkeyContext *c = NULL;
if (node == NULL) {
return NULL;
Expand Down Expand Up @@ -1917,7 +1901,7 @@ static int valkeyClusterAppendCommandInternal(valkeyClusterContext *cc,
return VALKEY_ERR;
}

c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL) {
return VALKEY_ERR;
} else if (c->err) {
Expand Down Expand Up @@ -2082,7 +2066,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc,
}
}

c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL || c->err) {
/* Failed to connect. Maybe there was a failover and this node is gone.
* Update slotmap to find out. */
Expand All @@ -2094,7 +2078,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc,
if (node == NULL) {
goto error;
}
c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL) {
goto error;
} else if (c->err) {
Expand Down Expand Up @@ -2170,7 +2154,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc,
}
}

c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL) {
goto error;
} else if (c->err) {
Expand All @@ -2190,7 +2174,7 @@ static void *valkey_cluster_command_execute(valkeyClusterContext *cc,
freeReplyObject(reply);
reply = NULL;

c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL) {
goto error;
} else if (c->err) {
Expand Down Expand Up @@ -2275,16 +2259,6 @@ static int prepareCommand(valkeyClusterContext *cc, struct cmd *command) {
return VALKEY_OK;
}

/* Deprecated function, replaced with valkeyClusterSetOptionMaxRetry() */
void valkeyClusterSetMaxRedirect(valkeyClusterContext *cc,
int max_retry_count) {
if (cc == NULL || max_retry_count <= 0) {
return;
}

cc->max_retry_count = max_retry_count;
}

int valkeyClusterSetConnectCallback(valkeyClusterContext *cc,
void(fn)(const valkeyContext *c,
int status)) {
Expand Down Expand Up @@ -2397,7 +2371,7 @@ void *valkeyClustervCommandToNode(valkeyClusterContext *cc,
void *reply;
int updating_slotmap = 0;

c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL) {
return NULL;
} else if (c->err) {
Expand Down Expand Up @@ -2576,7 +2550,7 @@ int valkeyClustervAppendCommandToNode(valkeyClusterContext *cc,
cc->requests->free = listCommandFree;
}

c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL) {
return VALKEY_ERR;
} else if (c->err) {
Expand Down Expand Up @@ -2679,7 +2653,7 @@ static int valkeyClusterSendAll(valkeyClusterContext *cc) {
continue;
}

c = ctx_get_by_node(cc, node);
c = valkeyClusterGetValkeyContext(cc, node);
if (c == NULL) {
continue;
}
Expand Down Expand Up @@ -2906,8 +2880,9 @@ static void unlinkAsyncContextAndNode(void *data) {
}
}

valkeyAsyncContext *actx_get_by_node(valkeyClusterAsyncContext *acc,
valkeyClusterNode *node) {
valkeyAsyncContext *
valkeyClusterGetValkeyAsyncContext(valkeyClusterAsyncContext *acc,
valkeyClusterNode *node) {
valkeyAsyncContext *ac;
int ret;

Expand Down Expand Up @@ -3194,7 +3169,7 @@ static int updateSlotMapAsync(valkeyClusterAsyncContext *acc,
}

/* Get libvalkey context, connect if needed */
ac = actx_get_by_node(acc, node);
ac = valkeyClusterGetValkeyAsyncContext(acc, node);
}
if (ac == NULL)
goto error; /* Specific error already set */
Expand Down Expand Up @@ -3303,7 +3278,7 @@ static void valkeyClusterAsyncCallback(valkeyAsyncContext *ac, void *r,
if (slot >= 0) {
cc->table[slot] = node;
}
ac_retry = actx_get_by_node(acc, node);
ac_retry = valkeyClusterGetValkeyAsyncContext(acc, node);

break;
case CLUSTER_ERR_ASK:
Expand All @@ -3313,7 +3288,7 @@ static void valkeyClusterAsyncCallback(valkeyAsyncContext *ac, void *r,
goto done;
}

ac_retry = actx_get_by_node(acc, node);
ac_retry = valkeyClusterGetValkeyAsyncContext(acc, node);
if (ac_retry == NULL) {
/* Specific error already set */
goto done;
Expand Down Expand Up @@ -3437,7 +3412,7 @@ int valkeyClusterAsyncFormattedCommand(valkeyClusterAsyncContext *acc,
goto error;
}

ac = actx_get_by_node(acc, node);
ac = valkeyClusterGetValkeyAsyncContext(acc, node);
if (ac == NULL) {
/* Specific error already set */
goto error;
Expand Down Expand Up @@ -3489,7 +3464,7 @@ int valkeyClusterAsyncFormattedCommandToNode(valkeyClusterAsyncContext *acc,
return VALKEY_ERR;
}

ac = actx_get_by_node(acc, node);
ac = valkeyClusterGetValkeyAsyncContext(acc, node);
if (ac == NULL) {
/* Specific error already set */
return VALKEY_ERR;
Expand Down
Loading