Repository navigation
api: a no-match by-query run must not flush the index (#1222) - #1227
Merged
Merged
Conversation
Corrected root cause, superseding the idle-flush fingerprint theory in the issue: the fingerprint loop is already dead (Index::flush clears the idle-probe pair at entry, with the PR #878 regression test for exactly the write->age->flush->same-shape-write sequence), and the node evidence rules the idle path out entirely — the corpus-builder node runs flush_idle_secs = 0, a single write under that config provably sits in the memtable (reproduced: 47 s, zero segments), and the 1-doc segment storm continued anyway. The real mechanism: run_delete_by_query flushes the member index FIRST, unconditionally, before it even parses the query (#1019: _id-keyset paging is only correct over on-disk segments). A delete whose query matches nothing still pays that flush, and the corpus apply loop fires one defensive no-match delete per group op — #1224's cve-records build issued 402,744 of them. Per op: bulk writes 1 doc (per-file group), the next op's delete flushes it straight back out into a 1-doc segment (~121 files on the cvelistV5 dynamic mapping) which the merge scheduler then rewrites. That is the measured "6,848 one-doc segments for ~3,005 writes" — a flush per write with no idle path involved. It also reframes most of #1226: the 5-16 s delete_by_query/_refresh latencies are this flush (segment write + fsync + merge contention), not a refresh-specific bottleneck. Fix (server-side twin of the client gate in #1225): probe first with a size:0 search through the ordinary search path — active memtable plus segments, so a matching doc that was never flushed still counts and the run proceeds to the flush arm exactly as before. Zero matches returns the zero response (total 0 / batches 0 — the same shape both arms below already return for a no-match run over a flushed index) without flushing. A probe error propagates; a script resource limit during the probe refuses the whole run, matching the fail-closed per-batch check. Applied to _update_by_query's runner too (identical shape). _reindex's flush-first is left as is: it is not in the apply loop's path. Tests (fail-before verified by forcing the gate to always report a match: the new no-match test fails with the memtable drained — the exact production behavior): - no_match_by_query_does_not_flush: a no-match delete AND update leave the just-written document in the memtable. - matching_delete_by_query_still_flushes_and_purges: an unflushed matching doc is visible to the probe, takes the flush arm, is purged; the non-matching doc survives. Live A/B on a throwaway node: PUT 1 doc -> 0 segments; no-match delete -> 0 segments (old binary: 1-doc segment, 121 files); matching delete -> total 1 / deleted 1 / doc gone. Crate suite: xerj-api 811 passed / 0 failed. ES-YAML gate on this branch: see PR. Files: - crates/xerj-api/src/es_compat.rs: by_query_matches_anything gate + call sites in run_delete_by_query / run_update_by_query + tests
This was referenced Oct 7, 2026
Merged
Merged
thomas-villani
pushed a commit
to thomas-villani/xerj
that referenced
this pull request
Oct 9, 2026
Workspace version + Cargo.lock (17 member entries). Release window: xerj-org#1219, xerj-org#1223, xerj-org#1225, xerj-org#1227, xerj-org#1228.
thomas-villani
pushed a commit
to thomas-villani/xerj
that referenced
this pull request
Oct 9, 2026
Window: xerj-org#1219 (Vinz2168 field report, closes the xerj-org#1091 tracker it diagnoses), xerj-org#1223 (kNN exact-scan capture bracket, xerj-org#1220), xerj-org#1227 (no-match by-query must not flush, xerj-org#1222), xerj-org#1225 (visibility probe gates the per-group delete), xerj-org#1228 (O(1) journal state writes, the xerj-org#1224 client-CPU leg). Release-notes gate: PASS locally (release-notes-gate.sh against origin/main) after the gate itself caught the xerj-org#1224 claims-it-whole drift in the first draft - the entry now says the tracker closes on the completed re-measure, not on the legs.
thomas-villani
pushed a commit
to thomas-villani/xerj
that referenced
this pull request
Oct 9, 2026
- xerj-org#1220 closed by xerj-org#1223, xerj-org#1222 closed by xerj-org#1227, xerj-org#1091 closed by the xerj-org#1219 field report: moved to the closed-inside-window record (all three verified closed live before de-linking). - xerj-org#1226 added OPEN: the 5-16s refresh/by-query latencies, reframed by xerj-org#1227 (the no-match flush the callers of which are now gone) - what remains is the flush cost itself under concurrent bulk load. - Count eleven -> ten, all verified open live.
neoneye
pushed a commit
to agent-memory-atlas-archive/xerj-org--xerj
that referenced
this pull request
Oct 10, 2026
xerj-org#1224's original report measured ~0.66 s of client CPU per file during cve-records apply. The client no-op delete gate (xerj-org#1225) and the server-side no-flush gate (xerj-org#1227) removed the delete_by_query storm, but the re-measure still ran at 1.18 items/s with the client pinning one core in pure user time (82% of a core, 0 kernel ticks) at 5.7 GB RSS. The original per-file CPU claim was right for a reason nothing had profiled yet: the parked delete stacks of the first gdb probe masked it. Root cause: Journal::sync_operation_state runs twice per replayed operation (Started + Committed), and each call cloned the ENTIRE PendingSync - desired GenerationManifest with all 402,695 groups, the 402,744-entry operations Vec, and the growing operation_states map - before appending one small durable line. Two full deep clones per file, plus three more quadratics hiding behind them: - PendingSync::apply_operation_state validated membership with a linear operations.iter().any() per state event, both live and again on every journal load-replay (2 events per operation). - EsSyncBackend::apply_shared resolved each operation's group with base/desired groups.iter().find() over every group, per operation. - replay_prepared resolved each content_id with a linear scan of the snapshot's 402k files, per upsert. Fix, all client-side, event format and semantics unchanged: - sync_operation_state: validate (pure) -> durable append -> record in place. The journal line is the transaction boundary; a crash between append and record loses nothing because load replay rebuilds the map from the file, and a failed append returns before any mutation, the same guarantee the clone-on-write provided. - PendingSync carries a lazily-built, never-serialized OperationIdIndex (HashSet + len guard) so membership is O(1); apply_operation_state is now validate+record so load replay shares the fast path. - EsSyncBackend builds a ReplayLookup (group_id and content_id to position maps for base, desired and snapshot) once per replay_operations call. Hits are verified against the slice they answer from and length-guarded, so a stale or absent cache falls back to the exact scan it replaces. Pattern reference (approach, not code): redb's InMemoryState - the durable structure is the truth, in-memory state is a derived cache updated after the durable commit and rebuilt on load (redb src/tree_store/page_store/page_manager.rs:252, Apache-2.0/MIT). Measured, cve-records (402,695 files, 1.9 GB prepared) against the isolated rc.89-gate node on :19285: apply phase 1.18 items/s before this change (0.72 s client CPU per file); after-numbers land on xerj-org#1224 as the resumed run reaches the apply phase. Tests: operation_state_split_semantics_and_membership_index_hold pins the validate/record split, the pre-split transition rules, the clone-carried index, and the len guard against stale-shape answers. Full xerj-autoindex lib suite 1299 passed / 0 failed. Files: - engine/crates/xerj-autoindex/src/state.rs :: sync_operation_state - engine/crates/xerj-autoindex/src/sync.rs :: PendingSync, OperationIdIndex, validate/record_operation_state - engine/crates/xerj-autoindex/src/sync_executor.rs :: ReplayLookup, EsSyncBackend::{apply_shared, replay_prepared, replay_metadata, replay_operations}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
run_delete_by_queryandrun_update_by_queryflush the member index FIRST, unconditionally — the #1019 paging precondition (_id-keyset paging is only correct over on-disk segments). A run whose query matches nothing still paid that flush. This PR gates it: asize:0probe through the ordinary search path (active memtable + segments) runs first; zero matches returns the zero response without flushing. A matching doc that was never flushed still counts and takes the flush arm exactly as before. Probe errors propagate; a script resource limit during the probe refuses the run, matching the fail-closed per-batch check.Corrected root cause of the #1222 segment storm
The issue blames the #873 idle-flush fingerprint loop. That mechanism is already dead —
Index::flush()clears the idle-probe pair at entry (with the PR #878 regression test for exactly the write→age→flush→same-shape-write sequence) — and the node evidence rules the idle path out entirely: the corpus-builder node runsflush_idle_secs = 0, a single write under that config provably sits in the memtable (reproduced: 47 s, zero segments), and the 1-doc segment storm continued anyway.The real mechanism is this PR's target. The corpus apply loop fires one defensive no-match
delete_by_queryper group op (#1224: 402,744 of them on cve-records). Per op: bulk writes 1 doc (per-file group), the next op's delete flushes it straight back out into a 1-doc segment (~121 files on the cvelistV5 dynamic mapping), which the merge scheduler then rewrites. That is the measured "6,848 one-doc segments for ~3,005 writes" — a flush per write with no idle path involved. Full corrected diagnosis posted on the issue.This also reframes most of #1226: the 5–16 s
delete_by_query/_refreshlatencies are this flush (segment write + fsync + merge contention under concurrent ops), not a refresh-specific bottleneck.Verification
refresh=false:total 1 / deleted 1 / batches 1, doc goneno_match_by_query_does_not_flush(delete + update twins) andmatching_delete_by_query_still_flushes_and_purgesines_compat.rs.Server-side twin of the client gate merged in #1225 (which stops our own client from sending the no-op deletes; this makes the server tolerate any ES-native client that still does).
_reindex's flush-first is left unchanged — not in the apply loop's path.Refs #1222 (segment-storm half), #1224 (server half), #1226 (likely explains most of the measured refresh cost).