Skip to content

Commit

Permalink
Remove support for splitting multi-key commands per slot (valkey-io#23)
Browse files Browse the repository at this point in the history
- Remove support for command splitting in cluster API
  Since old days (from hiredis-vip) there has been support for sending
  some commands that contains multiple keys, but which covers multiple
  slots. The client would split a command into multiple commands and send
  to each node handling each slot.
  This is unnecessary complex, so lets remove it in this early stage.

- Refactor function that prepares cluster commands    
  Rename and remove unnecessary checks in the internal function
  `command_format_by_slot()`.

Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv authored Jun 28, 2024
1 parent a84615c commit 899ac88
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 835 deletions.
57 changes: 0 additions & 57 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,42 +140,6 @@ cmddef *valkey_lookup_cmd(const char *arg0, uint32_t arg0_len, const char *arg1,
return NULL;
}

/*
* Return true, if the valkey command is a vector command accepting one or
* more keys, otherwise return false
* Format: command key [ key ... ]
*/
static int valkey_argx(struct cmd *r) {
switch (r->type) {
case CMD_REQ_VALKEY_EXISTS:
case CMD_REQ_VALKEY_MGET:
case CMD_REQ_VALKEY_DEL:
return 1;

default:
break;
}

return 0;
}

/*
* Return true, if the valkey command is a vector command accepting one or
* more key-value pairs, otherwise return false
* Format: command key value [ key value ... ]
*/
static int valkey_argkvx(struct cmd *r) {
switch (r->type) {
case CMD_REQ_VALKEY_MSET:
return 1;

default:
break;
}

return 0;
}

/* Parses a bulk string starting at 'p' and ending somewhere before 'end'.
* Returns the remaining of the input after consuming the bulk string. The
* pointers *str and *len are pointed to the parsed string and its length. On
Expand Down Expand Up @@ -357,22 +321,6 @@ void valkey_parse_cmd(struct cmd *r) {
if (!push_keypos(r, arg, arglen))
goto oom;

/* Special commands where we want all keys (not only the first key). */
if (valkey_argx(r) || valkey_argkvx(r)) {
/* argx: MGET key [ key ... ] */
/* argkvx: MSET key value [ key value ... ] */
if (valkey_argkvx(r) && rnarg % 2 == 0)
goto error;
for (uint32_t i = 2; i < rnarg; i++) {
if ((p = valkey_parse_bulk(p, end, &arg, &arglen)) == NULL)
goto error;
if (valkey_argkvx(r) && i % 2 == 0)
continue; /* not a key */
if (!push_keypos(r, arg, arglen))
goto oom;
}
}

done:
ASSERT(r->type > CMD_UNKNOWN && r->type < CMD_SENTINEL);
r->result = CMD_PARSE_OK;
Expand Down Expand Up @@ -428,7 +376,6 @@ struct cmd *command_get(void) {
command->slot_num = -1;
command->frag_seq = NULL;
command->reply = NULL;
command->sub_commands = NULL;
command->node_addr = NULL;

command->keys = vkarray_create(1, sizeof(struct keypos));
Expand Down Expand Up @@ -468,10 +415,6 @@ void command_destroy(struct cmd *command) {

freeReplyObject(command->reply);

if (command->sub_commands != NULL) {
listRelease(command->sub_commands);
}

if (command->node_addr != NULL) {
sdsfree(command->node_addr);
command->node_addr = NULL;
Expand Down
6 changes: 1 addition & 5 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,13 @@ struct cmd {
/* Command destination */
int slot_num; /* Command should be sent to slot.
* Set to -1 if command is sent to a given node,
* or if a slot can not be found or calculated,
* or if its a multi-key command cross different
* nodes (cross slot) */
* or if a slot can not be found or calculated. */
char *node_addr; /* Command sent to this node address */

struct cmd *
*frag_seq; /* sequence of fragment command, map from keys to fragments*/

valkeyReply *reply;

hilist *sub_commands; /* just for pipeline and multi-key commands */
};

void valkey_parse_cmd(struct cmd *r);
Expand Down
Loading

0 comments on commit 899ac88

Please sign in to comment.