[Enhance]: Creating a RocksDB instance syncs every step, although nothing references the instance until the manifest is published
Maintainer thường phản hồi trong vòng 1 ngày
@zhourrr đang làm issue này rồi.
Từ ngày 21/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Affected Component
RocksdbContext::create() in src/db/common/rocksdb_context.cc. It creates every new RocksDB instance: the id map at collection create, the scalar index and FTS instances of each new segment (collection create, every segment rollover), and the instances that index builds and compactions create.
Current Behavior
create() opens a new RocksDB directory and adds its column families:
While it runs, RocksDB syncs the MANIFEST once per column family, and CURRENT, IDENTITY, OPTIONS and the directory several times. On macOS each of these syncs is an F_FULLFSYNC, about 7 ms on our machine (Apple M1 Max, APFS). #799 (PR #802) removes the per-family OPTIONS rewrites, but the MANIFEST and directory syncs remain.
These syncs protect nothing. A new instance becomes reachable only when zvec publishes the collection manifest that names it: a rollover publishes the new segment after creating it, and an index build publishes the new block after building it. Until then, nothing reads the directory, and a crash at any point leaves the directory unreferenced.
Desired Improvement
Skip RocksDB's syncs while create() runs, and make the finished instance durable once before create() returns:
- A
rocksdb::FileSystemWrapper, passed as theEnvof the create options, wraps writable files and directories. ItsSync,Fsync,RangeSyncand directoryFsyncreturn OK without syncing while a thread-local flag is set. The flag is set only on the thread that runscreate(), and only while it runs. Other threads,open()and every later write sync as today. - Before
create()returns, it fsyncs every file in the new directory, then syncs the directory once (F_FULLFSYNCon macOS,fsyncelsewhere). Aftercreate()returns, the instance is as durable as today. - A failed
create()closes the instance and removes the directory it made.create()already requires that the path does not exist, so nothing else is in it. - Windows keeps the current behaviour.
The patch is about 200 lines in rocksdb_context.cc. We have tests for it (CreateFailureLeavesNothing, which fails without the change because the directory is left, and CreatedInstanceIsCompleteAfterReopen). We ran them on our build, whose rocksdb_context.cc is identical to upstream's, not on a plain upstream build.
What changes for crashes. A process crash (kill -9) during create() leaves the same files as today, because a skipped sync writes nothing. An OS crash or power loss during create() is different:
- Today, the directory holds a consistent RocksDB instance that may lack some column families.
- With this change, the directory may hold RocksDB files whose contents were only partly written to disk, which RocksDB may refuse to open.
In both cases no published manifest names the directory, so zvec never opens it. But its name stays taken, and the next create() at that path fails, as in #801. So this change depends on recovery removing unreferenced directories on a writable open:
- a new segment that was never published: already removed by the orphan cleanup of #674;
- an index directory inside a published segment: removed by the fix proposed for #801 (
scalar.index.<id>.rocksdb,fts.<id>.rocksdband their.tmpcheckpoint names that the manifest does not reference); - the id map of a collection whose first manifest was never published: in our build such a collection cannot be opened today either (not re-checked on plain upstream).
This change does not touch the publish itself. Whether a published manifest and the directories it names survive a power loss is the subject of #789, and this change neither improves nor weakens that.
Alternative considered: build under a temporary name and rename it. It gives the same guarantee and needs the same cleanup for the temporary names. RocksDB cannot rename an open instance, so each create would need a close, a rename, a parent directory sync and a read-write reopen, which costs more syncs than it saves.
Impact
Faster collection create and segment rollover, mostly on macOS. Measured on macOS arm64 with F_FULLFSYNC, on a build that also carries unrelated local patches:
- Creating 62 collections with 2,311 column families in total: 32.6 s with one
CreateColumnFamilies()call per instance (#802) alone, and 3.8 s with this change as well. - Creating the new segment at a rollover, in a collection with 137 column families and #802 applied: 1.26 s before, 0.03 to 0.05 s with this change.
On Linux, fsync is much cheaper than F_FULLFSYNC, so the gain there is smaller. We have not measured it.
We would open a PR only after #801 is resolved, because this change relies on its cleanup. We are glad to adjust the approach, for example to limit the deferral to the instances that segments and index builds create.
- 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