Skip to content

The flush drain waits still poll, so the snapshot barrier holds the JVM-wide page-manager lock across 1 ms sleeps that #6133 made unnecessary #6199

Closed

Description

@lvca

Follow-up to #6133, which made "does this database still have pages in the flush pipeline?" an O(1) counter read. The cost of one check is now negligible, but both callers still discover the answer by sleeping and asking again, so the latency they pay is set by the poll interval rather than by when the pages actually land.

Where

1. The bulk drain, PageManagerFlushThread.waitAllPagesOfDatabaseAreFlushed (engine/src/main/java/com/arcadedb/engine/PageManagerFlushThread.java:209), polls every DEFAULT_FLUSH_WAIT_POLL_MILLIS = 10 ms (line 64/240). Every close(), rename(), index compaction, backup suspension and the snapshot barrier's step 1 goes through it, and each of them rounds up to the next 10 ms boundary even when the pipeline was already empty or emptied 9 ms ago. On a process cycling through many databases that is pure dead time.

2. The residual drain, waitPendingPagesOfDatabaseUntil (line 398), polls every 1 ms - and its caller, PageManager.openSnapshot (engine/src/main/java/com/arcadedb/engine/PageManager.java:560), runs it with both the database's apply write lock and the JVM-wide page-manager lock held. That is deliberate and correct (publication is excluded, so the drain converges by construction), but it means every Thread.sleep(1) there is a millisecond in which no committer of any database in the JVM can publish a page. The method's own javadoc argues for the 1 ms sleep over a spin, and that trade-off is right as long as polling is the only option - it is the polling itself that is now avoidable.

Why this is newly cheap to fix

Before #6133 the decrement was scattered across five call sites, so there was no single place to hook a "this database just drained" signal without risking a missed or duplicated notify. After #6133 there is exactly one: FlushPageIndex.release() (engine/src/main/java/com/arcadedb/engine/FlushPageIndex.java:229) is the only path on which a database's pending count goes down, and removeAllOfDatabase is the only other way an entry leaves.

Proposed

Give FlushPageIndex a per-database monitor (the same shape as the existing suspendLocks / replayDrainLocks / snapshotBarrierLocks maps) and notifyAll() from release() on the count reaching zero, plus from removeAllOfDatabase. Both waits then become lock.wait(interval) instead of Thread.sleep(interval):

  • they wake the moment the last page lands, instead of up to a full interval later;
  • the bounded wait() keeps the existing timeout machinery working unchanged - waitAllPagesOfDatabaseAreFlushed's no-progress window still needs periodic re-evaluation, and waitPendingPagesOfDatabaseUntil still needs its deadline check, so neither becomes an unbounded park;
  • the snapshot barrier's JVM-wide lock hold drops from "number of residual pages, rounded up to whole milliseconds" to "the time the writes actually take".

Alternative considered and rejected: shortening DEFAULT_FLUSH_WAIT_POLL_MILLIS. It trades dead latency for CPU burn on the exact path that already holds a JVM-wide lock, and it cannot get below one scheduling quantum, so it improves the average without touching the worst case.

Verification

  • A test that measures the wake latency of waitAllPagesOfDatabaseAreFlushed against a page that is released mid-wait: today it is quantised to the poll interval, after the change it should track the release.
  • The existing Issue6133PendingPagesPerDatabaseTest, PageManagerFlushSuspend*Test and FlushRobustnessTest must stay green - the notify must not be able to be missed between the counter reaching zero and the waiter parking (take the monitor before the final count read, standard guarded-wait shape).

Activity

  1. added this to the 26.9.1 milestone on Aug 15, 2026
  2. self-assigned this
    on Aug 16, 2026
  3. added theissue type on Aug 16, 2026
  4. added 3 commits that reference this issue on Aug 16, 2026
  5. added
    concurrency
    engine
    storage
    on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencyenginestorage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions