1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

fix(cluster): Fix CROSSSLOTS error with multi-key operations (#1488)

Fixes #1487
This commit is contained in:
Shahar Mike 2023-06-28 13:16:50 +03:00 committed by GitHub
parent bf363661e4
commit 3ebfdb1e19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View file

@ -733,6 +733,40 @@ TEST_F(ClusterFamilyTest, Keyslot) {
CheckedInt({"cluster", "keyslot", "123{def}456"}));
}
TEST_F(ClusterFamilyTest, ClusterCrossSlot) {
string config_template = R"json(
[
{
"slot_ranges": [
{
"start": 0,
"end": 16383
}
],
"master": {
"id": "$0",
"ip": "10.0.0.1",
"port": 7000
},
"replicas": []
}
])json";
string config = absl::Substitute(config_template, RunAdmin({"dflycluster", "myid"}).GetString());
EXPECT_EQ(RunAdmin({"dflycluster", "config", config}), "OK");
EXPECT_EQ(Run({"SET", "key", "value"}), "OK");
EXPECT_EQ(Run({"GET", "key"}), "value");
EXPECT_EQ(Run({"MSET", "key", "value2"}), "OK");
EXPECT_EQ(Run({"MGET", "key"}), "value2");
EXPECT_THAT(Run({"MSET", "key", "value", "key2", "value2"}), ErrArg("CROSSSLOT"));
EXPECT_THAT(Run({"MGET", "key", "key2"}), ErrArg("CROSSSLOT"));
EXPECT_EQ(Run({"MSET", "key{tag}", "value", "key2{tag}", "value2"}), "OK");
EXPECT_THAT(Run({"MGET", "key{tag}", "key2{tag}"}), RespArray(ElementsAre("value", "value2")));
}
class ClusterFamilyEmulatedTest : public BaseFamilyTest {
public:
ClusterFamilyEmulatedTest() {

View file

@ -611,7 +611,7 @@ bool Service::CheckKeysOwnership(const CommandId* cid, CmdArgList args,
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) {
for (unsigned i = key_index.start; i < key_index.end; i += key_index.step) {
string_view key = ArgS(args, i);
SlotId slot = ClusterConfig::KeySlot(key);
if (keys_slot && slot != *keys_slot) {