[Bug]: Index seal can lose errors and keep an incomplete range index, so range queries miss documents
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
Description
When a segment seals, InvertedIndexer::seal() seals each inverted column, then flushes and compacts. A column seal (InvertedColumnIndexer::seal()) builds the range index and value histogram of a range-optimized field, then writes the column's "sealed" marker. I found four defects on this path. Each one is reproduced below on 98aa126 with tests only. Three of them can make range queries (<, <=, >, >=) silently return too few documents, and two together can crash the process after a single I/O error. They share one code path, so I report them together.
1. A column seal error is logged and then lost. The loop logs a failed column seal and goes on. flush() and compact() then overwrite s, so seal() returns OK:
InvertedIndexer::flush() in the same file returns on a column error. From code reading, SegmentImpl::dump() then finishes the seal as if it had succeeded, so nothing retries the failed column. Finding 6 of #789 mentions this from code reading. The tests below confirm it.
2. The seal marker can reach disk before the range index it describes. The indexes write without a WAL, so data becomes durable only when its column family is flushed. RocksdbContext::flush_unlocked() flushes the families in the order of cf_handles_:
create() puts the default family, which holds the sealed markers, last. A writable open() of an existing instance lists the families in RocksDB's order, with the default family first:
So an index that was opened in this process, not created in it, flushes the marker before the $RANGES and $CDF families. One example is the writing segment's scalar index after a restart (from code reading). A large range index is also partly flushed while the seal builds it, whenever its memtable fills. A crash after the default family's flush therefore keeps the marker and only part of the range index. After a reopen, the column is sealed, and range queries skip every term after the last surviving range:
A later seal() skips the column because it is already sealed, so the wrong results stay.
3. reset_cf() keeps a deleted handle when the re-create fails. It deletes the old handle after DropColumnFamily() succeeds. It stores the new handle only if CreateColumnFamily() succeeds:
If the create fails, for example because a MANIFEST sync fails, cf_handles_ keeps the deleted pointer. The next flush() or close() uses it. drop_cf() removes the handle from cf_handles_ when it deletes it. generate_statistical_indexes() starts with reset_cf(). Because of defect 1, InvertedIndexer::seal() continues into flush() after the failed reset. So one failed sync during a seal crashes the process.
4. The term scan treats a read error as the end of the terms. generate_statistical_indexes() loops while iter_term->Valid() and never checks iter_term->status():
A read error in the middle of the term table ends the scan. The seal then builds the range index from the terms it has read, writes the marker and returns OK. If the error was transient, the following compaction succeeds, and nothing reports the error. The FTS indexer checks status() after its scan (fts_column_indexer.cc, line 769).
Steps to Reproduce
All runs use 98aa126 with test files only and no source change. main (7f54d94) has the same code in these files. The index has one INT32 field seq with InvertIndexParams(true), and seq = document id unless noted. The tests inject faults through a rocksdb::FileSystemWrapper that they set as the RocksDB env before the index opens. To reach the indexer's private context, the test file uses a test-only access override. Crash tests kill a child process with SIGKILL from a rocksdb::EventListener.
- Column seal error. Create an index with two fields, insert 5,000 documents, flush and close. Put a value with header byte
0xffunder the term ofseq = 0. Reopen the index and callInvertedIndexer::seal().- Expected:
seal()returns the column error. - Actual:
seal()returns OK. Columnseqis not sealed, and columncycis sealed.
- Expected:
- Marker before the range index. Insert 4,500,000 documents with
seq = id * 7919 mod 4,500,000, which is a field unrelated to insertion order, then flush and close. A child process reopens the index writable and callsInvertedIndexer::seal(). Its handle order isdefault seq$TERMS seq$RANGES $CDF. A listener kills the child right after the default family's flush is installed. The parent then reopens the index. All RocksDB options are zvec's defaults.- Expected: a sealed column has its whole range index, and range queries return the exact count.
- Actual: column
seqis sealed, but only 768 of its 1,000 range entries are on disk. The test checks<,<=,>and>=at 41 values, and 82 of these 164 range queries are wrong. For example,seq >= 0returns 3,456,000 of 4,500,000 documents.seal()then returns OK and the answers stay wrong. - The same happens with 200,000 documents and a 64 KB range memtable: 998 of 1,000 entries survive, and 82 of 164 queries are wrong.
- Control: an index created in the same process flushes the default family last.
- Failed re-create. Create a
RocksdbContextwith a familyr. Fail the second MANIFEST sync after arming the fault (the first one is the drop's), then callreset_cf("r").- Actual:
reset_cf()returns an error, andcf_handles_still holds the deleted handle.close()then crashes with SIGSEGV. - Through the seal: insert 5,000 documents, reopen the index and inject the same fault.
InvertedIndexer::seal()logs the two errors below and then crashes with SIGSEGV inrocksdb::DBImpl::Flush(const FlushOptions&, ColumnFamilyHandle*).
- Actual:
- Read error in the term scan. Insert 100,000 documents, flush and close. This leaves one term table with 1,749,069 bytes of data blocks. Reopen the index. While
InvertedColumnIndexer::seal()runs, fail every read that covers the middle byte of that table. One read failed.- Expected: the column seal fails and writes no marker.
- Actual: the column seal returns OK, and only 499 of 1,000 range entries are written. 40 of 164 range queries are wrong. For example,
seq > 14999returns 34,841 documents instead of 85,000. InvertedIndexer::seal()then returns OK, because its compaction reads the table without the fault. The wrong answers remain after a reopen.- Control without the fault: 1,000 entries, and 0 of 164 queries wrong.
Logs / Stack Trace
# 1
[ERROR inverted_column_indexer_write.cc:343] Failed to deserialize bitmap for term[...] from InvertedColumnIndexer[collection:repro|field:seq|...]
[ERROR inverted_column_indexer_write.cc:449] Failed to generate statistical indexes in InvertedColumnIndexer[collection:repro|field:seq|...]
[ERROR inverted_indexer.cc:134] Failed to seal InvertedColumnIndexer[collection:repro|field:seq|...]
InvertedIndexer::seal() -> OK
# 3, through the seal
[ERROR rocksdb_context.cc:525] Failed to create cf[seq$RANGES] in RocksDB[...], code[5], reason[IO error: injected MANIFEST sync failure]
[ERROR inverted_indexer.cc:134] Failed to seal InvertedColumnIndexer[collection:repro|field:seq|...]
stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
frame #0: rocksdb::DBImpl::Flush(rocksdb::FlushOptions const&, rocksdb::ColumnFamilyHandle*) + 64
Operating System
macOS 27 (arm64). The code paths are platform independent. Linux was not run.
Build & Runtime Environment
Apple clang, CMake Release build of 98aa126, RocksDB 8.1.1 from the submodule.
Additional Context
PR #809 fixes the four defects, with one commit and one regression test each:
InvertedIndexer::seal()returns the first column error, asflush()does. It prepares every column before it marks any of them sealed, so a failed seal leaves no column read-only.- The seal markers are written only after the data they describe is flushed. Flushing the default family last would order only the explicit flush. An automatic flush of a full default memtable during the seal could still go first.
- When the drop succeeded and the create failed,
reset_cf()removes the handle fromcf_handles_, asdrop_cf()does. - The seal fails if
iter_term->status()is not OK after the scan, or ifSeekToLast()finds no term.
With fixes 1 and 3, the failed MANIFEST sync makes the seal return an error instead of crashing.
SegmentImpl also ignores the result of column_indexer->seal() in two places (segment.cc lines 3254 and 3406, from code reading). The PR leaves them unchanged, because the segment meta is already updated there and returning the error needs a decision on how to roll it back.
Related: #798 and PR #803 replace the reset_cf() calls in the seal with an in-place clear, and they keep reset_cf() only as a fallback for an unreadable range family. With #803 applied, defects 1, 2 and 4 reproduce unchanged. Defect 3 is then reachable from the seal only through that fallback. The PR and #803 merge without conflicts.
- 主要语言
- C++
- 星标
- 16.3k
- 派生
- 1k
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 32
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
alibaba/zvec 的其他 Issue
-
[Feature]: IVF_TIEREDQ index type, with a learned variable-bit codec (25–44% less index memory than `IVF_RABITQ` at equal recall)可能已有人在做 @richyreachy 于 7 天前认领。 未关闭feature
维护者通常 1 天内回复
-
Support an opt-in portable x86 FastPFOR build without SSE4.1可能已有人在做 @egolearner 于 20 天前认领。 未关闭
alibaba/zvec#875 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[Enhance]: Reduce vector index block fragmentation caused by frequent flushes可能已有人在做 @feihongxu0824 于 22 天前认领。 未关闭enhancement
维护者通常 1 天内回复
-
[Performance]:High-selectivity range filter materializes a full bitmap — `bitset_set_list` ~49% CPU, dwarfing the ANN search可能已有人在做 @zhourrr 于 22 天前认领。 未关闭enhancement
alibaba/zvec#868 · 13 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[Performance] Warm-query latency on small collections with query() and query_internal_ids() in v0.8.0可能重新可做 @egolearner 于 33 天前认领,目前没有进行中的 PR。 未关闭
维护者通常 1 天内回复
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 72/100
-
deprecation internal refactor
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
realloc(ptr, 0) on glibc leaves the freed block in the capture as a leak可能已有人在做 @ADAMAMZAR 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
bloomberg/memray#1097 · 2 条评论 ·
维护者通常 1 天内回复
-
new-compilers request
难度 2/5 1-3 小时 新手友好度 65/100
compiler-explorer/compiler-explorer#9640 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
deepseek-ai/DeepEP#839 ·
维护者通常 6 天内回复