Skip to content

Commit 7842c87

Browse files
fix(search_family): Fix empty key bug (#5264)
Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>
1 parent e8ba42e commit 7842c87

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/server/search/doc_index.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ std::optional<ShardDocIndex::DocId> ShardDocIndex::DocKeyIndex::Remove(string_vi
223223

224224
string_view ShardDocIndex::DocKeyIndex::Get(DocId id) const {
225225
DCHECK_LT(id, keys_.size());
226-
DCHECK_GT(keys_[id].size(), 0u);
226+
// Check that this id was not removed
227+
DCHECK(id < last_id_ && std::find(free_ids_.begin(), free_ids_.end(), id) == free_ids_.end());
227228

228229
return keys_[id];
229230
}

src/server/search/search_family_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,4 +2881,14 @@ TEST_F(SearchFamilyTest, SearchStatsInfoRace) {
28812881
ASSERT_FALSE(service_->IsShardSetLocked());
28822882
}
28832883

2884+
TEST_F(SearchFamilyTest, EmptyKeyBug) {
2885+
auto resp = Run({"FT.CREATE", "index", "ON", "HASH", "SCHEMA", "field", "TEXT"});
2886+
EXPECT_THAT(resp, "OK");
2887+
2888+
resp = Run({"HSET", "", "field", "value"});
2889+
EXPECT_THAT(resp, IntArg(1));
2890+
2891+
resp = Run({"FT.SEARCH", "index", "*"});
2892+
EXPECT_THAT(resp, AreDocIds(""));
2893+
}
28842894
} // namespace dfly

0 commit comments

Comments
 (0)