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

fix: handle no key commands in slot check #1207

Merged
merged 1 commit into from
May 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/server/main_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -601,28 +601,25 @@ bool Service::CheckKeysOwnership(const CommandId* cid, CmdArgList args,
}

const auto& key_index = *key_index_res;
SlotId keys_slot;
optional<SlotId> keys_slot;
bool cross_slot = false;
// Iterate keys and check to which slot they belong.
for (unsigned i = key_index.start; i < key_index.end; ++i) {
string_view key = ArgS(args, i);
SlotId slot = ClusterConfig::KeySlot(key);
if (i == key_index.start) {
keys_slot = slot;
continue;
}
if (slot != keys_slot) {
// keys belong to diffent slots
cross_slot = true;
if (keys_slot && slot != *keys_slot) {
cross_slot = true; // keys belong to different slots
break;
} else {
keys_slot = slot;
}
}
if (cross_slot) {
(*dfly_cntx)->SendError("-CROSSSLOT Keys in request don't hash to the same slot");
return false;
}
// Check keys slot is in my ownership
if (!server_family_.cluster_config()->IsMySlot(keys_slot)) {
if (keys_slot && !server_family_.cluster_config()->IsMySlot(*keys_slot)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use keys_slot.has_value(), but definitely your call.
Anyway, thanks for making this change!

(*dfly_cntx)->SendError("MOVED"); // TODO add more info to moved error.
return false;
}
Expand Down