fix(fts): allow global doc id gaps during compaction (#588)

This commit is contained in:
egolearner
2026-07-13 10:54:30 +08:00
committed by GitHub
parent 78ef197aaa
commit 4de76fdbde
5 changed files with 93 additions and 13 deletions
@@ -132,12 +132,14 @@ Result<void> FtsRocksdbReducer::feed(
return {};
}
// Require consecutive global doc_id ranges between non-empty segments so
// the shared delete_row_id_bitmap stays aligned with input scan order.
// Global doc_id gaps are valid after deleted documents have been removed
// during compaction. Only require ordered, non-overlapping ranges; the
// shared delete bitmap is aligned by feed-order scan position and doc_count.
if (!segment_stats_.empty() &&
segment_stats.min_doc_id != segment_stats_.back().max_doc_id + 1) {
segment_stats.min_doc_id <= segment_stats_.back().max_doc_id) {
return tl::make_unexpected(Status::InternalError(
"FtsRocksdbReducer: segments not in consecutive doc_id order. field=",
"FtsRocksdbReducer: segments have overlapping or unordered doc_id "
"ranges. field=",
field_name_));
}
@@ -52,7 +52,9 @@ class FtsRocksdbReducer {
Result<void> cleanup();
/*! Feed a source segment to be merged.
* Segments must be fed in consecutive doc_id order.
* Segments must be fed in ascending, non-overlapping global doc_id order.
* Gaps between global doc_id ranges are allowed because deleted documents
* may already have been removed by an earlier compaction.
* \param segment_stats Stats of the source segment (min/max doc_id)
* \param src_ctx RocksdbContext owning the source CFs
* \param src_postings_cf Source postings CF (must be BitPacked)
+2 -2
View File
@@ -37,8 +37,8 @@ struct FtsQueryParams {
};
/*! Per-segment statistics needed by the FTS reducer for doc_id remapping.
* - min_doc_id / max_doc_id: GLOBAL doc_id range used by the delete filter
* (filter.is_filtered() takes a global doc_id).
* - min_doc_id / max_doc_id: GLOBAL doc_id range used to order segments and
* reject overlapping inputs. Gaps are valid after compaction deletes.
* - doc_count: number of FTS LOCAL doc_ids in the source segment; the posting
* list domain is [0, doc_count). For fresh (non-merged) segments this
* equals max_doc_id - min_doc_id + 1, and the local-to-global mapping is