[Bug]: Index seal can lose errors and keep an incomplete range index, so range queries miss documents
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- C++
- Star
- 16.3k
- Fork
- 1k
- Merge trung bình
- 2 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 32
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của alibaba/zvec
-
[Feature]: IVF_TIEREDQ index type, with a learned variable-bit codec (25–44% less index memory than `IVF_RABITQ` at equal recall)Có thể đã có người làm @richyreachy đã nhận 7 ngày trước. Đang mởfeature
alibaba/zvec#909 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support an opt-in portable x86 FastPFOR build without SSE4.1Có thể đã có người làm @egolearner đã nhận 20 ngày trước. Đang mở
alibaba/zvec#875 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Enhance]: Reduce vector index block fragmentation caused by frequent flushesCó thể đã có người làm @feihongxu0824 đã nhận 22 ngày trước. Đang mởenhancement
alibaba/zvec#869 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Performance]:High-selectivity range filter materializes a full bitmap — `bitset_set_list` ~49% CPU, dwarfing the ANN searchCó thể đã có người làm @zhourrr đã nhận 22 ngày trước. Đang mởenhancement
alibaba/zvec#868 · 13 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Performance] Warm-query latency on small collections with query() and query_internal_ids() in v0.8.0Có thể làm lại được @egolearner đã nhận 33 ngày trước và không có pull request nào đang mở. Đang mở
alibaba/zvec#841 · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
deprecation internal refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
realloc(ptr, 0) on glibc leaves the freed block in the capture as a leakCó thể đã có người làm @ADAMAMZAR đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
bloomberg/memray#1097 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
new-compilers request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
compiler-explorer/compiler-explorer#9640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
deepseek-ai/DeepEP#839 ·
Maintainer thường phản hồi trong vòng 6 ngày