Repository navigation
perf(query): use owning forward views for sealed IPC - #905
Conversation
3b51fac to
f959ad9
Compare
5a76ab2 to
b5e162d
Compare
d54c599 to
22fa6bb
Compare
|
Could we simplify this by preparing an immutable forward-read state during segment open/seal, and updating it during column DDL under the existing lifecycle synchronization? Queries would only capture the published state and compose their column projections. With that structure,
The key requirement is to finish preparation before publishing a segment as sealed, and coordinate replacement with DDL/close. Shared ownership of Arrow buffers can remain, allowing existing views to retain their data after replacement. Query preparation may still need a short shared lock to capture the state. This could start as an internal |
f9e704d to
2fa1ec3
Compare
fixed:
Points that differ from the suggestion
|
Reuse immutable, zero-copy forward columns across query projections so sealed IPC candidate filtering avoids per-candidate segment locks. Read global document IDs through owned columns while retaining live deletion bitmap checks. Keep writing segments and unsupported storage on live locked fetch. Invalidate column catalogs with segment lifecycle changes and cover buffer lifetime, independent chunk layouts, schema changes and concurrent captures.
…ilures Preparing the sealed read state at open/seal turned several failures that the lazy catalog used to absorb into hard errors. Make preparation an optimization again: on failure the segment serves forward reads through locked fetch. - DDL: add/alter/drop_column republish the state on every return through a scope guard. A failure partway through no longer leaves a sealed segment without a state, which made every filtered query on it fail until reopen. - Reload: reload_vector/scalar/fts_index no longer abort when the state cannot be prepared, so the new indexers are always installed with the new meta. - Open: an inconsistent block no longer makes Segment::Open fail. - prepare_forward_read distinguishes a closed segment (explicit closed_ flag) from a missing state instead of inferring closure from it. - Rollover: validate the version before sealing, destroy the new writing segment on failure, and make the sequence retryable. dump() no longer takes a defaulted virtual parameter; resume_dump() accepts a segment that was already dumped, whether or not its writing block was removed. - reload_scalar_index recomputes block offsets before its early returns, so they always match the new meta. - Log how long each state preparation takes.
Keep the best-effort read state from the previous commit and drop changes that are not needed for it. - Rollover: restore switch_to_new_segment_for_writing() and the void remove_writing_forward_block() from main. Publishing the read state can no longer fail, so sealing has no new error path, and queries cannot observe the order of add_segment() and sealing because the whole switch holds the exclusive write_mtx_. resume_dump() is removed. - Sealing: remove the writing block, then publish, under one exclusive seg_mtx_. The `sealing` flag that previewed the post-seal state is gone. - Split the read state into a const build_persisted_read_state() and publish_persisted_read_state(), which handles failures and logs. - Rename PersistedReadState::sealed to owning_views; it was easy to confuse with SegmentImpl::sealed_ (dumped). - Share the locked-fetch Arrow field construction between fetch_unsafe() and prepare_forward_read() so their schemas cannot diverge. - Shorten the Segment interface comments. No behavior change for queries, DDL, reload or open.
cc3bcab to
28d11b3
Compare
This PR removes the per-candidate segment lock from single-stage forward filtering on sealed IPC segments. Opening or sealing a segment prepares immutable, zero-copy forward columns. Each query captures the published state under a shared lock and projects the columns its predicate needs.
Changes and scope
Performance
The following warmed-query measurements were taken at
d54c599a, before moving metadata construction to open/seal. A is this revision with view eligibility disabled, retaining locked fetch and the existing deletion lookup; B is the unmodified PR. Both used the same index and build dependencies and returned identical ordered results and scores. A is a same-revision control, not an upstream-main build.Linux x86: Xeon Platinum 8369B under KVM, GCC 11.4 Release; clients bound to distinct physical cores on one NUMA node, query pool=8. One 1M-row sealed segment; 62-dimensional HNSW/COSINE/INT8, M=16, ef_construction=200; query ef=300, topk=21, ~50% predicate selectivity, forced single-stage filtering. The deletion case has 10% tombstones without rebuilding the index.
Median end-to-end QPS improvement across five alternating-order, warmed runs:
At 8 clients without deletions, QPS is 546.0 → 638.6 and p99 is 15.94 → 13.66 ms. Runs vary substantially: QPS ranges are 504.2–625.5 for A and 486.1–721.8 for B. Both variants scale about 3.26× from 1 to 8 clients. With 10% tombstones, 8-client throughput is effectively unchanged. The unfiltered negative control differs by less than 1% at every client count.
An unpinned Apple M5 Pro run measured larger 8-client gains: 2.08× without deletions and 1.78× with tombstones. The benefit is platform-dependent; the Linux measurements do not establish improved parallel scaling.
Validation
On macOS arm64, the Release build at
2fa1ec3bpassed 168 tests covering segment storage, column DDL, forward filtering and concurrent reads. Three regressions for concurrent projections, DDL and retirement also passed 10 repetitions each. clang-format and clang-tidy passed.