Skip to content

fix(#9857): a replica's vector graph picks up vectors replicated after its first search - #9859

Merged
robfrank merged 2 commits into
ArcadeData:mainfrom
blaus23:fix-9857-follower-vector-graph
Oct 13, 2026
Merged

robfrank merged 2 commits into
ArcadeData:mainfrom
blaus23:fix-9857-follower-vector-graph

Conversation

@blaus23

@blaus23 blaus23 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

It makes a follower's LSM_VECTOR graph pick up vectors that are replicated after its first search.

LSMVectorIndex.applyReplicatedPageUpdate() (called from TransactionManager.applyChanges()) kept only the vector location index in step with a replicated page. A local put()/remove() also queues a delta entry, counts a mutation and promotes graphState to MUTABLE. The replicated path did none of that, so:

  • rebuildGraphBeforeSearch() never fired on a follower whose graph was already built;
  • vectors replicated after that first build were never searchable on that node;
  • a follower promoted to leader kept the same gap.

Only a restart or REBUILD INDEX recovered.

A replicated page now does what a local write does:

  • an id the index has never seen is queued as a delta entry, with no payload: deltaVectorOf() reads the vector from the page that was just written;
  • a newly tombstoned id counts as a removal;
  • both count as mutations, and graphState is promoted to MUTABLE under the index write lock, as put() does.

Only genuinely new state counts. A page carries every entry it holds, not just the new ones, so "new" means an id that is neither live nor tombstoned before the page is applied. A re-applied page therefore changes nothing. Compacted pages are left out entirely: a compaction adds and removes no vector, and since #5870 its ids are renumbered.

Motivation

We hit this while evaluating ArcadeDB HA as a Neo4j replacement (Bolt plus db.index.vector.queryNodes). After the second batch, both followers returned 0 of 50 newly inserted vectors by self-lookup, while the leader returned 50 of 50 and count() matched on every node. Full reproduction in #9857.

Related issues

Fixes #9857.

Related but different: #9428 / #9507 (vectors inserted on a follower) and #9758 (snapshot-installed vecgraph).

Additional Notes

Test. Issue9857VectorReplicaSeesReplicatedInsertsIT (3 nodes, @Tag("slow")):

  1. insert on the leader;
  2. search on every node, which builds each node's graph;
  3. insert more on the leader;
  4. every node must find every new record by its own embedding.

It fails without the fix (server 0 must find record 200 by its own embedding) and passes with it.

Other verification:

  • Engine *Vector* + *Compact* tests: 983/983.
  • ha-raft integration tests matching *Vector*, *Compaction*, *Snapshot*, Issue9428*, Issue9758*: 455/455.
  • A Docker 3-node cluster built from this branch's engine jar:
  • A 3-minute stress run (writer on the leader, 4 searchers per follower, periodic deletes) had no deadlocks or apply stalls, no duplicate rows, and counts converged.

Things I'd like a maintainer's eye on:

  1. Locking. The index write lock is now taken on the Raft apply thread, once per replicated vector page that carries new ids or tombstones. That's the same lock put() takes on the leader inside commit. I saw no deadlock under stress, but you know the lock ordering with graphBuildLock and the build paths better than a stress test can show.
  2. Follower cost. Followers now do the rebuild work the leader does. Under constant writes with constant searches, each follower ran an async graph rebuild about every 1–2 s. That matches what an unpatched leader does under the same search load (78 rebuilds in 3 min), so I believe it's the intended behaviour now applied to followers. Before this change, followers looked cheap only because they never rebuilt.
  3. Startup recovery. applyChanges() also runs during WAL recovery at startup, so replayed vector pages now take the same path. The restart tests pass.

Pre-commit: the hooks that apply to Java files (trailing whitespace, final newline, line endings, BOM) were checked on every changed file. pre-commit itself was not run.

Checklist

  • I have run the build using mvn clean package command. Not the full reactor: I built and installed the touched modules (-pl ha-raft -am install) and ran the suites listed above.
  • My unit tests cover both failure and success scenarios

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Replicated vector index updates are now reflected in searches across servers. Newly replicated vectors become searchable, and deletions of known vectors are applied, helping keep search results consistent across the cluster.

@mergify

mergify Bot commented Oct 12, 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

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

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 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ad16570a-1817-458f-95ec-69c313bcabd7
📥 Commits

Reviewing files that changed from the base of the PR and between 9ae0350 and 144edb6.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a8952d5-29ca-4b64-83ed-c33ddd8fc999
📥 Commits

Reviewing files that changed from the base of the PR and between cb0f720 and 9ae0350.

📒 Files selected for processing (2)
  • engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java
  • ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue9857VectorReplicaSeesReplicatedInsertsIT.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

Replicated vector page updates now track new vectors and eligible removals, update mutation counts, and promote graph state when needed. A three-server Raft integration test checks vector searches after two insert batches.

Changes: Vector replication

Layer / File(s) Summary
Track replicated vector changes
engine/src/main/java/com/arcadedb/index/vector/LSMVectorIndex.java
Replicated page processing tracks previously unknown vectors and eligible tombstones. It queues new vectors, updates mutation counts, and promotes LOADING or IMMUTABLE graph state to MUTABLE when changes are found.
Verify searches across servers
ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue9857VectorReplicaSeesReplicatedInsertsIT.java
The test creates a cosine vector index, inserts two batches, and checks that searches on all three servers find each inserted record. It also checks cluster consistency.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 9ae03

No concrete issue currently prevents merging; complete the normal verification checks before release.

Pre-merge checks | Passed 6 | Inconclusive 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the fix for replicated vectors missing from a replica's vector graph.
Description check Passed The description includes all template sections, explains the problem and solution, identifies related issues, and documents testing. It also clearly notes that the full mvn clean package command was…
Linked Issues check Passed The description references and marks issue #9857 as fixed, and distinguishes related issues #9428, #9507, and #9758.
Out of Scope Changes check Passed The implementation and integration test directly support the stated objective of making replicated vectors searchable on followers.
Linked Issues check Passed Issue #9857 requires replicated LSM_VECTOR pages to make later vectors searchable after a follower has built its graph. The reviewed source summary reports that applyReplicatedPageUpdate() queues …
Out of Scope Changes check Passed The change is limited to the replicated vector-page update logic and one slow integration test for Issue #9857. The test directly verifies the required follower behavior and cluster consistency. No un…
Full details: Docstring Coverage

Explanation

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

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • 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.

…cated after its first search

applyReplicatedPageUpdate() kept only the vector location index in step with replicated
LSM_VECTOR pages. Unlike put()/remove() it queued no delta entry, counted no mutation and
never promoted graphState, so a follower that had built its graph on an earlier search kept
searching that graph forever, and a follower promoted to leader kept the same gap. Only a
restart or REBUILD INDEX recovered.

A replicated page now does what a local write does: an id the index has never seen is queued
as a delta entry (no payload: deltaVectorOf() reads it from the page) and a newly tombstoned
id counts as a removal, both as mutations, and graphState is promoted to MUTABLE. A page
carries every entry it holds, so a re-applied page changes nothing. Compacted pages are left
out: a compaction adds and removes no vector, and since ArcadeData#5870 its ids are renumbered.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@blaus23
blaus23 force-pushed the fix-9857-follower-vector-graph branch from da0ef71 to 9ae0350 Compare October 12, 2026 16:18
@robfrank

Copy link
Copy Markdown
Collaborator

@claude review

@claude

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Claude finished @robfrank's task in 33s —— View job


Review of PR #9859

The fix is small and well targeted, and I think it is correct for the reported bug. I found no blocking issues. This is a read-only review of the diff and the surrounding put()/remove() code. I did not build or run any tests.

What I checked

  • Mirrors the local write path. The replicated path now queues a payload-less DeltaVectorEntry, increments mutationsSinceSerialize, and promotes IMMUTABLE/LOADING to MUTABLE under lock.writeLock(). put() does the same at LSMVectorIndex.java:9361-9370, and remove() at :9878-9886. queueDeltaEntry asserts the write lock is held, and this code takes it.
  • Idempotency. known is computed before addOrUpdate, so a re-applied page or WAL replay finds the ids live or tombstoned and changes nothing. A tombstone only counts when !wasDeleted. Skipping isCompacted pages is right, since a compaction adds and removes no vector and its ids are renumbered.
  • Lock scope. The page parse and addOrUpdate stay outside the write lock, and the lock is taken once per page rather than per entry. That keeps hold time on the Raft apply thread short.

Points to consider (non-blocking)

  1. scheduleInactivityRebuild() is not called. put() calls it after releasing the lock (:9378), and remove() does too (:9892). The replicated path skips it. rebuildGraphBeforeSearch() covers the search path, so the bug is fixed. A follower that receives writes and no searches will never get the idle-timer rebuild, though, so its delta buffer grows until the first search. Please either call it after the unlock or add a comment saying the omission is deliberate.
  2. Queued deltas are not dropped for a replicated tombstone. remove() runs deltaVectors.removeIf on the rid and fixes up deltaResidentPayloads. The replicated tombstone path only counts the removal. If an insert and its delete both replicate before the next search, the delta entry for the deleted id stays queued. This is probably harmless if deltaVectorOf() and the merge scan filter on isDeleted, since your stress run showed deleted vectors returned by no node. Please confirm that filter exists. If it does, a one-line comment would help the next reader. If it doesn't, a deleted vector could come back from the delta scan.
  3. undo bookkeeping is not mirrored. put() and remove() use undo.recordGraphFlip and undo.mutationsCharged so a rolled-back commit restores state. For a replicated page that is already committed on the leader, rollback should not apply, so this looks fine. I'm noting it only so you know I looked.
  4. Cost of a long-lived replicatedInserts list. A huge replicated page, such as a batch import, allocates an ArrayList plus one DeltaVectorEntry per new id. That is bounded by the page size, so it is acceptable. Your CLAUDE.md prefers primitives, and an int[] of ids could be used with rid re-read from the location index. I would not block on it.
  5. Unbounded delta growth on followers. Because vectors are now queued without payload, the delta buffer on a follower with constant writes and no searches is bounded only by the rebuild trigger (point 1). Please check that the buffer-size trigger in queueDeltaEntry or the async rebuild still fires from this path.

Test

Issue9857VectorReplicaSeesReplicatedInsertsIT covers the reported scenario: insert, search on every node, insert more, then search every node for every new record. Two gaps worth a follow-up:

  • Nothing exercises the tombstone branch (replicatedRemovals) in the integration test. Your PR notes a manual docker check for deletes. A small assertion in the same IT would give it a regression guard: delete a few records on the leader after the first search, then assert no node returns them.
  • There is no engine-level unit test that applies the same replicated page twice and asserts the mutation counter and delta buffer do not move. That is the invariant the known logic exists for, and a cheap test would protect it.

Process notes

  • The checklist item for mvn clean package is unchecked. That is acceptable given the scoped builds you describe, but CI should be green before merge.
  • Your three review requests (locking, follower rebuild cost, startup recovery) look reasonable to me. I found no lock-order inversion: the new lock acquisition sits after all page reads and addOrUpdate, and nothing is held that graphBuildLock paths would need.

Overall this looks good to merge once points 1 and 2 are answered.

LSMVectorIndex.applyReplicatedPageUpdate conflict resolved to main's version:
main already fixed ArcadeData#9857 (6928f57, 6473e14, fe238c8). The branch keeps
Issue9857VectorReplicaSeesReplicatedInsertsIT, which passes against main's fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robfrank
robfrank merged commit c3d6668 into ArcadeData:main Oct 13, 2026
robfrank added a commit that referenced this pull request Oct 21, 2026
…r its first search (#9859)

applyReplicatedPageUpdate() kept only the vector location index in step with replicated
LSM_VECTOR pages. Unlike put()/remove() it queued no delta entry, counted no mutation and
never promoted graphState, so a follower that had built its graph on an earlier search kept
searching that graph forever, and a follower promoted to leader kept the same gap. Only a
restart or REBUILD INDEX recovered.

A replicated page now does what a local write does: an id the index has never seen is queued
as a delta entry (no payload: deltaVectorOf() reads it from the page) and a newly tombstoned
id counts as a removal, both as mutations, and graphState is promoted to MUTABLE. A page
carries every entry it holds, so a re-applied page changes nothing. Compacted pages are left
out: a compaction adds and removes no vector, and since #5870 its ids are renumbered.

Co-authored-by: robfrank <[email protected]>
(cherry picked from commit c3d6668)
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)

2 participants