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

Allow multi-slot MGET in Cluster Mode #707

Open
wants to merge 4 commits into
base: unstable
Choose a base branch
from
Open
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
31 changes: 25 additions & 6 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ getNodeByQuery(client *c, struct serverCommand *cmd, robj **argv, int argc, int
clusterNode *n = NULL;
robj *firstkey = NULL;
int multiple_keys = 0;
int multi_slot = 0;
multiState *ms, _ms;
multiCmd mc;
int i, slot = 0, migrating_slot = 0, importing_slot = 0, missing_keys = 0, existing_keys = 0;
Expand Down Expand Up @@ -1080,12 +1081,26 @@ getNodeByQuery(client *c, struct serverCommand *cmd, robj **argv, int argc, int
}
} else {
/* If it is not the first key/channel, make sure it is exactly
* the same key/channel as the first we saw. */
* the same key/channel as the first we saw or an allowed crossslot situation. */
int prevent_crossslot =
(cmd_flags & CMD_WRITE) // eliminate issues with client->current_slot
|| pubsubshard_included // pubsub does not benefit and too many edge cases
|| c->cmd->proc == execCommand // We do not permit crossslot transactions to prevent client code
// which will break when cluster topology changes
// finally, if any key is migrating we cannot permit the crossslot since we don't check if the
// specific keys are affected
// this could potentially be relaxed in the future.
|| migrating_slot || importing_slot || getMigratingSlotDest(thisslot) != NULL ||
getImportingSlotSource(thisslot) != NULL || n != getNodeBySlot(thisslot);
if (slot != thisslot) {
/* Error: multiple keys from different slots. */
getKeysFreeResult(&result);
if (error_code) *error_code = CLUSTER_REDIR_CROSS_SLOT;
return NULL;
if (prevent_crossslot) {
/* Error: multiple keys from different slots. */
getKeysFreeResult(&result);
if (error_code) *error_code = CLUSTER_REDIR_CROSS_SLOT;
return NULL;
} else {
multi_slot = 1;
}
}
if (importing_slot && !multiple_keys && !equalStringObjects(firstkey, thiskey)) {
/* Flag this request as one with multiple different
Expand Down Expand Up @@ -1140,7 +1155,11 @@ getNodeByQuery(client *c, struct serverCommand *cmd, robj **argv, int argc, int
}

/* Return the hashslot by reference. */
if (hashslot) *hashslot = slot;
if (hashslot) {
// If we have multiple slots we disable slot caching on the client
// In the future perhaps this optimization could be extended to work with multiple keys
*hashslot = multi_slot ? -1 : slot;
}

/* MIGRATE always works in the context of the local node if the slot
* is open (migrating or importing state). We need to be able to freely
Expand Down
3 changes: 2 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -5646,7 +5646,8 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) {
"executable:%s\r\n", server.executable ? server.executable : "",
"config_file:%s\r\n", server.configfile ? server.configfile : "",
"io_threads_active:%i\r\n", server.active_io_threads_num > 1,
"availability_zone:%s\r\n", server.availability_zone));
"availability_zone:%s\r\n", server.availability_zone,
"features:%s\r\n", "cluster_mget"));

/* Conditional properties */
if (isShutdownInitiated()) {
Expand Down
Loading