Repository navigation
fix(#9857, #9858): replicated vectors reach every node's search; vector search skips concurrently deleted candidates - #9900
Conversation
…or search skips candidates a concurrent commit deleted #9857: a page applied from another node (Raft follower, or a follower's own commit on the leader) moved only the vector location index. It now does what a local put()/remove() does to the in-memory search state: a never-seen id is queued in the delta buffer, a tombstone over a live id leaves the buffer and the search cache, both count as mutations, the graph turns MUTABLE and the inactivity rebuild is armed - all under the index write lock, like put(). This node's own WAL replayed at open only rebuilds the locations: the first search reconciles the persisted graph against the pages, and counting there too would charge the tombstones twice (#7842). #9858: db.index.vector.queryNodes and the native select().nearestTo() loaded every candidate and let a RecordNotFoundException escape when a concurrent commit had deleted one. Both now skip a stale candidate and widen the search until they have k live rows, through VectorUtils.searchWithStaleTopUp, now shared with vector.neighbors and vector.sparseNeighbors (#9368, #9692). Also: select().fromType(T).nearestTo() searched the buckets of every sibling of T when T inherits its index from a parent, answering with records of other types. It is now scoped to T's buckets (polymorphic or not), as vectorNeighbors('T[p]') and queryNodes('T[p]') are (#8958), and dedupes sub-indexes and records (#7057).
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
ReviewOverall this is a well-reasoned fix with good tests (HA reproducer plus stale-candidate regression tests). The changes follow CLAUDE.md conventions. I only read the diff and did not run the tests. Notes below, none blocking. What looks good
Points to check
LGTM pending confirmation of points 1 and 2. |
|
Review of #9900 Overall this is a well-reasoned fix. The comments explain the invariants (#7742, #7842, #9428), and the new tests cover each bug. Pulling the top-up loop into VectorUtils.searchWithStaleTopUp removes duplicated code. I only read the main-source part of the diff. I did not run the tests or read the three test files, and part of the SelectExecutor diff was truncated in my view. Things to check
Style and tests
No security concerns found. Nice work. |
… so a re-applied page charges nothing twice A page holding both an id's live entry and its tombstone re-publishes the live entry first when it is applied again (LSM merge-on-read), so judging entry by entry read the tombstone as a fresh delete. Adds a direct engine test of the peer and recovery paths, and a Select test for polymorphic(false) on a type with no bucket of its own.
|
Review of PR 9900 (read from the diff only; I did not build or run the tests). Overall a careful fix. The root cause of 9857 is well identified, the lock scope is justified, and the stale top-up logic is now shared in What looks good
Points to consider
Security: nothing concerning. |
…plyChanges again The recovery flag rode a private applyChanges overload, so the replay loop stopped calling the public one that RecoveryHousekeepingTest and RecoveryHousekeepingGraphTest override (slow lane). It is now a field set around each replayed transaction, read by applyChangesInternal.
Review of #9900I read the main-source changes ( What looks good
Concerns and suggestions
VerdictThe design is sound and well documented, and the fix targets the right root cause. Please look at items 1 to 3, and tidy the comment style in item 5. I have no blocking findings. |
…ratch set per index for replicated pages A replicated apply running on another thread while the open replays its own WAL can no longer be mistaken for the replay, and a replicated vector page no longer allocates its id set: one instance per index serves every page under the write lock.
ReviewSolid, well-reasoned fix. The design is coherent: apply the whole page under the index write lock, judge each id by its pre-page state, exclude crash-recovery replays, and share the stale top-up loop in Strengths
Points to consider
Tests No security concerns. The non-replicated path is unaffected, and a single pass is still the common case for searches. |
|
Review of #9900 I reviewed the main-code diff: TransactionManager, LSMVectorIndex.applyReplicatedPageUpdate, VectorUtils.searchWithStaleTopUp, DbIndexVectorQueryNodes and the start of SelectExecutor. The diff output cut off partway through SelectExecutor, so I did not review the rest of it or any test files. I did not build the PR or run tests. Overall the design is sound: the page is applied under the index write lock, recovery replay is told apart from a peer apply by the replaying thread, and the stale top-up loop is now one shared helper. Points to consider
Tests No security concerns found. 🤖 Generated with Claude Code |
What does this PR do?
Fixes #9857 and #9858, plus a scope bug found in the same code path. Supersedes the reporter's #9859 and #9860.
#9857 - a node's vector graph never picks up vectors replicated after its first search
LSMVectorIndex.applyReplicatedPageUpdate()only updated the vector location index. A localput()/remove()also queues a delta entry, counts a mutation and turns the graphMUTABLE. So once the first search on a follower had built its graph, every vector replicated afterwards was invisible on that node, and on the leader it later became.The same path applies a follower's own commit on the leader (#9428), so the leader's search also missed vectors inserted on a follower. The new HA test reproduces that case too.
A replicated page now updates the in-memory search state the same way a local write does:
deltaVectorOf()reads the vector back when a search needs it, so the apply thread never reads a record.remove()does.MUTABLEand the inactivity rebuild is armed, so a node nobody searches still keeps its delta buffer bounded.How this differs from #9859:
put()does. Without it, a replicated entry could land between a concurrent build's snapshot and itspublishLocationIndex(), or split the allocator/mutation pair the build reads as one instant (LSMVectorIndexIncrementalIngestScalingTest leaves one vector unabsorbed and keeps the engine unit-tests lane red #7742). Either way the vector is stranded.TransactionManagernow tells the index whether a page comes from a peer or from this node's own WAL replayed at open. On a recovery replay only the locations move: the first search reconciles the persisted graph against the pages, and counting there too would charge the tombstones twice.Issue7842DeleteKeepsPersistedGraphTestcaught this.#9858 -
db.index.vector.queryNodesfails the whole query on a concurrently deleted candidatequeryNodesletRecordNotFoundExceptionescape from the record load. The nativeselect().nearestTo()had the same problem. Both now skip a stale candidate and widen the search until they haveklive rows.Instead of a third copy of the #9368 top-up loop, the loop is now
VectorUtils.searchWithStaleTopUp(), shared byvector.neighbors,vector.sparseNeighbors,queryNodesandselect().nearestTo(). TheMAX_FETCH_CANDIDATEScap lives in one place.For
select().nearestTo().where(...), the post-filter still applies to theknearest live records. A stale candidate never changes which records the filter sees.Related:
select().fromType(T).nearestTo()returned records of T's sibling typesWhen
Tinherits its vector index from a parent, the index spans every sibling's buckets, and the native Select API searched all of them. It is now limited toT's buckets (honouringpolymorphic(false)), the same scopevectorNeighbors('T[p]')andqueryNodes('T[p]')use (#8958). Sub-indexes and records are also deduplicated (#7057).Tests
Issue9857ReplicatedVectorsReachSearchHATest(3 nodes): inserts, updates and deletes replicated after every node's first search; a follower-originated insert found by the leader. All 3 fail without the fix.Issue9858VectorQueryNodesStaleCandidateTest(5) andIssue9858SelectVectorStaleCandidateTest(4): all fail without the fix withRecordNotFoundException.SelectVectorSubtypeScopeTest(3): 2 fail without the fix.index.vector.**+index.sparsevector.**: 795 testsquery.select.**: 1,418 testsengine.**and WAL/recovery: 1,720 tests*Vector*and*Replicat*: 134 testsIssue7952ConstraintViolationScanTestwas excluded: it hangs on main as well.Summary by CodeRabbit