Repository navigation
Description
Collected while fixing #6281 (merged as PR #6290, 7707a2ffb). Three independent items plus two smaller notes. Items 1 and 2 were each raised by a review pass on that PR and deliberately left out of its scope; item 3 is a capability gap the fix made visible rather than created.
Item 1 - the other per-database maps of PageManagerFlushThread are keyed by a Database that compares by PATH
LocalDatabase.equals()/hashCode() compare databasePath, not instance identity (LocalDatabase.java:2114-2130). Every per-database map in PageManagerFlushThread is keyed on that:
ConcurrentHashMap<Database, Integer> suspended // :90
ConcurrentHashMap<Database, ConcurrentLinkedQueue<PagesToFlush>> deferredByDatabase // :138
ConcurrentHashMap<BasicDatabase, AtomicInteger> slotsInUse // :198
ConcurrentHashMap<BasicDatabase, AtomicLong> flushedPagesPerDatabase // :236
ConcurrentHashMap<BasicDatabase, AtomicLong> deferredRAMByDatabase // :257A database closed or dropped and then reopened at the same path is therefore an equal key but a different instance. Anything still holding the old instance resolves to the new database's entry.
removeAllPagesOfDatabase() clears these entries on close, so the window is narrow - it needs an old-instance reference used after that purge - but such references exist. The concrete path: a PagesToFlush still in the queue carries the old instance in its database field, and the defer check at PageManagerFlushThread:736 calls isSuspended(db) with it. After a reopen that consults the new instance's suspension flag, so a straggler batch of a database that no longer exists can be deferred into the new database's backlog and charged to its deferredRAMByDatabase. #6200's accounting has drift-repair counters that regression tests assert stay at zero, so this would surface there first - as a mystery.
#6281 defended only slotsInUse, in two ways worth reusing: the emptied wrapper is now removed from the queue when its database goes (so there is nothing stale to poll), and each batch carries the AtomicInteger its slot was charged on, so the release never re-resolves through the map. The second technique generalises to any of these counters.
Not every map needs fixing, and that is worth stating so a sweep does not churn them all: suspendLocks and replayDrainLocks (:143, :148) are correct to alias by path - the same path means the same files, so two instances sharing a monitor is the desired behaviour. The counting maps are the ones to audit.
Suggested scope: decide per map whether path-aliasing is benign (flushedPagesPerDatabase feeds a progress heuristic, so probably), harmful (suspended, deferredByDatabase, deferredRAMByDatabase), or correct (the monitors), and apply the carry-the-reference pattern where it is harmful. A test in the shape of Issue6281PerDatabaseFlushQueueTest#aBatchOfAClosedDatabaseCannotSpendTheBudgetOfOneReopenedAtTheSamePath covers this scenario.
Item 2 - BucketIndexBuilder's worker pause is best-effort, and nothing checks it
BucketIndexBuilder.create() parks every async worker for the duration of the build by scheduling a DatabaseAsyncExecuteAlone task per worker (BucketIndexBuilder.java:93), each blocking on semaphoreAfterFinish until the build releases it at :173:
((DatabaseAsyncExecutorImpl) database.async()).scheduleTask(i, new DatabaseAsyncExecuteAlone(...), true, 100);scheduleTask returns a boolean and the return value is discarded. Nothing confirms the workers actually parked before the scan begins.
Until #6281 this was partly obscured by a second CountDownLatch, semaphoreToStart, that the pause tasks counted down and nothing ever awaited - so the build started whether or not any worker had reached the pause. That latch has been removed (what it was reaching for - the build seeing everything already written - is now provided properly by database.waitForAsyncCompletion() at :82), which leaves the remaining question sharp rather than hidden:
The barrier guarantees the scan sees everything the async side wrote BEFORE the build. The pause is what is supposed to stop new writes DURING it. If a worker is not actually parked, can it write a record that the in-progress scan misses, and if so does that record still get an index entry through the normal indexing path? If the answer is "it can be missed", the pause needs to be gated on (check the return, and wait for the workers to confirm) rather than fired and forgotten. If the answer is "it cannot", the pause tasks are doing less than they appear to and the code should say which.
Item 3 - async-dispatched DDL is now refused rather than supported
Since #6281, CREATE INDEX, a manual index create and REBUILD INDEX raise NeedRetryException when they run on one of the async executor's own worker threads - a command sent over HTTP with awaitResponse=false, for instance. That is the correct immediate behaviour and a strict improvement: the barrier they need enqueues a marker on every worker including the caller's own, and the only consumer of a worker's queue is that worker, so before the guard the thread parked for ever (measured: the surefire fork does not merely fail, it never finishes). REBUILD INDEX had refused this since #2097; CREATE INDEX and ManualIndexBuilder had no guard at all and simply hung.
Refusing is not the same as supporting, though. POST /command with awaitResponse=false is a documented way to fire a long DDL statement, and index creation is exactly the kind of long DDL somebody would want to fire that way. The fix turned a hang into a clear error and a workaround ("run it synchronously"); it did not give the operation back.
Worth deciding whether async-dispatched DDL should work. The shape that suggests itself: recognise DDL that needs the barrier at dispatch time and run it on a thread that is not one of the executor's workers, so the barrier can be satisfied rather than refused. The guard added in #6281 stays either way as the backstop for anything that reaches it anyway.
Smaller notes, not worth issues of their own
a. Wire pageFlushQueueMaxPerDatabase into Micrometer when the pagemanager gauges get there. #6281 made pageFlushQueueLength a sum across databases (the queue no longer carries the per-database bound) and added pageFlushQueueMaxPerDatabase as the number that can still be compared against arcadedb.pageFlushQueue. Both currently reach operators only through the profiler JSON and text dump. When item 2 of #6087 wires arcadedb.pagemanager.deferred_ram_bytes and friends into Micrometer, the new gauge belongs in the same pass - an alert on the old field alone now means something different from what it used to.
b. Two mechanisms answer "am I on an async worker thread?" RebuildIndexStatement uses the DatabaseContext.asyncMode thread-local (set in AsyncThread.run()); LocalDatabase.waitForAsyncCompletion() uses thread identity via isCurrentThreadOneOfMyWorkers() / AsyncThread.getOwner(). They agree today and each is correct for where it sits - the context flag survives a call that leaves the executor's own classes, the identity check is exact about which executor - but two spellings of one question tend to drift. Worth collapsing to one, or documenting which to reach for.
Activity
fix(#6303): review round 1 - drop the task the quiesce replaced, and …
fix(#6303): review round 2 - the caller-runs path gets a test and a c…
docs(#6303): the release note says SQL DDL, and says what a saturated…
style(#6303): the lazy-init holder goes below the fields it hides, an…
perf(#6303): a dispatched script that mentions no DDL verb is classif…
fix(#6303): review round 3 - the in-flight count cannot be released t…
fix(#6303): a failing command on the pool no longer rolls back a tran…
fix(#6303): a stale batch stops answering for the database at its pat…
lvca commentedon Aug 17, 2026
Closed by #6309 (
bdf46f9). What shipped against each item, and the two places the outcome differs from what this issue proposed:Item 1 - path-keyed maps. Audited per map rather than swept. There is exactly ONE path that reaches a per-database map through a stale instance: the flush thread reading
pagesToFlush.databaseafter the poll.isOpen()now runs insidesynchronized (suspendLock(db))and ahead of the suspension check, which is exact rather than merely narrower -LocalDatabase.close()clearsopenbefore the purge that forgets this bookkeeping, and that purge takes the same monitor, so "isOpen() true" means the purge has not run and will collect whatever we defer.flushedPagesPerDatabasegot the carry-the-reference treatment as well (defence in depth after the hoist, and a perf win: one map lookup per batch instead of one per page).suspendLocks/replayDrainLocksare documented in place as correctly path-keyed, so the next sweep does not churn them.Item 2 - the pause. The answer to the question this issue posed ("can a write be missed, and does it still get an entry?") is yes, it can be missed, so the pause is now gated:
DatabaseInternal.quiesceAsync()commits each worker's batch, waits for every worker to confirm it parked, and holds them.Beyond the issue:
TypeIndexBuilder- the ordinaryCREATE INDEX- never parked the workers at all. It paid only the #6281 barrier, so a record written between that barrier andaddIndexInternal, still uncommitted when the scan read, was in neither the scan nor the index. Same hole asBucketIndexBuilder's, on the more common path. It quiesces now, as doesREBUILD INDEX ... statsOnly, which reaches no builder to inherit one from and overwrites the BM25 corpus counters with what its scan found.Item 3 - async-dispatched DDL: narrower than proposed, on purpose. Routing all dispatched commands off the workers broke
AsyncInsertTest, and the reason is worth recording: an async worker is not just a thread. It owns a batch transaction across up toASYNC_TX_BATCH_SIZEtasks, and it is the unitThreadBucketSelectionStrategypins a bucket to - so "as many workers as buckets" is a documented way to make concurrent asynchronous writers never contend for the same pages, arithmetic a JVM-wide pool sized for the machine cannot honour. It showed up as MVCC conflicts and a duplicated row, not as an error anybody would connect to a dispatch change.So only statements that parse to a
DDLStatementgo to the newAsyncCommandPool- which is what this issue actually proposed ("recognise DDL that needs the barrier at dispatch time"). Everything else stays on the workers exactly as before. Classification is by parse, never by keyword match; the verb pre-filter is a negative filter only, kept honest by a test that walks everyDDLStatementsubclass. SQL only (sql/sqlscript): other languages keep today's behaviour, including #6281's refusal, which is a refusal rather than the old hang.Note b - collapsed to one mechanism, thread identity. The
DatabaseContext.asyncModecheck inRebuildIndexStatementis gone: since item 3 the two disagree (the pool setsasyncModeand is not a worker), so keeping it would have gone on refusing exactly the operation this issue set out to give back.Note a - deliberately NOT done, per this issue's own scoping:
pageFlushQueueMaxPerDatabasebelongs to item 2 of #6087's Micrometer pass.AsyncCommandPoolis wired intoPoolMetricsaspool=async_commandin the meantime.fix(#6324): a build shares a transaction for what it CONTAINS, and a …
fix(#6324): an index built inside a transaction indexes what that tra…
fix(#6359): the propagation holds the async workers, and its two list…
fix(#6359): a propagated index joins the transaction that wrote the r…
fix(ArcadeData#6526): resize the async pool without tearing it down, …