fix: RENAME in cluster mode crash (#4995)

fixed: https://github.com/dragonflydb/dragonfly/issues/4993
This commit is contained in:
Volodymyr Yavdoshenko 2025-04-28 11:45:05 +03:00 committed by GitHub
parent 0f415acb81
commit aa7e8abcb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View file

@ -870,6 +870,9 @@ OpResult<void> OpRen(const OpArgs& op_args, string_view from_key, string_view to
is_prior_list = (to_res.it->second.ObjType() == OBJ_LIST);
}
// Delete the "from" document from the search index before deleting from the database
op_args.shard->search_indices()->RemoveDoc(from_key, op_args.db_cntx, from_res.it->second);
bool sticky = from_res.it->first.IsSticky();
uint64_t exp_ts = db_slice.ExpireTime(from_res.exp_it);

View file

@ -2722,4 +2722,23 @@ TEST_F(SearchFamilyTest, JsonWithNullFields) {
AreDocIds("doc:1", "doc:2"));
}
TEST_F(SearchFamilyTest, RenameDocumentBetweenIndices) {
absl::FlagSaver fs;
SetTestFlag("cluster_mode", "emulated");
ResetService();
EXPECT_EQ(Run({"ft.create", "idx1", "prefix", "1", "idx1", "filter", "@index==\"yes\"", "schema",
"t", "text"}),
"OK");
EXPECT_EQ(Run({"ft.create", "idx2", "prefix", "1", "idx2", "filter", "@index==\"yes\"", "schema",
"t", "text"}),
"OK");
Run({"hset", "idx1:{doc}1", "t", "foo1", "index", "yes"});
EXPECT_EQ(Run({"rename", "idx1:{doc}1", "idx2:{doc}1"}), "OK");
EXPECT_EQ(Run({"rename", "idx2:{doc}1", "idx1:{doc}1"}), "OK");
}
} // namespace dfly