Skip to content

fix(#11805): a one-file sync no longer waits for a full sync, retries a failed directory force, and does not spin on a refused page - #12311

Open
shaunpatterson wants to merge 3 commits into
ArcadeData:mainfrom
shaunpatterson:fix/11805-one-file-sync-followups
Open

shaunpatterson wants to merge 3 commits into
ArcadeData:mainfrom
shaunpatterson:fix/11805-one-file-sync-followups

Conversation

@shaunpatterson

Copy link
Copy Markdown
Contributor

What does this PR do?

Follow-ups to the one-file sync that #11827 merged for #11805. They come from the review of the superseded #11807 and are ported onto the merged implementation:

  • FileManager.syncFile holds the file's own force lock (PaginatedComponentFile.getForceLock()) instead of the database-wide sync lock. A vector graph build no longer waits out a WAL rotation fsyncing every file of the database (about 1.1 s per call during an application ingest, with the searches of the index queued behind the build lock). forceIfModified holds the same lock from its claim to the end of its force, so a syncFiles() reaching the file while a one-file force is in flight still waits for it.
  • Without the shared lock, a one-file sync can find a file clean after a full sync forced it with its metadata but before that sync forced the directory. PaginatedComponentFile counts its metadata forces and the directory forces that followed them (directoryForceOwed / directorySynced), and either sync forces a directory still owed.
  • A directory force that fails no longer clears what the files owe: the next sync, full or of one file, retries it. A force skipped because fsync is off or the platform has none counts as done (FileUtils.skipsDirectoryForce).
  • PageManagerFlushThread.waitPagesOfFileAreFlushed sleeps the poll interval when the only pages left are copies the disk refused. Those are not counted as pending, so the drain wait returned at once and the loop spun on the CPU until its deadline, while the caller held the graph build lock.

Not ported: #11807's "a file closed between the lookup and the force reports not synced". Main's syncFile deliberately answers true for a file that is no longer open, and a file closed mid-sync is the same case.

Motivation

#11805 (search p95 of 2.4 s in an application ingest). #11827 forces only the graph file, but the call still queues behind any full sync in progress.

Related issues

#11805, #11807, #11827

Additional Notes

Tests:

  • New OneFileSyncTest.aOneFileSyncDoesNotWaitForAFullSyncInProgress: a thread holds the database-wide sync lock and syncFile must still complete. On main it times out (TimeoutException after 10 s).
  • New OneFileSyncTest.waitingOnlyForARefusedPageDoesNotSpin: one refused page, a 1 s wait. On main the wait used 892 ms of CPU; the limit is 300 ms.
  • New PaginatedComponentFileSyncStateTest.aOneFileSyncForcesTheDirectoryAFullSyncStillOwes and aFailedDirectoryForceIsRetriedByTheNextSync. Both read the new directory bookkeeping, so they cannot run on main.

Tests run, engine com/arcadedb/engine/** and com/arcadedb/index/vector/** without the slow and benchmark groups: 3,424 tests, 3,421 passed, 0 skipped, 3 failed. All three failures are in ReplicatedApplyPublicationTest (aTransactionalReadIsServedWhileEntriesAreAppliedBackToBack, aPlaceholderReadIsServedWhileEntriesAreAppliedBackToBack, aProofOfCorruptionStandsWhileEntriesAreAppliedBackToBack), the timing test that also fails on main's CI.

Checklist

  • I have run the build using mvn clean package command
  • My unit tests cover both failure and success scenarios

…c, retries a failed directory force, and does not spin on a refused page

- FileManager.syncFile holds the file's own force lock instead of the database-wide sync lock, so a vector graph build no longer waits out a WAL rotation fsyncing every file. PaginatedComponentFile counts its metadata forces and the directory forces that followed them, so a one-file sync arriving between a full sync's file loop and its directory force still forces the directory.
- A directory force that fails leaves its files owing it; the next sync, full or of one file, retries it. A force skipped because fsync is off or the platform has none counts as done (FileUtils.skipsDirectoryForce).
- waitPagesOfFileAreFlushed sleeps the poll interval when only copies the disk refused are left, which the drain wait does not count as pending.
- Follow-ups from the review of ArcadeData#11807, ported onto the implementation merged in ArcadeData#11827.
@coderabbitai

coderabbitai Bot commented Nov 16, 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 6 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: fd684b0d-db66-4d2c-8fb5-d170ca8bc0f6
Commits

Reviewing files that changed from the base of the PR and between d4af4c4 and 2717e04.

Files selected for processing: 2

  • engine/src/main/java/com/arcadedb/engine/PageManagerFlushThread.java
  • engine/src/test/java/com/arcadedb/engine/OneFileSyncTest.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 16, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

@codacy-production

codacy-production Bot commented Nov 16, 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

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 concurrency Threading / concurrency / MVCC engine Core engine: document/schema API no-issue The PR links no issue severity:minor Cosmetic, documentation, edge case, or a workaround exists storage Storage/paging/WAL engine layer 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:needs-changes · severity:minor · areas: engine, storage, concurrency · no-issue

Thanks for the follow-up. The design reads sound: the lock order is consistent (syncFiles takes syncLock then forceLock, syncFile takes only forceLock, so there is no inversion). The metadata-force and directory-force counters are monotonic and written under the lock. The pendingOf and markUnsynced APIs the code and tests use do exist.

Changes needed:

  1. PaginatedComponentFileSyncStateTest.aFailedDirectoryForceIsRetriedByTheNextSync depends on POSIX permissions to make the directory force fail. It will not fail as expected when the tests run as root (for example in a container), because root ignores the permission bits and the directory force succeeds. Files.setPosixFilePermissions also throws UnsupportedOperationException on Windows. Please guard it with Assumptions.assumeThat(...), for example skipping when System.getProperty("user.name") is root or when the directory is still readable after the chmod. Alternatively, inject the failure some other way.

  2. OneFileSyncTest.waitingOnlyForARefusedPageDoesNotSpin asserts a CPU-time bound of 300 ms. It is thread CPU time, not wall clock, so it is less exposed than the wall-clock case in CLAUDE.md. A GC or JIT-heavy run can still push it up. State the bound as a tripwire (on main it was 892 ms) and keep it generous, or use StallAwareStopwatch as CLAUDE.md recommends.

  3. Reflection on private fields. Both new tests read syncLock, flushThread, lastFailedFlushRetryMs and failedFlushPages by reflection. They will break silently if those fields are renamed. Package-private test accessors would be sturdier, but this is optional.

  4. PR checklist. The mvn clean package item is unchecked. Also, three ReplicatedApplyPublicationTest failures are noted. Please confirm they also fail on main and are unrelated.

The production changes look correct and well scoped.

Main's fix for ArcadeData#11932 (a vector index build waits only for its own file's
fsync) landed the same design as three of the four follow-ups of this PR:
the file's own force lock instead of the database-wide sync lock, the
per-file directory bookkeeping (a generation pair), and a directory force
that fails or is skipped. FileManager, PaginatedComponentFile, FileUtils and
the PaginatedComponentFileSyncStateTest additions now take main's version.

What is left is the drain wait of PageManagerFlushThread.waitPagesOfFileAreFlushed:
a copy the disk refused is not counted as pending, so awaitDrain returned at
once and the loop spun on the CPU until its deadline. OneFileSyncTest keeps
the test for it; the test of the one-file sync not queueing behind a full
sync is dropped, main's PaginatedComponentFileSyncStateTest and
Issue11932VectorIndexBuildDoesNotWaitForASyncPassTest cover it.
@github-actions github-actions Bot removed the triage:needs-changes PR triage: the PR needs changes before it can merge label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

concurrency Threading / concurrency / MVCC engine Core engine: document/schema API no-issue The PR links no issue severity:minor Cosmetic, documentation, edge case, or a workaround exists storage Storage/paging/WAL engine layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant