[Bug]: Index seal can lose errors and keep an incomplete range index, so range queries miss documents
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
- Lenguaje dominante
- C++
- Estrellas
- 16.3k
- Forks
- 1k
- Merge medio
- 2 d 10 h
- PR fusionados (30 d)
- 32
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de alibaba/zvec
-
[Feature]: IVF_TIEREDQ index type, with a learned variable-bit codec (25–44% less index memory than `IVF_RABITQ` at equal recall)Posiblemente ocupada @richyreachy la tomó hace 7 días. Abiertofeature
alibaba/zvec#909 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Support an opt-in portable x86 FastPFOR build without SSE4.1Posiblemente ocupada @egolearner la tomó hace 20 días. Abierto
alibaba/zvec#875 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Enhance]: Reduce vector index block fragmentation caused by frequent flushesPosiblemente ocupada @feihongxu0824 la tomó hace 22 días. Abiertoenhancement
alibaba/zvec#869 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Performance]:High-selectivity range filter materializes a full bitmap — `bitset_set_list` ~49% CPU, dwarfing the ANN searchPosiblemente ocupada @zhourrr la tomó hace 22 días. Abiertoenhancement
alibaba/zvec#868 · 13 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[Performance] Warm-query latency on small collections with query() and query_internal_ids() in v0.8.0Quizá libre de nuevo @egolearner la tomó hace 33 días y no hay ningún pull request abierto. Abierto
alibaba/zvec#841 · 2 asignados ·
Los mantenedores suelen responder en 1 día
Todos los issues de alibaba/zvec
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
deepseek-ai/DeepEP#839 ·
Los mantenedores suelen responder en 6 días
-
multilabel_margin_loss returns an unwritten scalar for an empty CPU batch with reduction='sum'Abiertobot-triaged module: correctness (silent) module: cpu module: empty tensor module: loss triage review
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
stephenberry/glaze#3126 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ultravideo/kvazaar#453 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
google-ai-edge/LiteRT-LM#4783 ·
Los mantenedores suelen responder en 1 día