Skip to content

fix(#8898): keep Ratis's JVM-pause close out of reach and log in-place restarts loudly - #8902

Merged
robfrank merged 4 commits into
mainfrom
fix/8898-ha-jvm-pause-ratis-restart-never-recovers
Oct 2, 2026
Merged

robfrank merged 4 commits into
mainfrom
fix/8898-ha-jvm-pause-ratis-restart-never-recovers

Conversation

@robfrank

@robfrank robfrank commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #8898

Summary

A follower paused for more than 60s had its Raft division closed by Ratis's own JVM-pause monitor (raft.server.close.threshold). ArcadeDB then restarted Ratis in place, but the follower never took another append, and the health monitor ended up reformatting its storage. This PR removes that trigger. The new arcadedb.ha.jvmPauseCloseThresholdMs defaults to 0, which keeps the Ratis close out of reach, so long-pause recovery stays with ArcadeDB's own monitors. A leader still steps down on a long pause, because that uses a separate threshold. A positive value restores the stock Ratis close.

restartRatis also stops hiding failures. An error closing the old server is logged at WARNING instead of FINE. A successful restart is logged at INFO instead of HALog BASIC. A new WARNING fires when the old server is not CLOSED after close().

What this does not fix: why an in-place restart can leave the leader appending to a CLOSED division is still unproven. That is tracked in #8900 together with the regression IT. The needless stale-term reformat is tracked in #8901.

Test plan

  • RaftPropertiesBuilderTest: jvmPauseCloseThresholdIsOutOfReachByDefault, jvmPauseCloseThresholdCanBeRestoredToACustomValue (fail on main by construction, since Ratis's stock value is 60s)
  • RaftPropertiesBuilderTest + HealthMonitorTest: 56/56 pass
  • RaftHealthMonitorRecoveryIT, Issue4839RecoveryRewiresStateMachineIT pass (both log the new INFO restart line)

Coverage

Invariant: the Ratis JVM-pause monitor cannot close the division unless the operator opts in.

grep -rn "RaftPropertiesBuilder.build(" ha-raft/src/main e2e-ha/src:

RaftHAServer.java:1390   (startup)
RaftHAServer.java:2296   (restartRatis)
Entry point Fixed Test
startup RaftPropertiesBuilder.build yes RaftPropertiesBuilderTest
restartRatis RaftPropertiesBuilder.build yes same builder, same test

Known gaps

Adversarial pass

Review cycles

Cycle Head Changes Bot outcome
1 e30c857 initial LGTM, 5 non-blocking suggestions
2 0915a1b config description reflowed, "0 or negative disables", 0/-1 test LGTM, 6 non-blocking
3 27adca0 named JVM_PAUSE_CLOSE_DISABLED constant, tests assert against it LGTM, 5 non-blocking
4 3dfa7e3 neutral wording for the old-server-not-closed WARNING LGTM, 6 non-blocking

Deferred items

Final state

max-cycles-reached (4/4, every cycle LGTM with only non-blocking suggestions)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a server setting to control when a long JVM pause causes a Raft node to close its division. The default value of 0 disables pause-triggered closure; positive values set the threshold in milliseconds.
    • Long JVM pauses may still cause a leader to step down, and the health monitor continues to assess whether recovery is needed.

…e restarts loudly

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robfrank robfrank added bug ha High availability / replication (Raft) labels Oct 2, 2026
@mergify

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

@claude

claude Bot commented Oct 2, 2026

Copy link
Copy Markdown

Review

Small, focused change, and the PR description is honest about what it does and does not fix. Imports (LifeCycle, Level, TimeDuration, TimeUnit) are all present and the 3650-day value fits comfortably in a long of nanoseconds. No blocking issues found.

What looks good

  • The default of 0 mapping to a 10-year threshold is a pragmatic workaround for TimeDuration having no "disabled" value, and the leader step-down path (separate threshold) is untouched.
  • Both build() call sites (startup and restartRatis) go through the same builder, so the setting applies uniformly.
  • Raising the restart failure logs from FINE to WARNING/INFO is a real observability improvement.

Suggestions (non-blocking)

  1. Negative values: jvmPauseCloseMs > 0 ? ... : 10y silently treats negatives like 0. That is reasonable, but the config description could say "0 or negative disables".
  2. Config description formatting: in GlobalConfiguration, storage. The default of 0 disables \ leaves an odd line break in the middle of a sentence. Reflow it. The text also carries a lot of incident narrative (HA: after a JVM pause past Ratis's 60s close threshold, an in-place Ratis restart never recovers the follower (appends hit a CLOSED division, then a needless storage reformat) #8898); consider keeping the description to what the setting does, and leaving the history to the PR and issue.
  3. Test strength: jvmPauseCloseThresholdIsOutOfReachByDefault asserts >= 365 days. That is fine, but it only proves the property was set, not that Ratis's JVM-pause monitor honors it. The PR already acknowledges the regression IT is deferred to HA: in-place Ratis restart can leave the leader appending to a CLOSED division (restart verification, leader-side appender rebuild, regression IT) #8900, which is acceptable. A 0 and a negative-value case in the unit test would cheaply pin the branch.
  4. Misleading WARNING: as the code comment admits, the new "not CLOSED after close()" warning cannot fire in the reported scenario (Ratis already closed it, so close() is a no-op that reports CLOSED). It still has value for other cases, but the log text ("the leader may keep appending to it") could mislead operators who see it. That is minor.
  5. Safety-net trade-off: disabling the Ratis close by default changes behaviour for every deployment, not just the one in HA: after a JVM pause past Ratis's 60s close threshold, an in-place Ratis restart never recovers the follower (appends hit a CLOSED division, then a needless storage reformat) #8898. The PR accepts this, relying on HealthMonitor for stuck/CLOSED detection. Worth a release-note line, and a user-facing mention in the HA docs, so operators who relied on the 60s close know the knob exists.

Conventions: tests use the assertThat(...) style and the change adds no dependencies and no System.out. Nothing in CLAUDE.md is violated.

Overall: LGTM once the minor description cleanup is considered.

@codacy-production

codacy-production Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

🟢 Coverage 50.00% diff coverage

Metric Results
Coverage variation Report missing for a4a69bb1
Diff coverage ✅ 50.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a4a69bb) Report Missing Report Missing Report Missing
Head commit (3dfa7e3) 239272 188459 78.76%

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 (#8902) 12 6 50.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.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
ha-raft/CLAUDE.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: c34192dc-2464-4cae-a702-e533a5fce590

📥 Commits

Reviewing files that changed from the base of the PR and between a4a69bb and 3dfa7e3.

📒 Files selected for processing (4)
  • engine/src/main/java/com/arcadedb/GlobalConfiguration.java
  • ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftHAServer.java
  • ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftPropertiesBuilder.java
  • ha-raft/src/test/java/com/arcadedb/server/ha/raft/RaftPropertiesBuilderTest.java

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


📝 Walkthrough

Walkthrough

The change adds a configurable JVM-pause close threshold for Ratis and updates lifecycle checks and logs during Ratis restart.

Changes

HA pause recovery

Layer / File(s) Summary
Configure JVM-pause close threshold
engine/src/main/java/com/arcadedb/GlobalConfiguration.java, ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftPropertiesBuilder.java, ha-raft/src/test/java/com/arcadedb/server/ha/raft/RaftPropertiesBuilderTest.java
Adds a server setting for the Ratis close threshold. Positive values are applied in milliseconds; zero or negative values use a ten-year disabled duration. Tests cover the default, nonpositive values, and a positive configured value.
Check and report Ratis restart
ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftHAServer.java
The restart path warns if the old server is not CLOSED, logs close exceptions at WARNING, and reports whether storage was reformatted or recovered.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: lvca

Merge Risk: ⚪ Minimal · up to 3dfa7

No actionable merge-blocking issue is identified. The threshold behavior is covered by the reported tests, and the restart changes improve reporting.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 3dfa7

The change is narrowly scoped to pause recovery and preserves the existing replacement sequence. No new privilege expansion or attack path was established. Independent leader fencing during long pauses remains partially verified, and restoring the previous policy is only established when a new server instance is constructed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed policy affects each configured HA node’s division lifecycle and, through replication and recovery, its existing Raft group. Configuration authority over the node can select its closure policy; the inspected change does not itself create a new remote entrypoint.

Trust Boundaries and Controls

  • observed — The inspected code changes a lifecycle policy, not peer identity. Its documented security-relevant assumption is that a paused leader still steps down independently of division closure. That assumption remains a dependency-level evidence gap, not a verified control failure.

Resilience and Maintainability Implications

  • observed — Existing failure containment remains: recovery attempts are serialized, shutdown suppresses recovery, failed reconstruction increments a counter, and exhausting the restart budget triggers server shutdown. These controls do not establish that old RPC endpoints are fenced after close or that a reconstructed follower accepts appends.

Hardening Proposals

  • proposed — Document when threshold edits become effective and validate the pinned dependency’s leader step-down behavior during prolonged pauses. Treat post-restart append recovery and old-endpoint fencing as separate validation goals; neither is demonstrated by the new success or lifecycle logs.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #8898 requires more than the threshold change. This PR implements the configurable HA_JVM_PAUSE_CLOSE_THRESHOLD_MS setting, disables the Ratis close by default, and adds unit tests. It also im… Implement the remaining #8898 recovery behavior. At minimum, ensure restartRatis waits for and validates old-server termination before starting a new server, prevent reformat for a follower with no post-restart append, rebuild the leader …
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both primary changes: disabling Ratis JVM-pause closure by default and improving in-place restart logging.
Description check ✅ Passed The description is detailed and relevant. It explains the change, motivation, related issues, testing, coverage, known gaps, and deferred work. It does not use the template headings exactly and does n…
Out of Scope Changes check ✅ Passed The changed configuration, Ratis property mapping, restart logging, and related unit tests all address the active issue #8898. No unrelated implementation change is established. Closed dependency issu…
Full details: Linked Issues check

Explanation

Issue #8898 requires more than the threshold change. This PR implements the configurable HA_JVM_PAUSE_CLOSE_THRESHOLD_MS setting, disables the Ratis close by default, and adds unit tests. It also improves restart logging. However, restartRatis still starts the new server when oldServer is not CLOSED; it does not wait for full termination or fail the restart. The PR does not implement the stale-term reformat guard, leader appender or channel rebuild, or the requested recovery regression IT. Closed issues #3 and #4 provide no requirements.

Resolution

Implement the remaining #8898 recovery behavior. At minimum, ensure restartRatis waits for and validates old-server termination before starting a new server, prevent reformat for a follower with no post-restart append, rebuild the leader appender after persistent ServerNotReadyException, and add the requested catch-up, no-reformat, continued-write regression test. Alternatively, link this PR only to a narrower active issue that contains the threshold objective.

  • 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
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

…egative branch

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

claude Bot commented Oct 2, 2026

Copy link
Copy Markdown

Review

Small, focused change. Overall LGTM, with a few non-blocking notes.

What I checked

  • RaftPropertiesBuilder.build is the single place both the startup path and restartRatis build properties, so the new threshold covers both entry points (matches the PR's coverage table).
  • 3650 days as "out of reach" is about 3.15e17 ns, which fits in a long of nanoseconds, so there is no overflow risk if Ratis converts the TimeDuration internally.
  • Imports (LifeCycle, TimeDuration, TimeUnit) are already present in both files. Style follows CLAUDE.md (single-statement if without braces, final locals, no fully qualified names).
  • Tests cover default, zero/negative, and a custom positive value. The zero/negative case is a good addition over what the PR description lists.

Notes / suggestions

  1. Safety-net trade-off (medium). Defaulting to "never close on long pause" changes behaviour for every HA deployment, not just the reported scenario. It relies on HealthMonitor catching a node that Ratis would previously have closed. Since HA: in-place Ratis restart can leave the leader appending to a CLOSED division (restart verification, leader-side appender rebuild, regression IT) #8900 admits that the restart path itself is still unproven, it would be good to have an IT (or at least a HealthMonitorTest case) showing that a node paused >60s with the close disabled actually rejoins and catches up. The PR cites only the existing recovery ITs, which do not exercise a long JVM pause with the close disabled.
  2. Magic number. TimeValue 3650 days is inlined in the ternary. A named constant (e.g. JVM_PAUSE_CLOSE_DISABLED) in RaftPropertiesBuilder would make the intent self-documenting and let the test refer to it instead of the >= 365 days literal.
  3. Docs. The new arcadedb.ha.jvmPauseCloseThresholdMs setting is only described in GlobalConfiguration. If the HA docs list tunables or a release-notes/behaviour-change section exists, a line there would help, since operators who relied on the 60s Ratis close will see different behaviour on upgrade.
  4. New WARNING in restartRatis. As the PR itself notes, it cannot fire in the reported scenario because Ratis already closed the proxy. That is fine as a diagnostic, but it has no test. A small unit test with a mocked RaftServer whose getLifeCycleState() is not CLOSED after close() would lock it in, or consider deferring it to HA: in-place Ratis restart can leave the leader appending to a CLOSED division (restart verification, leader-side appender rebuild, regression IT) #8900 where the regression IT lands.
  5. Log level. Raising the successful restart from HALog.BASIC to INFO is reasonable (restarts are rare and operationally important). Just confirm restartRatis cannot be called in a tight loop that would flood the log. restartFailureCount suggests it is bounded.
  6. Minor. Long.class, 0L with getValueAsLong is fine. The description says "0 or a negative value disables", and the code does > 0, which is consistent.

No security or performance concerns. Nothing here blocks merge; item 1 is the one I would most like to see addressed (here or in #8900).

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

claude Bot commented Oct 2, 2026

Copy link
Copy Markdown

Review

Small, focused change. Imports are present, both `build()` call sites (startup and `restartRatis`) go through the same builder, and the leader step-down path (separate threshold) is untouched. The tests cover default, zero/negative and custom values, and follow the `assertThat` style. No dependencies, no `System.out`. No blocking issues.

Suggestions (non-blocking)

  1. Default behaviour change for all deployments: the default flips from Ratis's 60s close to "never", so every cluster loses that safety net, not only the one in HA: after a JVM pause past Ratis's 60s close threshold, an in-place Ratis restart never recovers the follower (appends hit a CLOSED division, then a needless storage reformat) #8898. The PR accepts this and relies on `HealthMonitor`, but until HA: in-place Ratis restart can leave the leader appending to a CLOSED division (restart verification, leader-side appender rebuild, regression IT) #8900 proves the restart path works, a node that was previously recycled by the 60s close may now sit stuck until the health monitor notices. Worth a release note and a line in the HA docs mentioning `arcadedb.ha.jvmPauseCloseThresholdMs`.
  2. Misleading WARNING text: "the leader may keep appending to it instead of the restarted one" asserts a consequence that is unproven (per the PR's own caveats). Consider a neutral wording such as "Old Ratis server is %s after close(); restart proceeds anyway".
  3. `JVM_PAUSE_CLOSE_DISABLED` sentinel: 3650 days in nanoseconds (~3.15e17) fits in a `long`, but Ratis may convert the value (e.g. to millis or via `Duration`) elsewhere. A quick check that `RaftServerConfigKeys.closeThreshold(props)` plus `JvmPauseMonitor` startup does not overflow or reject it in an IT (even the existing recovery ITs starting a server with the default) would settle that; the PR says those ITs pass, so this is likely fine.
  4. Config description: keep it to what the setting does, and make sure the multi-line text block reflows cleanly (the `\` line continuations are easy to get wrong).
  5. Log level: the restart success line is now INFO on every restart, which is the right call for a rare, operator-relevant event.

LGTM once point 1 (docs/release note) is considered.

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

claude Bot commented Oct 2, 2026

Copy link
Copy Markdown

Review

Small, focused change, and the tests are honest about what they cover. No blockers. Notes below.

What looks good

Points to consider

  1. Behavior change for all deployments, not just the reported one. Default 0 silently removes a Ratis safety net for every user. The trade-off is argued well in the description, but it is worth a line in the docs or release notes, because operators who relied on the stock 60s close will not notice the change otherwise. I found no docs mention of the new key in the repo.
  2. Unproven root cause. The PR says the in-place restart failing to recover is still unproven (HA: in-place Ratis restart can leave the leader appending to a CLOSED division (restart verification, leader-side appender rebuild, regression IT) #8900). If a long pause then leaves the division in a bad state without Ratis closing it, nothing in this PR covers that case beyond the health monitor. Please confirm in HA: in-place Ratis restart can leave the leader appending to a CLOSED division (restart verification, leader-side appender rebuild, regression IT) #8900 that the health monitor does detect a follower that is alive but stuck after a long pause, since the safety argument depends on it.
  3. Negative-value semantics. The key is Long, and 0 or negative both mean "disabled". That is tested and documented, so fine. A positive value below Ratis's leader step-down threshold would make the close fire before the step-down. That is an operator choice, but one sentence in the config description would help.
  4. The new "not CLOSED after close()" WARNING is acknowledged to be unable to fire in the reported scenario. It is cheap and harmless, but it has no test. If LifeCycle state can be stubbed or injected easily, a small test would stop it from rotting. If not, ignore this.
  5. Test coverage. The three builder tests are good and use the preferred assertThat style. They only assert the property value, not that Ratis actually keeps the division open through a long pause. Since HA: in-place Ratis restart can leave the leader appending to a CLOSED division (restart verification, leader-side appender rebuild, regression IT) #8900 tracks the regression IT, that is acceptable for now, but this PR should not be read as a full regression test for HA: after a JVM pause past Ratis's 60s close threshold, an in-place Ratis restart never recovers the follower (appends hit a CLOSED division, then a needless storage reformat) #8898.
  6. Minor: the Javadoc comments reference issue numbers (Issue #8898). CLAUDE.md prefers comments that explain the why without task references, since they rot. The reasoning is already in the comments, so the issue prefix could be dropped.

Performance and security: none affected. This is a config-time change with no hot-path code.

Overall: LGTM once the docs and release-note point (1) and the health-monitor confirmation (2) are addressed or explicitly deferred.

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.41%. Comparing base (802233c) to head (3dfa7e3).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...java/com/arcadedb/server/ha/raft/RaftHAServer.java 0.00% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8902      +/-   ##
============================================
- Coverage     76.41%   76.41%   -0.01%     
- Complexity     3810     3812       +2     
============================================
  Files          2106     2106              
  Lines        206663   206672       +9     
  Branches      43569    43572       +3     
============================================
+ Hits         157930   157931       +1     
- Misses        31729    31745      +16     
+ Partials      17004    16996       -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

bug ha High availability / replication (Raft)

Projects

None yet

1 participant