Skip to content

The deferred-flush backpressure of #4728 is JVM-wide: one suspended database's backlog stops the flush thread from draining the queue for every other database #6200

Closed

Description

@lvca

Noticed while working on #6133, which removed one instance of the pattern "one database's backlog is charged to every other database in the JVM". Here is another, in the deferred-flush backpressure added by #4728.

The shape

PageManagerFlushThread.deferredRAMBytes (engine/src/main/java/com/arcadedb/engine/PageManagerFlushThread.java:112) is a single JVM-wide AtomicLong, even though what it accumulates is strictly per-database: deferredByDatabase (line 68) holds the batches of the databases that are currently suspended (HA snapshot ship, full backup), and only those batches are ever added to it (line 284).

The gate that consumes it is not per-database either (line 256, flushPagesFromQueueToDisk):

if (running && maxDeferredRAM > 0 && deferredRAMBytes.get() >= maxDeferredRAM) {
  Thread.sleep(timeout);
  return;
}

That return skips the queue.poll entirely. So once one suspended database's deferred backlog crosses arcadedb.flushSuspendMaxDeferredRAM (512 MB by default), the flush thread stops draining the shared queue for everybody: the bounded queue fills, and scheduleFlushOfPages then throttles the committing threads of every open database, including databases that are not suspended and whose pages could be written to disk immediately.

Concretely: a leader shipping a multi-GB snapshot of database A stalls the committers of unrelated databases B and C on the same server, for as long as A's backlog stays above the cap.

Why the cap itself is right and only its scope is wrong

The cap exists to bound heap, and heap is genuinely a JVM-wide resource, so a global ceiling is the correct thing to measure. What does not follow is the response: batches of non-suspended databases do not add to deferredRAMBytes at all, so flushing them cannot make the heap situation worse - it strictly improves it, since it moves pages out of the queue and lets the page cache release them. Refusing to poll is therefore giving up throughput for no memory benefit.

Proposed

Keep the global ceiling as the trigger, but make the back-off selective:

  1. Poll the queue as usual instead of skipping the poll.
  2. If the polled batch belongs to a database that is not suspended, flush it normally - it cannot grow the deferred backlog.
  3. Only when the polled batch belongs to a suspended database and the cap is crossed, apply the current behaviour (put it back / back off), which is the case the cap was written for.

Step 3 needs care so the batch is not lost and the loop does not spin on the same head-of-queue batch; the existing deferredByDatabase re-enqueue machinery in unsuspend (line ~619) is the model to follow, and PagesToFlush already carries its database.

The natural companion is to split deferredRAMBytes into a per-database counter plus a derived total. That also unblocks item 2 of #6087, which asks for a arcadedb.pagemanager.deferred_ram_bytes gauge tagged by database - not expressible today, because the number simply does not exist per database.

Verification

  • A test with two databases, A suspended and pushed past a deliberately small arcadedb.flushSuspendMaxDeferredRAM, asserting that B's commits still complete promptly instead of blocking on a full queue. Today B stalls; it should not.
  • PageManagerFlushSuspendBackpressureTest must keep proving that A's own committers are still throttled - the cap must not be weakened for the database it applies to.
  • PageManagerFlushSuspendDeferRaceTest and PageManagerFlushSuspendRefCountTest cover the re-enqueue and refcount paths that step 3 touches.

Not a bug, checked while here

The two deferredRAMBytes.set(0) resets (lines 640 and 720) look like they could zero another database's accounting, but both are guarded by deferredByDatabase.isEmpty(), so they only fire when the backlog is provably empty. They are safety nets, not drift.

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 11 commits that reference this issue on Aug 16, 2026
  5. added a commit that references this issue on Aug 17, 2026
  6. 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