Durability: acknowledged data can be lost after power loss, and a damaged manifest can make recovery delete every segment
I maintainer di solito rispondono entro 1 giorno
@zhourrr ci sta già lavorando.
Dal 29/9/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Summary
We use zvec as an embedded store and audited its persistence path (collection, segment, WAL, version manager, RocksDB contexts) at main (98aa126). We found that there is currently no way for a caller to know that a write will survive power loss. We also found cases where a crash or a full disk can lead recovery to delete data that was already safely on disk.
Process crashes (kill -9) are mostly handled well, and #768 fixes most of the remaining WAL-recovery windows. The remaining problems are about the order of operations around checkpoints and manifests, and about fsync.
The failing tests are in #788, a PR into #760's branch that reuses #760's harness. We'd be glad to help implement the fix below.
Findings
-
A checkpoint deletes the WAL before the replacement data is on disk.
SegmentImpl::flush(explicitflush(), block rotation, segment rollover,close(), iterators, DDL) fsyncs the WAL, then writes forward blocks, vector index files, the delete snapshot and a new manifest without fsync, then removes the WAL and the old manifest. After a power loss, data acknowledged long before can be missing, or the collection may not open. -
The manifest write is not atomic and has no checksum, and a damaged manifest makes recovery delete segments. The manifest is written in place to its final name through
ofstream, and the implicit close/flush of the stream is never checked. A manifest cut at a field boundary (including 0 bytes) still decodes as valid. On the next writable open, orphan cleanup removes every segment the damaged manifest doesn't list, and then crashes with SIGSEGV.-
manifest_codec.cc#L949-L993;collection.cc#L2107,collection.cc#L2172-L2253 -
Reproduced on 8321c131; master and #768 have the same code on this path. The collection has 2600 docs in segments 0, 1 and 2.
-
0-byte newest manifest (power loss before the data reached disk): a writable open logs "Recovery removed orphan segment directory" for 0, 1 and 2, then crashes. Only
idmap.0/,del.0,LOCKand the empty manifest remain, and every later open crashes. A read-only open crashes but deletes nothing. -
Other truncation lengths: of all 439 possible lengths, the five cuts that fall on a field boundary all crash. Three of them delete every segment and two delete some. Cut 437 opens "complete" with
next_segment_id = 0. -
Disk full during
flush()(HFS+ 30 MiB image, manifest about 10 KiB). The bytes beyond the last 4 KiB boundary are written only when the stream is destroyed, and that write is unchecked.- With 48 KiB free,
flush()returns "Failed to serialize manifest to file" but leaves an emptymanifest.4next to the validmanifest.3. The next writable open deletes segments 0 and 1 and crashes. If the process closes afterwards,close()returns OK and leaves more empty manifests behind. - With 52 KiB free,
flush()returns OK, but the old manifest is unlinked and the new one is cut at 8192 bytes. The collection can no longer be opened.
- With 48 KiB free,
This turns a disk-full or power-loss event into data loss. The orphan cleanup was added in #674 (for #673), and it trusts whatever the newest manifest decodes to.
-
-
Optimize and DDL retire the old segments and index files before the replacement is durable.
-
No write is ever fsynced before it is acknowledged.
-
The WAL fsync interval (
WalOptions.max_docs_wal_flush) is always 0, and no public option exposes it. -
When it is set, a failed fsync is only logged, and
appendstill returns success (local_wal_file.cc#L41-L49). -
The README and the Python
flush()docstring promise durability that the code doesn't provide.
-
-
Platform barriers.
- On macOS,
fsyncdoes not flush the drive cache;F_FULLFSYNCdoes. - mmap-backed index files are flushed with
msync(MS_ASYNC), and the result is ignored. - Directories are never fsynced after create, rename or unlink.
- On macOS,
-
Swallowed errors in the persistence path. Examples:
zvec_collection_closealways returnsZVEC_OK;IDMap::removeignores its status;- segment close discards its flush and close errors;
- forward-store close hides writer-close failures;
- index seal errors are overwritten by later results.
-
From code reading; not yet covered by #788 or confirmed by tests.
- The RocksDB-backed idmap and indexes run with their WAL disabled (
rocksdb_context.cc#L93,rocksdb_context.cc#L199), but they can be flushed ahead of the zvec WAL: an auto memtable flush, the idmap destructor after a failed checkpoint, or a crash between the idmap flush and the manifest save (segment.cc#L2216-L2252). Replay then works from a map that is ahead of the WAL. An upsert can delete the version it is rebuilding, and because doc ids are reused, a lookup by key can return a different document. #768's predecessor-aware replay addresses part of this. Id fencing (never reusing a doc id that a durable index may still reference) would close it. - Rows deleted before a failed checkpoint can reappear after the checkpoint is retried.
- A segment rollover can split its state across two manifests.
delete_by_filtercan leave the key mapped in the idmap, so a later insert of the same key fails.
We'll add tests for these if they are useful to you.
- The RocksDB-backed idmap and indexes run with their WAL disabled (
Proposed fix: one small durability API; everything else is internal
A. Crash-safe checkpoints for everyone, with no API change
- Each writer fsyncs the files it owns: forward block, vector index and delete snapshot. RocksDB is flushed through its owner. The new directories are then fsynced.
- The manifest is published atomically: write
manifest.N.tmp, check close, fsync, rename, fsync the directory. It carries a checksum. - Only after publication are the WAL, the old manifest and the old files retired. Optimize and DDL follow the same retire-after-publish order.
- Recovery picks the newest manifest that validates. Orphan cleanup runs only after that, and never deletes a directory that still holds a WAL. If no complete manifest exists, open fails closed and deletes nothing.
- Add
F_FULLFSYNCon Apple, a directory-fsync helper, and checkedmsync(MS_SYNC)and close. Errors are propagated rather than logged.
Result: flush() returning OK really means that every earlier write survives power loss, which matches the existing documentation.
B. A group-committed WAL barrier: Collection::sync_wal() (C++, C API, Python)
sync_wal()returns OK only when every write that returned before the call is on disk. It fsyncs the WAL, and the WAL's directory entry when the WAL is new, and returns any fsync error to the caller.- It runs outside the write lock, and one fsync covers every caller waiting on it (group commit). Applications that batch writes (several
upsertcalls per logical transaction) pay one fsync per transaction, not one per call, and can release their own locks before waiting. - After an fsync failure, the collection refuses further writes until it is reopened. A later barrier must never report success over data the failed fsync dropped.
- Optional convenience: a
sync_writescollection option that calls the barrier after every write call, for applications that want per-call durability without managing barriers. - The default write path stays exactly as fast as today.
Suggested README wording:
By default, writes survive a process crash, and data flushed with
flush()survives power loss. Callsync_wal()when writes made so far must survive power loss; it is cheap and shared across concurrent callers.
Expected cost:
- The default write path: no change.
- Each checkpoint: a few extra fsyncs and one rename.
sync_wal(): one fsync per call, shared by concurrent callers, and zero when nothing new has been written since the last barrier.
Tests
The tests in #788 extend #760's harness. They fail on main today and should pass with the fix:
- a truncated or empty manifest on reopen, which must not delete data;
- ENOSPC while writing the manifest;
- kill -9 after a write that triggers block rotation, which #768 fixes;
- a power-loss simulation. A test-only syscall shim records exactly what each fsync made durable, including RocksDB's and Arrow's own syncs, and builds the post-crash image with unsynced renames and unlinks both applied and not applied. It covers "after
flush()returns" and later rotation, rollover and optimize. - #760's dm-log-writes block replay extended with rotation, index create/drop and optimize workloads, cut at the durable point;
- fsync failure injection.
Suggested order
- #768, rebased onto main after #759.
- The tests, into #760.
- Durability primitives and error propagation.
- Atomic manifest and safe recovery.
- Crash-safe checkpoint, optimize and DDL.
sync_wal()with group commit.
We can open PRs for steps 3-6 in this order if that works for you, and we'd welcome guidance on how you'd like them split.
- Lingua principale
- C++
- Stelle
- 16.3k
- Fork
- 1k
- Merge medio
- 2g 10h
- PR unite (30g)
- 32
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di alibaba/zvec
-
[Feature]: IVF_TIEREDQ index type, with a learned variable-bit codec (25–44% less index memory than `IVF_RABITQ` at equal recall)Forse già presa @richyreachy l’ha presa 7 giorni fa. Apertafeature
alibaba/zvec#909 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Support an opt-in portable x86 FastPFOR build without SSE4.1Forse già presa @egolearner l’ha presa 20 giorni fa. Aperta
alibaba/zvec#875 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Enhance]: Reduce vector index block fragmentation caused by frequent flushesForse già presa @feihongxu0824 l’ha presa 22 giorni fa. Apertaenhancement
alibaba/zvec#869 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Performance]:High-selectivity range filter materializes a full bitmap — `bitset_set_list` ~49% CPU, dwarfing the ANN searchForse già presa @zhourrr l’ha presa 22 giorni fa. Apertaenhancement
alibaba/zvec#868 · 13 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Performance] Warm-query latency on small collections with query() and query_internal_ids() in v0.8.0Forse di nuovo libera @egolearner l’ha presa 33 giorni fa e non c’è nessuna pull request aperta. Aperta
alibaba/zvec#841 · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di alibaba/zvec
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
deprecation internal refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
realloc(ptr, 0) on glibc leaves the freed block in the capture as a leakForse già presa @ADAMAMZAR l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
bloomberg/memray#1097 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
new-compilers request
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
compiler-explorer/compiler-explorer#9640 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
deepseek-ai/DeepEP#839 ·
I maintainer di solito rispondono entro 6 giorni