Skip to content

fix(#11989): the Raft log compaction forces the data files on its own thread before the checkpoint - #11995

Merged
lvca merged 4 commits into
ArcadeData:mainfrom
shaunpatterson:fix/11989-checkpoint-sync-off-apply-thread
Nov 23, 2026
Merged

lvca merged 4 commits into
ArcadeData:mainfrom
shaunpatterson:fix/11989-checkpoint-sync-off-apply-thread

Conversation

@shaunpatterson

@shaunpatterson shaunpatterson commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11989.

Problem

Since #11519 (issue #11258), ArcadeStateMachine.takeSnapshot() forces the data files of every open database before it writes the snapshot marker. Ratis runs takeSnapshot() on its StateMachineUpdater thread, which is the apply thread, so every commit of the node waits while the files written since the previous checkpoint are forced. The periodic log compaction triggers one checkpoint per snapshotInterval. On an application's 3-node ingest, the leader's JFR showed the compaction waiting 0.24-1.63 s for the checkpoint once per 20-minute run. During the longest one, the group committer and 12 commitTransaction calls were parked for up to 1.57 s.

Change

  • RaftLogCompactionTarget.triggerSnapshot() calls ArcadeStateMachine.syncDataFilesAheadOfCheckpoint(creationGap) on the scheduler's thread before it asks Ratis for the snapshot. That is the same syncDataFilesOfOpenDatabases() pass: it waits for the pages pending in the asynchronous flush and then forces the files written since their last fsync.
  • takeSnapshot() still runs its own pass, so the guarantee of the marker does not depend on the new call. PaginatedComponentFile.forceIfModified() skips the files that are clean by then, so the apply thread only forces what was written between the two passes.
  • The early pass is skipped when Ratis is going to answer the request without a checkpoint (fewer than creationGap entries applied since the latest snapshot, the test of RaftServerImpl.takeSnapshotAsync), so a tick below the gap pays no fsync.
  • A failure of the early pass is logged at FINE, and nothing it throws keeps the tick from asking for the checkpoint. The checkpoint's own pass reports it at WARNING, as before.
  • The RaftLogCompactionScheduler Javadoc said a snapshot is "cheap enough"; it now names what the snapshot costs and where that cost is paid.

The pre-install purge (compactRaftLogBeforeSnapshotInstall) is unchanged. It runs only under disk pressure, with a short timeout on purpose. It and the entry-count auto-trigger still force on the apply thread: #12587.

Test

RaftLogCompactionWiringIT (ha-raft, 3 nodes), theCompactionForcesTheDataFilesBeforeTheApplyThreadCheckpoints:

  • The leader commits 500 records and waits until the pages reach the files.
  • A TEST_BEFORE_CHECKPOINT_SYNC hook (Consumer<ArcadeStateMachine>, filtered to the leader's state machine) records which data files the apply thread still has to force when the checkpoint reaches its sync.
  • The test then calls the compaction target's triggerSnapshot(1).
  • On main the hook sees the database's files unsynced. With the change it sees none, and none owe the disk afterwards either.
  • aTickBelowTheCreationGapForcesNoDataFile calls triggerSnapshot(Long.MAX_VALUE): Ratis takes no checkpoint and the data files still owe their fsync. It fails with the gap test removed.

Results:

…s own thread before the checkpoint

- Since ArcadeData#11519 the checkpoint forces every open database's data files, on the Ratis StateMachineUpdater, which is the
  apply thread: every commit of the node waited for it, up to 1.6 s in an application's ingest.
- RaftLogCompactionTarget.triggerSnapshot() runs the same pass first, on the scheduler's thread; the checkpoint's own
  pass is unchanged and now only forces what was written in between. The early pass logs a failure at FINE.
- Issue11989CheckpointSyncsOffTheApplyThreadIT reads what the apply thread still had to force through a test hook.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f1a45fd-e368-4246-8c03-5ed1f279956a
Commits

Reviewing files that changed from the base of the PR and between 964f283 and 83bff69.

Files selected for processing: 4

  • ha-raft/src/main/java/com/arcadedb/server/ha/raft/ArcadeStateMachine.java
  • ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftHAServer.java
  • ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftLogCompactionScheduler.java
  • ha-raft/src/test/java/com/arcadedb/server/ha/raft/RaftLogCompactionWiringIT.java
  • 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

@mergify

mergify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@codacy-production

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

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.

@shaunpatterson

Copy link
Copy Markdown
Contributor Author

Validated in a real workload. The patched image is 26.12.1-SNAPSHOT (main 04efccfcd3) plus this change, together with #11969, #11977, #11987 and #11995. It ran one 18-minute ingest-and-evaluate run of an application on a 3-node cluster with JFR on every node. The baseline is 11 runs on the same cluster with the stock image.

The arcadedb-raft-log-compaction thread's wait for the checkpoint (RaftServerImpl.waitForReply <- takeLocalSnapshot) went from 238-1630 ms, once per stock run (7 runs measured), to 13-16 ms, twice per node in the patched run. The forcing now happens on the compaction thread before the request, so the apply thread, and every commit waiting on it, no longer carries it.

@github-actions

Copy link
Copy Markdown
Contributor

Triage: triage:lgtm · severity:minor · areas: ha · has-issue

The change is small and targeted, and it looks correct. I read the diff only and did not run it.

What it does: RaftLogCompactionTarget.triggerSnapshot() now forces the data files on the scheduler thread before it asks Ratis for the snapshot. takeSnapshot() still runs its own pass on the apply thread, so the durability guarantee of the marker does not depend on the early pass. Because forceIfModified() skips files that are already clean, the apply thread only forces what was written between the two passes.

Why it is safe:

  • The early pass cannot weaken the checkpoint. A failure in it is logged at FINE, and the checkpoint's own pass still logs at WARNING and returns INVALID_LOG_INDEX.
  • The null check on stateMachine is correct.
  • The new Level parameter on syncDataFilesOfOpenDatabases is a clean way to vary the log level.
  • The test hook is package-private and volatile, and the test resets it in @​AfterEach.

Test: [redacted] is a regression test. It asserts that the apply thread has no unsynced files left, using isModifiedSinceLastSync and newCompactionTargetForTesting. Both exist in the base branch. It follows the BaseRaftHATest fixture convention. It has no raw wall-clock assertions.

Minor notes (non-blocking):

  • The test hook is called on every takeSnapshot(). Its cost is one volatile read, which is negligible.
  • The Javadoc says "up to 1.6 s". That figure is measured on one application's ingest and may not hold elsewhere.

The linked issue is severity:minor, and a pause of at most about 1.6 s once per compaction interval fits that.

1 value(s) redacted.

@lvca lvca self-assigned this Nov 19, 2026
@lvca lvca added this to the 26.12.1 milestone Nov 19, 2026
lvca added 2 commits November 19, 2026 17:17
…y when Ratis will checkpoint

Builds on the early pass of the previous commit, which moves the checkpoint's
data-file forcing from the apply thread to the log compaction thread.

- The early pass ran on every tick, also when Ratis answers the request
  without a checkpoint because fewer than creationGap entries were applied
  since the latest snapshot. A node with a few writes below the gap paid a
  data-file fsync pass per snapshotInterval for a tick that purges nothing.
  It now applies the same test as RaftServerImpl.takeSnapshotAsync, on the
  same two indexes, and forces nothing below the gap.
- Nothing thrown by the early pass (a database closed or swapped under it)
  may keep the tick from asking for the checkpoint: it is caught and logged
  at FINE, the checkpoint forces what is open by then.
- The regression test moves into RaftLogCompactionWiringIT (same fixture,
  tagged slow) since main no longer keeps Issue*-named classes in ha-raft,
  with a second test for the gap. The Javadoc drops a figure measured on one
  workload.

The entry-count auto-trigger and the pre-install purge still force on the
apply thread: ArcadeData#12587.
@github-actions github-actions Bot added triage:needs-changes PR triage: the PR needs changes before it can merge and removed triage:lgtm PR triage: nothing blocking, ready for a maintainer labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

The approach is sound: forcing the data files on the scheduler thread before the apply-thread checkpoint, and skipping it below the creation gap. I found one problem that blocks the merge, plus two smaller ones.

Blocker: the test will not compile.

  • RaftLogCompactionWiringIT calls leader.newCompactionTargetForTesting() twice (diff lines 211 and 236). That method is not defined anywhere in the base branch's ha-raft/src, and the diff does not add it to RaftHAServer.
  • Please add it (package-private, in RaftHAServer) or use an existing way to reach the compaction target. Then build with mvn -o -pl ha-raft -am verify and run the IT.

Description does not match the diff.

  • The PR body describes a new [redacted], which is not in the diff. The change instead edits RaftLogCompactionWiringIT.
  • The body also describes triggerSnapshot() calling syncDataFilesAheadOfCheckpoint() with no argument. The code takes a creationGap parameter and skips the pass below the gap.
  • Please update the description so it matches what is actually tested.

Minor points.

  • syncDataFilesAheadOfCheckpoint duplicates Ratis's own gap check. It reads getLastAppliedTermIndex() and storage.getLatestSnapshot(), and its Javadoc admits the two can race. That is acceptable because the checkpoint still forces everything. A short note on what happens if Ratis's logic changes would help.
  • Where RaftLogCompactionScheduler's Javadoc was edited, one line is far over the file's wrap width. Please re-wrap it.
  • TEST_BEFORE_CHECKPOINT_SYNC is a static volatile hook, the same pattern as the existing test hooks, and @​AfterEach resets it. That is fine.
  • RaftLogCompactionWiringIT is tagged slow, which is appropriate.
  • I found no security concerns.

1 value(s) redacted.

@lvca

lvca commented Nov 19, 2026

Copy link
Copy Markdown
Member

On the review of 5cf9634: RaftHAServer.newCompactionTargetForTesting() is not added by this diff because it already exists on main (ha-raft/src/main/java/com/arcadedb/server/ha/raft/RaftHAServer.java, used by the existing compactionTargetResolvesTheRaftStorageVolumeForTheFreeSpaceProbe of the same class), so the test compiles. mvn -o -pl ha-raft -am verify -DskipITs=false on RaftLogCompactionWiringIT (4), RaftPeriodicSnapshotCompactionIT (2), RaftLogCompactionSchedulerTest (17) and AppliedIndexCheckpointTest (36): all green. Each new test fails with its half of the change removed. The description now matches the diff, the scheduler Javadoc is re-wrapped and the gap test says what a wrong answer costs (83bff69). The auto-trigger and pre-install paths are tracked in #12587.

@github-actions github-actions Bot added triage:lgtm PR triage: nothing blocking, ready for a maintainer and removed triage:needs-changes PR triage: the PR needs changes before it can merge labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Triage: triage:lgtm · severity:minor · areas: ha · has-issue

The change is small and focused. The compaction target now forces the data files on the scheduler thread before it asks Ratis for the snapshot. takeSnapshot() still runs its own pass, so the durability guarantee of the marker is unchanged.

  • Skip below the creation gap: the early pass is skipped when Ratis would answer without a checkpoint, so a tick below the gap pays no fsync.
  • Failures: a failure of the early pass is logged at FINE and cannot stop the tick from asking for the snapshot.
  • Compile check: I confirmed that newCompactionTargetForTesting, PaginatedComponentFile.isModifiedSinceLastSync and the Consumer, Level and TermIndex imports exist, so the new code should compile.
  • Tests: RaftLogCompactionWiringIT covers both paths: files are forced early when a checkpoint is taken, and nothing is forced below the gap. The test-only hook is reset in @​AfterEach, as its Javadoc requires.
  • Conventions: the final usage, imports and @​Tag("slow") follow CLAUDE.md. I found no security concerns and no unrelated changes.

Optional, minor: the Javadoc and the PR body point to "#12587" for the remaining apply-thread forcing paths. Check that this is the issue number you mean.

I could not run the build or the tests here, so I am relying on the author's reported results.

@lvca lvca added the pr_approved review-pr: CI LGTM + clean triage + green sandbox tests on the reviewed head label Nov 21, 2026
@lvca
lvca merged commit 65b20b7 into ArcadeData:main Nov 23, 2026
25 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ha High availability / replication (Raft) has-issue The PR links an issue it resolves pr_approved review-pr: CI LGTM + clean triage + green sandbox tests on the reviewed head severity:minor Cosmetic, documentation, edge case, or a workaround exists triage:lgtm PR triage: nothing blocking, ready for a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HA: the Raft log compaction checkpoint forces every open database's data files on the apply thread, stalling all commits (regression since #11519)

2 participants