Skip to content

refactor(ha-raft): split ArcadeStateMachine and RaftHAServer by responsibility - #12300

Merged
lvca merged 1 commit into
mainfrom
refactor/ha-raft-state-machine-split
Nov 16, 2026
Merged

lvca merged 1 commit into
mainfrom
refactor/ha-raft-state-machine-split

Conversation

@lvca

@lvca lvca commented Nov 16, 2026

Copy link
Copy Markdown
Member

What

Splits the two largest HA classes into smaller classes with one responsibility each. This is a behaviour-preserving refactor: method bodies are moved as they are, with no logic change.

Class Before After New classes
ArcadeStateMachine 11,045 4,631 20
RaftHAServer 8,693 4,409 13

From ArcadeStateMachine:

Area Classes
Applying log entries SchemaEntryApplier, ConfigurationEntryApplier, DropDatabaseApplier, SecurityEntryApplier, CommittedEntryDecoding
Bootstrap BootstrapInstaller, BootstrapBaselines, BootstrapPasses, BootstrapDivergenceCheck, UnverifiedCopyReverifier
Resync and quarantine SnapshotResync, DatabaseQuarantine, DatabaseReplacement, LeaderSnapshotInstall
State and retries AppliedIndexFile, EntryApplyRetry, SchemaChangeHistory, ExclusiveDatabaseWindows, CriticalHaltHandler, MaterializedViewRecovery

From RaftHAServer: PeerEndpoints, PeerCapabilityMonitor, PeerChannelRecovery, MisdirectedRaftRequests, RatisInPlaceRestart, RaftStorageFiles, AppliedIndexWaits, TrafficReadiness, PeerAdmission, ReplicationStatistics, RaftTransportSetup, VoterQuarantineCheck, StepDownTargets.

All new classes are package-private, in com.arcadedb.server.ha.raft.

How

  • Each new class holds a back-reference to its owner for shared state. Calls back into the owner go through that reference, so test subclasses that override them still intercept them.
  • Logging still passes the owner, so logger names (and subclass names in logs) are unchanged.
  • Members overridden by test subclasses (FakeArcadeStateMachine, FakeRaftHAServer), read by reflection in tests, or keyed by census tests stay in place.
  • Methods called from outside the class keep a one-line delegator on the owner. References to moved static members point at the new class.

Edits that are not pure moves

  • Visibility raised from private to package-private only where a call now crosses a class boundary.
  • ArcadeStateMachine.updateLastAppliedTermIndexAfterInstall(...) bridges to the protected Ratis 2-arg updateLastAppliedTermIndex, which the moved snapshot-install code can no longer reach.
  • The emergency-stop lambda in CriticalHaltHandler is set in the constructor, since a field initializer cannot read the back-reference.
  • Stack-frame checks in Issue7475RepairExcludedByPauseTest and HaRemovedNodeIT name the new owning class; static and method references in tests were repointed the same way.

Verification

  • mvn -o -pl ha-raft -am verify -DskipITs -Dtest='com/arcadedb/server/ha/raft/*Test,com/arcadedb/server/ha/raft/**/*Test' -Dsurefire.failIfNoSpecifiedTests=false -DexcludedGroups=benchmark,slow,vector: 3,490 tests, 1 failure (Issue7549CapabilityMonitorInEveryRoleTest.concurrentStartsCreateExactlyOneMonitor, which fails the same way on main).
  • mvn -o -pl census -am verify -DskipITs -Dtest='com/arcadedb/census/*Test' -Dsurefire.failIfNoSpecifiedTests=false -DexcludedGroups=benchmark,slow,vector: 53 tests, 0 failures.
  • ha-integration-tests and the ha-raft *IT classes were not run locally.

…nsibility

ArcadeStateMachine goes from 11,045 to 4,631 lines and RaftHAServer from
8,693 to 4,409, with the moved code in 33 package-private classes, each with
one responsibility. Method bodies are moved as they are; the new classes keep
a back-reference to their owner for shared state, and log through the owner so
logger names do not change.

Members overridden by test subclasses, read by reflection in tests, or keyed
by census tests stay in place. Methods called from outside keep a one-line
delegator on the owner; references to moved static members point at the new
class.
@mergify

mergify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

@lvca
lvca merged commit 56c93c9 into main Nov 16, 2026
18 of 20 checks passed
@codacy-production

codacy-production Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 high · 8 medium

Alerts:
⚠ 10 issues (≤ 0 issues of at least minor severity)

Results:
10 new issues

Category Results
BestPractice 7 medium
ErrorProne 2 high
Complexity 1 medium

View in Codacy

🟢 Metrics 1795 complexity

Metric Results
Complexity 1795

View in Codacy

🟢 Coverage ∅ diff coverage · -4.31% coverage variation

Metric Results
Coverage variation ✅ -4.31% coverage variation
Diff coverage ∅ diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (7fffe29) 286055 252489 88.27%
Head commit (52fe705) 320068 (+34013) 268724 (+16235) 83.96% (-4.31%)

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 (#12300) 0 0 ∅ (not applicable)

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%

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.

@github-actions github-actions Bot added ha High availability / replication (Raft) no-issue The PR links no issue severity:minor Cosmetic, documentation, edge case, or a workaround exists triage:needs-changes PR triage: the PR needs changes before it can merge labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Triage: triage:needs-changes · severity:minor · areas: ha · no-issue

Triage review

I could not review this PR in full. The diff is about 1.9 MB and was truncated (diffTruncated: true). I did not read the moved method bodies, so I can't confirm that nothing but code moved. A 15,000-line move is the kind of change where a behavior change is easy to miss.

What I can say from the description and file list

  • This is a refactor with no linked issue, so I rated it severity:minor.
  • The stated approach is sound. The new classes are package-private. Back-references to the owner keep test-subclass overrides and logger names working. The classes that tests override or read by reflection stay in place.
  • The edits that are not pure moves are small and listed:
    • updateLastAppliedTermIndexAfterInstall bridges to the protected Ratis method.
    • The CriticalHaltHandler emergency-stop lambda is now set in the constructor.
    • Some members went from private to package-private.
      These are the spots to check line by line.
  • The PR touches engine/src/test/java/com/arcadedb/engine/WalFileCorruptionTest.java. That file is outside ha-raft and isn't mentioned in the description. Please say why it changed, or drop the change if it is unrelated.

Requested before merge

  1. Run the HA integration tests. The description says ha-integration-tests and the ha-raft *IT classes were not run. Those exercise snapshot install, bootstrap, in-place restart, leadership transfer and quarantine. Those are the paths this PR moves, so unit tests are not enough. Please run them, or point to a green CI run, and report the result.
  2. Check the one failing unit test. [redacted].concurrentStartsCreateExactlyOneMonitor is said to fail on main too. PeerCapabilityMonitor is one of the extracted classes, so please confirm the failure is identical before and after (same assertion, same frequency). A link to the failing run on main would settle it.
  3. Split the PR if you can. Separate PRs for ArcadeStateMachine and for RaftHAServer would let reviewers check each move properly. Another option is to share a move-detection diff (for example git diff --color-moved=dimmed-zebra) so the moved lines and the real edits can be told apart.
  4. Recheck concurrency-sensitive state after the move. For each extracted class, confirm that fields which were volatile, guarded by a lock, or accessed under synchronized on the owner still have the same visibility and locking now that they are reached through the back-reference. Check that the final and constructor-ordering behavior is unchanged too.
  5. Confirm the census tests. CLAUDE.md says census tests range over compiled call sites. The description says the census module passed (53 tests). Please confirm that the census tests which key on ArcadeStateMachine or RaftHAServer still reach the moved code and are not now passing because they scan nothing.

I saw no sign of a security issue in the metadata or the file list. I could not check the diff content, so a maintainer who can read the full diff should do the final pass.

1 value(s) redacted.

@lvca
lvca deleted the refactor/ha-raft-state-machine-split branch November 16, 2026 14:50
@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.54458% with 1062 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.29%. Comparing base (7fffe29) to head (52fe705).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...m/arcadedb/server/ha/raft/PeerChannelRecovery.java 22.70% 141 Missing and 2 partials ⚠️
...m/arcadedb/server/ha/raft/RatisInPlaceRestart.java 43.24% 86 Missing and 19 partials ⚠️
...om/arcadedb/server/ha/raft/SchemaEntryApplier.java 70.71% 63 Missing and 36 partials ⚠️
...adedb/server/ha/raft/UnverifiedCopyReverifier.java 60.74% 38 Missing and 15 partials ⚠️
...om/arcadedb/server/ha/raft/BootstrapInstaller.java 80.22% 33 Missing and 19 partials ⚠️
...arcadedb/server/ha/raft/PeerCapabilityMonitor.java 80.60% 24 Missing and 27 partials ⚠️
...om/arcadedb/server/ha/raft/DatabaseQuarantine.java 72.06% 23 Missing and 27 partials ⚠️
...va/com/arcadedb/server/ha/raft/SnapshotResync.java 82.18% 28 Missing and 21 partials ⚠️
...adedb/server/ha/raft/MaterializedViewRecovery.java 32.81% 34 Missing and 9 partials ⚠️
...adedb/server/ha/raft/BootstrapDivergenceCheck.java 56.84% 35 Missing and 6 partials ⚠️
... and 23 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12300      +/-   ##
==========================================
+ Coverage   80.28%   80.29%   +0.01%     
==========================================
  Files        2493     2526      +33     
  Lines      286055   286460     +405     
  Branches    63078    63085       +7     
==========================================
+ Hits       229653   230022     +369     
- Misses      33606    33656      +50     
+ Partials    22796    22782      -14     

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

shaunpatterson added a commit to shaunpatterson/arcadedb that referenced this pull request Nov 16, 2026
Ports the fix onto the ArcadeData#12300 split: the replay check lives in SchemaEntryApplier, the
previous-session positions in AppliedIndexFile, and the forget calls in BootstrapInstaller
and DropDatabaseApplier.
lvca added a commit to shaunpatterson/arcadedb that referenced this pull request Nov 17, 2026
Conflict in RaftHAServer: ArcadeData#12300 moved restartRatis into RatisInPlaceRestart. The publication gate stays in RaftHAServer; the restart now replaces the state machine through replaceStateMachineBetweenPublications from RatisInPlaceRestart, with the same ratisCloseTimeoutMs bound.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ha High availability / replication (Raft) no-issue The PR links no issue severity:minor Cosmetic, documentation, edge case, or a workaround exists triage:needs-changes PR triage: the PR needs changes before it can merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant