Skip to content

fix(#9857, #9858): replicated vectors reach every node's search; vector search skips concurrently deleted candidates - #9900

Merged
lvca merged 6 commits into
mainfrom
worktree-arcadedb-9857-9858
Oct 13, 2026
Merged

lvca merged 6 commits into
mainfrom
worktree-arcadedb-9857-9858

Conversation

@lvca

@lvca lvca commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

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 local put()/remove() also queues a delta entry, counts a mutation and turns the graph MUTABLE. 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:

  • an id that is neither live nor tombstoned is queued in the delta buffer, with no payload. deltaVectorOf() reads the vector back when a search needs it, so the apply thread never reads a record.
  • a tombstone over a live id removes that id's delta entry and search-cache entry, as remove() does.
  • both count as mutations. The graph turns MUTABLE and the inactivity rebuild is armed, so a node nobody searches still keeps its delta buffer bounded.

How this differs from #9859:

  • The whole page is applied under the index write lock, as put() does. Without it, a replicated entry could land between a concurrent build's snapshot and its publishLocationIndex(), 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.
  • Deletes are applied too. Delta entries and search-cache entries of tombstoned ids are dropped, not just counted.
  • Crash recovery is excluded. TransactionManager now 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. Issue7842DeleteKeepsPersistedGraphTest caught this.

#9858 - db.index.vector.queryNodes fails the whole query on a concurrently deleted candidate

queryNodes let RecordNotFoundException escape from the record load. The native select().nearestTo() had the same problem. Both now skip a stale candidate and widen the search until they have k live rows.

Instead of a third copy of the #9368 top-up loop, the loop is now VectorUtils.searchWithStaleTopUp(), shared by vector.neighbors, vector.sparseNeighbors, queryNodes and select().nearestTo(). The MAX_FETCH_CANDIDATES cap lives in one place.

For select().nearestTo().where(...), the post-filter still applies to the k nearest live records. A stale candidate never changes which records the filter sees.

Related: select().fromType(T).nearestTo() returned records of T's sibling types

When T inherits 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 to T's buckets (honouring polymorphic(false)), the same scope vectorNeighbors('T[p]') and queryNodes('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) and Issue9858SelectVectorStaleCandidateTest (4): all fail without the fix with RecordNotFoundException.
  • SelectVectorSubtypeScopeTest (3): 2 fail without the fix.
  • Regression runs, all green:
    • engine index.vector.** + index.sparsevector.**: 795 tests
    • SQL vector functions, Cypher procedures and query.select.**: 1,418 tests
    • engine engine.** and WAL/recovery: 1,720 tests
    • ha-raft *Vector* and *Replicat*: 134 tests

Issue7952ConstraintViolationScanTest was excluded: it hangs on main as well.

Summary by CodeRabbit

  • Bug Fixes
    • Vector searches skip deleted or unavailable records and continue searching for live results, returning fewer than requested only when not enough valid records are available.
    • When stale records reduce the available results, searches retry with a larger candidate pool, up to a defined limit.
    • Nearest-vector searches respect the queried type’s scope and apply filters to the nearest live records.
    • Vector index searches reflect replicated inserts, updates, and deletions across servers.
    • SQL vector-neighbor searches also continue past stale candidates to find available results.

…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).
@lvca lvca added this to the 26.11.1 milestone Oct 13, 2026
@lvca lvca self-assigned this Oct 13, 2026
@mergify

mergify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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.

@codacy-production

codacy-production Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity

Metric Results
Complexity 4

View in Codacy

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.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 21d23a08-2807-4749-b50b-126996d6e71a
📥 Commits

Reviewing files that changed from the base of the PR and between 789b15d and 0573ad3.

📒 Files selected for processing (2)
  • engine/src/main/java/com/arcadedb/engine/TransactionManager.java
  • engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Walkthrough

Vector queries now widen candidate searches when stale records reduce live results. SELECT vector searches scope subindexes to the queried type. Transaction application distinguishes WAL recovery from peer updates to vector indexes.

Changes: Stale vector candidates

Layer / File(s) Summary
Shared stale-candidate top-up
engine/src/main/java/com/arcadedb/index/vector/VectorUtils.java
VectorUtils defines a shared fetch cap and retry helper. The helper increases the candidate budget when a search skips stale records and an index fills its budget.
SQL and queryNodes top-up
engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorNeighbors.java, engine/src/main/java/com/arcadedb/function/sql/vector/SQLFunctionVectorSparseNeighbors.java, engine/src/main/java/com/arcadedb/query/opencypher/procedures/db/DbIndexVectorQueryNodes.java, engine/src/test/java/com/arcadedb/query/opencypher/Issue9858VectorQueryNodesStaleCandidateTest.java
The SQL vector-neighbor functions and queryNodes use the shared retry helper. queryNodes skips missing records. Regression tests cover stale candidates, multiple buckets, available result counts, and scores.
SELECT vector search and scope
engine/src/main/java/com/arcadedb/query/select/SelectExecutor.java, engine/src/test/java/com/arcadedb/query/select/Issue9858SelectVectorStaleCandidateTest.java, engine/src/test/java/com/arcadedb/query/select/SelectVectorSubtypeScopeTest.java
SELECT vector search scopes subindexes to the queried type, skips missing records, deduplicates RIDs, and checks timeouts during search and assembly. Tests cover stale candidates and subtype scope.

Replicated vector-index state

Layer / File(s) Summary
Distinguish recovery from peer updates
engine/src/main/java/com/arcadedb/engine/TransactionManager.java
WAL replay passes a recovery flag through transaction application. Vector-index page updates receive a flag that distinguishes recovery from peer updates.
Update search state for peer pages
engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java, engine/src/test/java/com/arcadedb/index/vector/Issue9857ReplicatedPageSearchStateTest.java, ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue9857ReplicatedVectorsReachSearchHATest.java
Peer-applied page entries update vector search state for live IDs and tombstones. Tests cover recovery and peer page handling, and replicated inserts, embedding updates, and deletes.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant TransactionManager
  participant LSMVectorIndex
  participant VectorGraph
  TransactionManager->>LSMVectorIndex: Apply page with peer or recovery origin
  LSMVectorIndex->>LSMVectorIndex: Update locations for page entries
  LSMVectorIndex->>VectorGraph: Update search mutation state for peer pages
Loading

Suggested reviewers: robfrank

Merge Risk: ⚪ Minimal · up to 0573a

The changes update replicated vector search state and top up results when stale candidates are skipped. The investigated concerns did not establish a concrete current-head failure, so no PR-specific issue blocks merging after normal checks.

Pre-merge checks · Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check Warning #9857 is the only active directly linked issue. The PR also implements stale-candidate top-up in queryNodes, vector.neighbors, vector.sparseNeighbors, and select().nearestTo(). It also changes… Move the stale-candidate and subtype-scope implementations and tests to separate PRs with the corresponding active issue links, or add active direct issue links that require these objectives.
Docstring Coverage Inconclusive Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 55 functions across 11 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly summarizes the two main fixes: replicated vector visibility and stale-candidate handling during vector searches.
Description check Passed The description is detailed and explains the implementation, motivation, related issues, tests, and regression results. It does not reproduce the template headings for Motivation, Related issues, Addi…
Linked Issues check Passed #9857 requires vectors replicated after a follower search to become searchable and remain available after promotion. LSMVectorIndex.applyReplicatedPageUpdate now applies peer pages under the index w…
Full details: Out of Scope Changes check

Explanation

#9857 is the only active directly linked issue. The PR also implements stale-candidate top-up in queryNodes, vector.neighbors, vector.sparseNeighbors, and select().nearestTo(). It also changes subtype scoping and deduplication in native select().nearestTo(). The added tests target #9858 and subtype scope behavior. These changes do not support replicated vector-page state for #9857.

Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 55 functions across 11 files. (1 skipped: 1 too large.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Review

Overall 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

  • applyReplicatedPageUpdate now holds the index write lock for the whole page, matching put(). This closes the window against a concurrent build's snapshot and publishLocationIndex().
  • The "new" decision is made before addOrUpdate, so re-applying a page changes nothing the second time.
  • Recovery is kept apart (fromPeer=false), which avoids double-charging tombstones (LSM_VECTOR: incremental delete with deferred compaction, instead of a full graph rebuild on every deletion #7842).
  • Deduplicating the stale top-up loop into VectorUtils.searchWithStaleTopUp removes three copies, and the shared MAX_FETCH_CANDIDATES is a good cleanup.

Points to check

  1. Lock hold time and ordering. vectorIndex() is materialised before taking the write lock, which is right. Inside the lock the page parse is bounded, but deltaVectors.removeIf is O(delta size) per page that carries tombstones. A large delete batch on a node with a big delta buffer therefore costs O(pages x delta) while holding the exclusive lock. Consider collecting the tombstoned ids across the whole transaction, or at least confirming the delta buffer is small enough in practice (it is bounded by the inactivity rebuild).
  2. Null-payload delta entries. new DeltaVectorEntry(id, rid, null) relies on deltaVectorOf() reading the record back. If the record is not yet visible, because the apply runs before the record page is written in the same tx, the search path must tolerate a miss. Please confirm that an entry whose vector cannot be read is skipped rather than throwing. A test for this ordering would be useful.
  3. Compacted pages. tracked = fromPeer && !isCompacted skips accounting for compacted files. The reasoning in the Javadoc is sound, but a tombstone applied through a compacted page is then never dropped from the delta buffer or search cache. This is probably fine because compaction only carries existing entries. A one-line test or comment would pin that down.
  4. Public API surface. The new applyReplicatedPageUpdate(page, boolean) overload is public, and so is VectorUtils.MAX_FETCH_CANDIDATES. Package-private or narrower visibility is probably enough for the overload, since TransactionManager is in a different package, so it may need to stay public. Worth a second look.
  5. Cypher procedure. saturated is set whenever any single index returns fetchK neighbours. That is consistent with the SQL path. When RecordNotFoundException is the only stale signal, other exception types (for example a record whose bucket was dropped) still propagate. This is likely acceptable.
  6. Style nit. The Javadoc on applyReplicatedPageUpdate is very long. A shorter summary with the details moved to inline comments would match the surrounding code better.

LGTM pending confirmation of points 1 and 2.

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

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

  1. Lock scope in applyReplicatedPageUpdate: the page is now parsed under the index write lock, so readers and writers wait for the whole page. vectorIndex() is correctly materialized before the lock is taken. The deltaVectors.removeIf scan also runs under the write lock and is O(delta size) per page that carries tombstones. It is bounded by the rebuild threshold, so probably fine, but a comment would help.
  2. Payload-less delta entries: DeltaVectorEntry(id, rid, null) relies on deltaVectorOf() reading the record on demand. Please confirm a search that sees the entry before the record is readable, or after it is deleted, skips it cleanly instead of throwing. The deltaResidentPayloads accounting looks consistent, since removeIf only decrements for non-null payloads.
  3. Idempotency: inserting depends on not live and not tombstoned. Re-applying a page is a no-op, which is good. An id that goes live, then tombstoned, then live again would not be re-queued. That is probably impossible because ids are monotonic, but a short comment would make the assumption explicit.
  4. The recovery flag is threaded through the private applyChanges and applyChangesInternal overloads and then inverted (!recovery) at the call site. Naming it fromPeer throughout would avoid the double negation. Minor.
  5. SelectExecutor: with polymorphic(false) on a type that has no bucket of its own, the query now returns an empty list. That is reasonable but differs from the old behavior. Please confirm SelectVectorSubtypeScopeTest covers it.
  6. DbIndexVectorQueryNodes: with several indexes, saturated is set if any index fills fetchK, which is the conservative choice. The per-index fetch can grow to 100k, so the worst case is 100k times the number of indexes. Fine, but worth knowing.

Style and tests

  • Imports over fully qualified names and final locals are followed.
  • Make sure the HA test takes its ports from the fixture (HardcodedTestServerPortsTest), uses no raw wall-clock assertions, and tags slow tests with @tag("slow").
  • Coverage is good: the HA test and the stale-candidate tests fail without the fix. One gap I'd fill is a direct test for the fromPeer=false (recovery) path asserting the mutation counter is not charged. Issue7842DeleteKeepsPersistedGraphTest only covers it indirectly.

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.
@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

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 VectorUtils.searchWithStaleTopUp.

What looks good

  • The whole replicated page is applied under the write lock, as put() does, closing the race with a concurrent graph build.
  • Locations are materialised before the lock is taken.
  • "New vs re-read" is decided from the state before the page, so re-applying a page is idempotent.
  • Recovery replay is excluded via the recovery flag, avoiding double-charged tombstones.
  • Delta entries carry no payload, so the apply thread never reads a record.
  • Tests cover the engine, Cypher, SELECT and a Raft HA scenario, in the repo style.

Points to consider

  1. Allocation on the apply path: every replicated page allocates IntHashSet(numberOfEntries) plus up to four lazy sets inside the exclusive lock. Consider skipping the bookkeeping when no graph or delta state is resident, or comment on why it is needed.
  2. deltaVectors.removeIf is O(delta size) per page with tombstones, under the write lock. A bulk delete replicated as many small transactions could be costly. Worth a note on the worst case.
  3. Null-payload delta entries: please confirm an entry whose record is not yet readable is never dropped permanently (e.g. index page applied before the record page of the same transaction). Does the HA test cover that order?
  4. SelectExecutor sub-type bucket scoping is a separate behaviour change bundled in. Consider splitting it out or calling it out explicitly. Also check getBuckets(polymorphic) for types with no buckets of their own.
  5. Comment style: the new comments in SelectExecutor.executeVector() are ALL CAPS; the rest of the codebase uses sentence case.
  6. Minor: the private MAX_FETCH_CANDIDATES aliases in the two SQL functions could reference VectorUtils.MAX_FETCH_CANDIDATES directly.
  7. Tests: make sure the HA test uses bounded polling, not fixed sleeps, and no raw wall-clock assertions (see CLAUDE.md). Consider @Tag("slow") if it takes several seconds.

Security: nothing concerning. MAX_FETCH_CANDIDATES still bounds the top-up memory.

…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.
@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Review of #9900

I read the main-source changes (TransactionManager, LSMVectorIndex, VectorUtils, DbIndexVectorQueryNodes, SelectExecutor). I did not read the test files in detail or run anything, so this is a code-reading review only.

What looks good

Concerns and suggestions

  1. replayingOwnWAL is a shared volatile field instead of a parameter. It is only set in recoverWALFiles(), so it is probably safe. applyChangesInternal reads it once at entry, which is good. It does make the "recovery vs peer" distinction implicit, though. Two things to check:
    • Is recoverWALFiles() guaranteed to be single-threaded relative to any replicated apply? If a Raft apply could run on another thread during open, it would be misclassified as recovery and its vectors would stay invisible.
    • A short comment or test that pins that guarantee would help.
  2. deltaVectors.removeIf is O(delta buffer) per replicated page that contains a tombstone. The comment says the buffer is bounded by rebuilds. Under a heavy delete stream with a large buffer, this runs on the apply thread while holding the index write lock. Consider whether it should be skipped when the id set is small, or use an id-keyed structure if the buffer can grow large.
  3. new IntHashSet(numberOfEntries) is allocated per page when fromPeer. On the replication hot path this is garbage for every page, even pages with nothing new. The lazy allocation of the other sets is good. You could avoid the cost with a cheap pre-check (for example, skip the seen set if the page version shows it was already applied), or reuse a per-index scratch set under the write lock.
  4. Payload-less delta entries. deltaVectorOf() reads the record back at search time, so the first search after a large replicated batch pays N record loads. This trade-off is reasonable. A note in the PR on expected cost, or a test with a few thousand replicated vectors, would help confirm it is acceptable.
  5. SelectExecutor:
    • The new comments are in ALL CAPS, which does not match the surrounding style.
    • allowedBucketIds is built from bucket.getFileId() and compared against getAssociatedBucketId(). These coincide for buckets in ArcadeDB, but bucket.getFileId() reads like a different concept. Using the bucket id accessor would be clearer, if one exists.
  6. DbIndexVectorQueryNodes. saturated[0] is set on neighbors.size() >= fetchK, so a multi-index search that is saturated on any index triggers a widening. That matches the other callers. Please confirm the limit-bounded loop still deduplicates correctly across passes. It looks fine, because each pass restarts with a fresh emitted set.
  7. Test hygiene (per CLAUDE.md).
    • Confirm the HA test uses getServerHttpUrl / fixture ports and has no hard-coded ports.
    • Confirm it is tagged if it is slow.
    • Confirm it has no raw wall-clock assertions.
  8. Out of scope: the PR notes that Issue7952ConstraintViolationScanTest hangs on main. It would be worth a separate issue if one does not exist.

Verdict

The 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.
@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

Review

Solid, 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 VectorUtils.searchWithStaleTopUp. I read the diff only and did not run the tests.

Strengths

Points to consider

  1. deltaVectors.removeIf(...) runs under the index write lock and is O(delta buffer) per page containing tombstones. A burst of replicated deletes means one full buffer scan per page, blocking all readers and writers. Consider collecting tombstoned ids across a transaction, or indexing delta entries by id. At minimum, please confirm the buffer bound in practice.
  2. replicatedPageSeenIds is a long-lived field that is cleared but never shrunk, so one huge page keeps its backing array for the life of the index. Minor; a trim after an unusually large page would be cheap.
  3. Each page lazily allocates up to four IntHashSets. queued looks redundant given unknownBefore is already deduplicated by seen; dropping it would simplify the logic.
  4. Delta entries are queued with a null payload, so deltaVectorOf() reads the record at search time. Please make sure a test covers a search hitting such an entry when the record was deleted or not yet applied (the skip path).
  5. SelectExecutor: the where post-filter now runs after the k nearest live records are loaded, rather than during assembly. Worth a test with where plus a timeout.
  6. DbIndexVectorQueryNodes.searchAndLoad derives saturated from the raw per-index count, which is conservative (may cause one extra pass). Acceptable.
  7. Style: a stray double blank line after MAX_FETCH_CANDIDATES in VectorUtils.

Tests
Please confirm the new tests carry the right @Tag (slow for HA), use no hard-coded ports, and make no raw wall-clock assertions, per CLAUDE.md.

No security concerns. The non-replicated path is unaffected, and a single pass is still the common case for searches.

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown

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

  1. Cost of deltaVectors.removeIf per page. It scans the whole delta buffer for every replicated page containing a tombstone, under the index write lock. With a large buffer and delete-heavy pages this can block readers and writers. A benchmark or a note on worst-case size would help.
  2. Delete before the record is read back. A tombstone only drops a delta entry if the id was live before the page or queued by the same page. That matches remove(). I would add a test where the record is deleted before deltaVectorOf() reads it, if Issue9857ReplicatedPageSearchStateTest does not already cover it.
  3. recovery flag. It is read once at the top of applyChangesInternal, which is correct. A short comment that replay never hands work to another thread would help future readers.
  4. Style. The block comments in SelectExecutor are in ALL CAPS, unlike the surrounding code. Please use sentence case.
  5. MAX_FETCH_CANDIDATES aliases. The private constants in SQLFunctionVectorNeighbors and SQLFunctionVectorSparseNeighbors now only alias VectorUtils.MAX_FETCH_CANDIDATES. Consider using the shared constant directly.
  6. DbIndexVectorQueryNodes. Please confirm the limit truncation happens inside searchAndLoad and not after the top-up, so the size check against k is accurate.
  7. Shared replicatedPageSeenIds. Reuse is safe only because of the write lock. Keep that invariant if the lock scope is ever narrowed.

Tests
Coverage looks good: an engine-level unit test, a 3-node HA test (the description says all 3 fail without the fix) and regression tests for stale candidates and sibling-type scope. Per CLAUDE.md, make sure the HA test takes its ports from the fixture and is tagged slow if it takes noticeably long.

No security concerns found.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HA: a follower's LSM_VECTOR graph never picks up vectors replicated after its first search (and a promoted follower keeps the gap)

1 participant