Skip to content

fix(#9590): refuse READ_YOUR_WRITES / LINEARIZABLE reads on a node removed from the Raft configuration - #9605

Merged
robfrank merged 4 commits into
mainfrom
fix/9590-ha-consistent-reads-on-removed-node
Oct 10, 2026
Merged

robfrank merged 4 commits into
mainfrom
fix/9590-ha-consistent-reads-on-removed-node

Conversation

@robfrank

@robfrank robfrank commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #9590

A node removed from the Raft configuration (leaveCluster(), DELETE /api/v1/cluster/peer/{id}) keeps an open division that receives no more appends. #9510 made it refuse writes; its consistent reads still waited on an index it never reaches. RaftReplicatedDatabase.waitForReadConsistency() now refuses them, retryably (NeedRetryException, HTTP 503 / Bolt TransientError / gRPC ABORTED), and the message names the reason:

  • a READ_YOUR_WRITES read on a non-leader whose bookmark is ahead of this node's trusted applied index. Before: it waited the full quorum timeout, then degraded to EVENTUAL and served data missing the write. It is also re-checked after the wait, so a node removed during the wait refuses rather than serving the degraded read. A member that merely timed out keeps the documented degrade-to-EVENTUAL contract;
  • any LINEARIZABLE read. Before: it waited for a read index the division never applies and failed only at the timeout.

EVENTUAL reads, and READ_YOUR_WRITES reads whose bookmark this node already applied, are still served and never consult membership (the already-applied case now also skips the no-op wait call). isRemovedFromConfiguration() is the #9510 check (a division lookup plus a configuration read, no lock), already run on every commit.

Test plan

  • Issue9590ReadConsistencyGateOnRemovedNodeTest (new, regular lane, FakeRaftHAServer): leader/follower x removed/member x RYW ahead/applied, removed during the wait, removed after the wait caught up, LINEARIZABLE on both roles, fail-open on an unknown configuration, EVENTUAL
  • Issue9590RemovedNodeRefusesConsistentReadsIT (new, slow, real Ratis, 3 nodes): 3 of its 4 tests fail on main without the fix (verified), all pass with it
  • Issue9510NodeRemovedFromConfigurationRefusesWritesIT, RaftReadConsistencyBookmarkIT, RaftCommandReadConsistencyIT
  • full ha-raft unit suite without slow/benchmark/vector: 3007 tests, 0 failures

Coverage

Invariant: a node that is not a member of the Raft configuration never serves a consistent read it cannot back, and never blocks one it knows it cannot reach.

Entry point Status
query(language, query[, args]) x3 -> waitForReadConsistency() fixed here
read-only command(...) -> applyReadConsistencyForReadOnlyCommand -> waitForReadConsistency() fixed here (same gate)
Bolt / gRPC / Postgres reads go through the same wrapper query/command, fixed here
ensureLinearizableRead / ensureLinearizableFollowerRead only caller is waitForReadConsistency() (grep), fixed here
post-commit RYW apply wait in the commit path write side, refused before submit by #9510

Known gaps: a read whose wait began while the node was still a member still blocks until the quorum timeout before it is refused (latency only, no stale data is served). Filed as #9606: closing it needs a read-only variant of waitForAppliedIndex, because the same wait backs the post-commit waits, where a retryable exception would invite a duplicate retry.

The fake-based test needed FakeRaftHAServer to record isRemovedFromConfiguration, ensureLinearizableRead and ensureLinearizableFollowerRead. Issue7641DropInReplicasWaitsForLocalApplyTest asserted the exact full call log, so it now filters the log to the two calls it checks.

Adversarial pass

This run had no tool for spawning a separate subagent, so no independent agent did the pass. The author's self-check found:

Review cycles

Cycle Head Changes Bot outcome
1 e513742 initial fix + IT LGTM, 4 minor points: added an explicit removal assertion to the IT and a fast unit test of the branch matrix. Points 1-2 were deferred (see below)
2 f542643 unit test, FakeRaftHAServer recording no blockers: added the post-wait re-check (the removed-during-wait race), filed #9606, made the #7641 assertion order-relative, aligned the constants
3 9f037bc post-wait re-check no blockers: commented why the applied index is read twice, filtered the #7641 log and kept containsExactly
4 5eb59aa comment + #7641 filter "Looks good to merge once CI is green", non-blocking nits only. The cycle cap was reached, so no further push

Deferred / skipped items

Final state: max-cycles-reached (4/4). The last review had no blocking items.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Consistent reads on nodes removed from the cluster are now refused when they cannot be served safely, allowing clients to retry instead of receiving potentially stale results.
    • Eventual reads remain available on removed nodes, as do read-your-writes requests when the requested changes have already been applied.
    • Consistent reads on nodes still in the cluster retain their existing timeout behavior.

…removed from the Raft configuration

A removed node's division stays open and receives no appends, so a
READ_YOUR_WRITES bookmark it has not applied, or a LINEARIZABLE read
index, is never reached there: the read waited the whole quorum timeout
and then degraded (READ_YOUR_WRITES) or failed (LINEARIZABLE). Refuse
them at once with a retryable NeedRetryException, as #9510 does for
writes. EVENTUAL reads and bookmarks already applied are still served.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mergify

mergify Bot commented Oct 9, 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 9, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Coverage 100.00% diff coverage

Metric Results
Coverage variation Report missing for 8c0ef0e1
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (8c0ef0e) Report Missing Report Missing Report Missing
Head commit (5eb59aa) 255895 205115 80.16%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#9605) 10 10 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

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.

@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review

The change is small and targeted, and it follows the intent of #9510. I found nothing blocking.

What looks good

  • The membership check runs only on the two paths that could block, so EVENTUAL reads and already-satisfied READ_YOUR_WRITES (RYW) reads pay nothing.
  • It throws NeedRetryException, so the existing 503 / TransientError / ABORTED mappings apply, and the message says what to do next.
  • The IT uses real Ratis and covers a removed follower, a removed former leader, and the two cases that must still be served. It uses StallAwareStopwatch.assertGaveUpWithin as CLAUDE.md asks, and it is tagged slow.

Minor points

  1. Check-then-wait race (RYW). getTrustedAppliedIndex < readAfterIndex is read, then waitForAppliedIndex runs. If the node is removed during the wait, that wait still runs to the quorum timeout and then degrades to EVENTUAL. This is a narrow window and arguably out of scope. If you want it closed, waitForAppliedIndex could re-check removal on timeout.
  2. Degrade-to-EVENTUAL on timeout. Your description notes that RYW served stale data after the timeout. That behaviour still applies to a node that is a member but lagging. If it is intentional, a short comment would help.
  3. Test ordering. In aRemovedNodeStillServesEventualReadsAndBookmarksItAlreadyApplied, isRemovedFromConfiguration() is true by then, so the test does exercise the bypass. Adding a plain assertion on that would make the intent explicit.
  4. Unit coverage. The only coverage is the slow IT. A fast unit test with a mocked RaftHAServer, next to Issue9510RemovedFromConfigurationFailOpenTest, would cover the branch matrix in the regular lane. The matrix is: leader or follower, RYW ahead or not, LINEARIZABLE, and the fail-open case where isRemovedFromConfiguration is false when the configuration is unknown.

LGTM overall.

@coderabbitai

coderabbitai Bot commented Oct 9, 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: 6e68e8dd-acda-4049-8c95-c26cc86a0826

📥 Commits

Reviewing files that changed from the base of the PR and between f542643 and 5eb59aa.


📒 Files selected for processing (3)
  • ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftReplicatedDatabase.java
  • ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue7641DropInReplicasWaitsForLocalApplyTest.java
  • ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue9590ReadConsistencyGateOnRemovedNodeTest.java

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



📝 Walkthrough

Walkthrough

Removed Raft members now receive a retryable error for specified consistent reads instead of waiting for indexes they cannot apply. EVENTUAL reads and READ_YOUR_WRITES reads with already-applied bookmarks remain available. Unit and integration tests cover these behaviors.

Changes

Removed-node read handling

Layer / File(s) Summary
Membership guard for consistent reads
ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftReplicatedDatabase.java
The read-consistency gate checks membership before waiting for an unapplied READ_YOUR_WRITES bookmark or starting a LINEARIZABLE read barrier. It throws NeedRetryException for removed nodes.
Read-gate unit coverage
ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue9590ReadConsistencyGateOnRemovedNodeTest.java, ha-raft/src/test/java/com/arcadedb/server/ha/raft/FakeRaftHAServer.java, ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue7641DropInReplicasWaitsForLocalApplyTest.java
Unit tests cover membership decisions, index waits, read barriers, and EVENTUAL reads. The fake server records membership and barrier calls. The drop-path call-order assertion filters for replication and apply-wait calls.
Removed-node read integration coverage
ha-raft/src/test/java/com/arcadedb/server/ha/raft/Issue9590RemovedNodeRefusesConsistentReadsIT.java
Integration tests cover rejected consistent reads on removed nodes and permitted EVENTUAL and already-applied READ_YOUR_WRITES reads. They also add cluster setup, node removal, and assertion helpers.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to 5eb59

The supplied review evidence identifies no issue that needs to be fixed before merge.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 37 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: refusing consistent reads on nodes removed from the Raft configuration.
Description check Passed The description provides the change, motivation, related issue, implementation details, test plan, coverage, known gaps, and review context. It does not reproduce the template headings exactly and doe…
Linked Issues check Passed The PR meets the coding requirements in [#9590]. waitForReadConsistency() refuses removed nodes for unapplied non-leader READ_YOUR_WRITES reads and for LINEARIZABLE reads. It raises retryable `N…
Out of Scope Changes check Passed The production change is limited to the read-consistency gate required by [#9590]. The new integration and unit tests directly verify this behavior. The fake-server call recording and the adjusted #76…


  • 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.

…moval in the served-reads IT

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review

Small, well-scoped fix. The gate sits in the one place all read paths share, costs nothing for EVENTUAL and already-satisfied RYW reads, fails open when the configuration is unknown (consistent with #9510), and is tested at both unit level and against real Ratis (the IT uses StallAwareStopwatch and @tag("slow") as CLAUDE.md requires).

Points to consider

  1. Check-then-wait is not atomic. If removal happens during an RYW wait that began while the node was still a member, that read still blocks the full quorum timeout and then degrades to EVENTUAL. The invariant holds only for reads that arrive after removal is observed. Re-checking membership on timeout, or failing the wait early on removal, would close it. A follow-up is fine, but "Known gaps: None" is slightly overstated.
  2. Degrade-on-timeout. RYW degrading to EVENTUAL after the timeout and serving data missing the write is the underlying hazard. Is that still intended for member nodes?
  3. Duplicate lookup (nit). getTrustedAppliedIndex is read here and again inside waitForAppliedIndex. It is cheap.
  4. Brittle assertion. Issue7641...Test uses containsExactly on the whole call log, so it breaks whenever a new recorded call is added. Asserting the relative order of the two relevant calls would be sturdier.
  5. Style nit. Constant alignment in Issue9590ReadConsistencyGateOnRemovedNodeTest is uneven.

No security or performance concerns. The fast refusal also stops removed nodes from tying up threads for the quorum timeout.

🤖 Generated with Claude Code

… during its wait; relax the #7641 order assertion

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review of #9605

Overall this looks good. The fix is small and well scoped, and it follows the shape of #9510.

What works

  • The membership check runs only on the two paths that can block (a RYW bookmark ahead of the applied index, and LINEARIZABLE). EVENTUAL reads and already-satisfied RYW reads pay nothing new.
  • The re-check after waitForAppliedIndex closes the 'removed while waiting' window. A member that timed out still degrades to EVENTUAL as documented.
  • It fails open when the configuration is unknown, which is consistent with HA: a node removed from the Raft configuration may still accept writes and stall each one for the quorum timeout (follow-up to #9411) #9510.
  • It throws NeedRetryException, so HTTP 503, Bolt and gRPC get the retryable mapping for free.
  • Coverage is good. The unit test covers the branch matrix, including both race orderings, and the IT runs against real Ratis. The IT uses StallAwareStopwatch.assertGaveUpWithin, which is the right choice under CLAUDE.md. It is tagged @Tag("slow").

Minor points (none blocking)

  1. In RaftReplicatedDatabase.java (the RYW branch), getTrustedAppliedIndex is read twice around the wait, and a third time inside the wait itself. Fine for correctness. A one-line comment saying the second read is deliberately fresh would stop a future 'dedupe' from breaking it.
  2. The LINEARIZABLE branch checks membership on every linearizable read, including on healthy members. If isRemovedFromConfiguration() reads the Ratis configuration each time, this adds per-read cost on a path that already pays for a read-index round trip, so it is probably negligible. Please confirm it does not take a lock or allocate a peer collection.
  3. The Issue7641 assertion now uses containsSubsequence(...).containsOnlyOnce(...). That is reasonable, but it weakens the 'exactly these calls' guarantee. It would be worth filtering the recorded methods to the two of interest and keeping containsExactly.
  4. In the IT, leftIndex is set before the removal completes, so getServerToCheck excludes that server even if leaveCluster throws. That is harmless for teardown.
  5. The PR notes that the adversarial pass was not run by a separate agent. Given that the race-window re-check is the subtle part, a second look at the removed-former-leader transition (still leader briefly after removal) is worth it. LINEARIZABLE is covered because it refuses regardless of role. RYW on a not-yet-stepped-down leader skips the wait, which is the same as the existing behavior.

No security concerns. The change only refuses requests, and the message leaks nothing sensitive. I did not run the tests locally.

…lter the #7641 call log to the calls under test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review

Overall this is a small, well-scoped fix. The gate sits in the one place all read paths go through, and the cost on the hot paths is nil: EVENTUAL reads and RYW reads that are already satisfied never check membership.

What looks good

  • The getTrustedAppliedIndex < readAfterIndex pre-check means the membership lookup is skipped when no wait is needed.
  • The re-check after the wait closes the race where a node is removed mid-wait and then serves data missing the bookmarked write. The comment explaining why the applied index is read twice is useful.
  • The NeedRetryException maps to 503, Bolt TransientError and gRPC ABORTED, so clients retry on a member. The message names the reason and the remedies.
  • Fail-open when the configuration is unknown follows the HA: a node removed from the Raft configuration may still accept writes and stall each one for the quorum timeout (follow-up to #9411) #9510 rule, and there is a test for it.
  • Tests cover the branch matrix in a fast unit test (leader/follower, removed/member, removed during the wait, removed after catching up) plus a real-Ratis IT. The IT uses StallAwareStopwatch.assertGaveUpWithin and no hard-coded ports, as CLAUDE.md asks.

Minor suggestions (non-blocking)

  1. A removed node that is still within its quorum-timeout wait will block for the full timeout if it is removed only after the wait starts. That is inherent in the design, but you could mention it in the Javadoc. The refusal is only immediate if removal was already visible when the read arrived.
  2. The post-wait re-check also runs for members that merely timed out. That costs one extra getTrustedAppliedIndex plus one isRemovedFromConfiguration call, only on the already-slow timeout path. That is fine, but a short note that this is the intended degrade-to-EVENTUAL path would help.
  3. Issue7641...Test was loosened to filter the recorded calls. That is reasonable, but it now hides any unexpected extra calls. Consider asserting the full list including isRemovedFromConfiguration instead, if the call is deterministic there.
  4. The IT is tagged slow, which fits. If it is not picked up in the CI lane that runs ha-raft ITs, check that it runs somewhere.
  5. The PR notes that the adversarial pass was not run by a separate agent. Nothing stands out to me, but a second look at the LINEARIZABLE leader path would be cheap. The test for a leader that left the cluster covers it.

I found no security or performance problems. Looks good to merge once CI is green.

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.56%. Comparing base (d0fb2ed) to head (5eb59aa).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...rcadedb/server/ha/raft/RaftReplicatedDatabase.java 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9605      +/-   ##
============================================
- Coverage     77.56%   77.56%   -0.01%     
- Complexity     4338     4364      +26     
============================================
  Files          2165     2166       +1     
  Lines        223158   223278     +120     
  Branches      47870    47892      +22     
============================================
+ Hits         173097   173185      +88     
- Misses        31762    31786      +24     
- Partials      18299    18307       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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: READ_YOUR_WRITES / LINEARIZABLE reads on a node removed from the Raft configuration wait the full timeout (follow-up to #9510)

1 participant