Repository navigation
Description
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:
- Poll the queue as usual instead of skipping the poll.
- If the polled batch belongs to a database that is not suspended, flush it normally - it cannot grow the deferred backlog.
- 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. PageManagerFlushSuspendBackpressureTestmust keep proving that A's own committers are still throttled - the cap must not be weakened for the database it applies to.PageManagerFlushSuspendDeferRaceTestandPageManagerFlushSuspendRefCountTestcover 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
fix(#6200): the deferred backlog is released per database, never zero…
fix(#6200): a database being purged drops its suspension and its defe…
docs(#6200): the throttle WARNING names both backlogs, and a stale ja…
fix(#6200): a release moves off the total only what the per-database …
fix(#6200): an unexpected failure while writing the backlog no longer…
fix(#6200): one page's unexpected failure no longer abandons the rest…
test(#6199, #6200): the success-path timeouts stop being a flake sour…
docs(#6200): the reason index compaction cannot hold the page-manager…
fix(#6200): a mixed-database flush batch fails loudly, and the deferr…
docs(#6200): say why only the asynchronous writers are held by the de…
fix(#6199, #6200): the flush drains wake on the page, and one suspend…
fix(#6259): a committer waits for flush-queue room before the page-ma…