From d120cf49630311512eac2b52b95b2c8712cd227e Mon Sep 17 00:00:00 2001 From: luzhang Date: Thu, 19 Dec 2024 14:47:13 +0800 Subject: [PATCH] fix:fix delete record assert failed Signed-off-by: luzhang --- internal/core/src/index/TextMatchIndex.cpp | 3 +++ internal/core/src/segcore/DeletedRecord.h | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/core/src/index/TextMatchIndex.cpp b/internal/core/src/index/TextMatchIndex.cpp index 8d3e62a376dab..b3d8e3beee729 100644 --- a/internal/core/src/index/TextMatchIndex.cpp +++ b/internal/core/src/index/TextMatchIndex.cpp @@ -246,6 +246,9 @@ TextMatchIndex::MatchQuery(const std::string& query) { Reload(); } + // The count opeartion of tantivy may be get older cnt if the index is committed with new tantivy segment. + // So we cannot use the count operation to get the total count for bitmap. + // Just use the maximum offset of hits to get the total count for bitmap here. auto hits = wrapper_->match_query(query); auto cnt = should_allocate_bitset_size(hits); TargetBitmap bitset(cnt); diff --git a/internal/core/src/segcore/DeletedRecord.h b/internal/core/src/segcore/DeletedRecord.h index ce2c82eb99fc2..47cca73cda225 100644 --- a/internal/core/src/segcore/DeletedRecord.h +++ b/internal/core/src/segcore/DeletedRecord.h @@ -80,12 +80,11 @@ class DeletedRecord { return; } - InternalPush(pks, timestamps); + auto max_deleted_ts = InternalPush(pks, timestamps); - SortedDeleteList::Accessor accessor(deleted_lists_); - auto* last = accessor.last(); - Assert(last != nullptr); - max_load_timestamp_ = last->first; + if (max_deleted_ts > max_load_timestamp_) { + max_load_timestamp_ = max_deleted_ts; + } //TODO: add support for dump snapshot when load finished } @@ -106,15 +105,19 @@ class DeletedRecord { } } - void + Timestamp InternalPush(const std::vector& pks, const Timestamp* timestamps) { int64_t removed_num = 0; int64_t mem_add = 0; + Timestamp max_timestamp = 0; SortedDeleteList::Accessor accessor(deleted_lists_); for (size_t i = 0; i < pks.size(); ++i) { auto deleted_pk = pks[i]; auto deleted_ts = timestamps[i]; + if (deleted_ts > max_timestamp_) { + max_timestamp = deleted_ts; + } std::vector offsets; if (segment_) { offsets = @@ -151,6 +154,7 @@ class DeletedRecord { n_.fetch_add(removed_num); mem_size_.fetch_add(mem_add); + return max_timestamp; } void