Skip to content

Async executor: on a single-bucket type at parallel level 4, a batch commit still exhausts its retries about 1% of the time (the #7625 replay has no backoff) #9529

Closed

Description

@tae898

Follow-up to #7615 and its fix #7625. The fix works as designed: a periodic batch commit that hits a page conflict is replayed, and a batch that still cannot commit is reported through every command's onError. What is left is how often a batch runs out of retries under ordinary load. With four async workers inserting into a type that has one bucket, nearly every batch commit conflicts on its first attempt, the replays in commitBatch() run back to back with no delay, and about 1 run in 100 (on two cores) loses one whole batch of 1,000 records after the default arcadedb.txRetries (3) is used up. The caller is told (1,000 per-command onError calls plus one executor-wide onError), so this is not silent loss any more, but an application that submits SQL inserts through async().command() and checks onError now has to resubmit a batch about once per hundred loads of 10,000 rows.

I found it because my CI regression test for #7615 (9,742 inserts, parallel level 4, commitEvery 1000, exact count expected) failed on 2 of 20 platforms in one run on 26.10.1, both on arm64 runners: stored 8742 of 9742, with ConcurrentModificationException: Slot rebase not possible on page PageId(test_db/1/8) slot 0 (concurrent change to the same record).

Reproduction

import com.arcadedb.database.Database;
import com.arcadedb.database.DatabaseFactory;
import com.arcadedb.database.async.AsyncResultsetCallback;
import com.arcadedb.database.async.DatabaseAsyncExecutor;
import com.arcadedb.query.sql.executor.ResultSet;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

public class AsyncBatchRetryExhausted {
  public static void main(final String[] args) {
    final int rows = 9_742;
    int failedRuns = 0;
    for (int run = 0; run < 200; run++) {
      final AtomicInteger executorErrors = new AtomicInteger();
      final AtomicInteger commandErrors = new AtomicInteger();
      long stored;
      try (DatabaseFactory factory = new DatabaseFactory("./async-repro/run" + run); Database db = factory.create()) {
        db.command("sql", "CREATE DOCUMENT TYPE Bulk4");
        final DatabaseAsyncExecutor async = db.async();
        async.setParallelLevel(4);
        async.setCommitEvery(1_000);
        async.onError(e -> executorErrors.incrementAndGet());
        final AsyncResultsetCallback callback = new AsyncResultsetCallback() {
          @Override
          public void onComplete(final ResultSet rs) {
          }

          @Override
          public void onError(final Exception e) {
            commandErrors.incrementAndGet();
          }
        };
        for (int i = 0; i < rows; i++)
          async.command("sql", "INSERT INTO Bulk4 SET id = :id", callback, Map.of("id", i));
        async.waitCompletion();
        try (ResultSet rs = db.query("sql", "SELECT count(*) AS c FROM Bulk4")) {
          stored = ((Number) rs.next().getProperty("c")).longValue();
        }
        db.drop();
      }
      if (stored != rows) {
        failedRuns++;
        System.out.printf("run %d: stored %d of %d, executor onError %d, command onError %d%n", run, stored, rows,
            executorErrors.get(), commandErrors.get());
      }
    }
    System.out.printf("%d of 200 runs lost records%n", failedRuns);
  }
}

Run it pinned to a few cores (for example docker run --cpuset-cpus 0-1 ...), since contention is the trigger. Every failing run looks the same: stored 8742 of 9742, executor onError 1, command onError 1000, cause ConcurrentModificationException: Slot rebase not possible on page PageId(.../1/N) slot S (concurrent change to the same record).

Results

200 runs per cell (400 where noted), fresh database each run, one JVM per cell, Linux x86_64, eclipse-temurin images, JDK 25 with -XX:+UseCompactObjectHeaders.

build JDK cores runs that lost a batch
26.10.1 25 4 1 of 200
26.10.1 21 4 0 of 200
26.10.1 25 2 1 of 200
26.10.1 21 2 1 of 200
main 6e067d9 25 4 0 of 200
main 6e067d9 21 4 0 of 200
main 6e067d9 25 2 2 of 200
main 6e067d9 21 2 4 of 200, 6 of 400 on a re-run

On two cores that is about 1% of runs (14 of 1,400 on both builds and JDKs with the default settings), on four cores about 0.1% (1 of 800). The Python bindings over 26.10.1 show the same thing (1 of 200 on two cores). In every failing run the per-command onError fired for all 1,000 commands of the batch, so #7625's reporting holds.

Controls, all on main 6e067d9, two cores:

change runs that lost a batch
-Darcadedb.txRetries=0 200 of 200 (on average 4.5 batch commits per run fail)
default (3) 6 of 400 (JDK 21)
-Darcadedb.txRetries=5 0 of 400
-Darcadedb.txRetries=10 0 of 400
-Darcadedb.txRetries=20 0 of 400 (JDK 21), 0 of 400 (JDK 25)
CREATE DOCUMENT TYPE Bulk4 BUCKETS 4 0 of 400 (JDK 21), 0 of 400 (JDK 25)

So the first commit attempt of a batch conflicts most of the time when four workers share one bucket's tail page, and three immediate replays are usually but not always enough.

Where it comes from

commitBatch() retries a ConcurrentModificationException by rolling back and replaying the buffered commands right away, up to TX_RETRIES times:

void commitBatch(final boolean currentUseWAL, final WALFile.FlushType currentSync,
final boolean beginFreshTransaction) {
final int maxRetries = database.getConfiguration().getValueAsInteger(GlobalConfiguration.TX_RETRIES);
Throwable lastFailure = null;
for (int attempt = 0; attempt <= maxRetries; ++attempt) {
try {
if (attempt > 0) {
replayingBatch = true;
try {
database.begin();
database.getTransaction().setUseWAL(currentUseWAL);
database.getTransaction().setWALFlush(currentSync);
for (final DatabaseAsyncCommand command : pendingBatchCommands)
command.execute(this, database);
} finally {
replayingBatch = false;
}
}
final IntConsumer hook = TEST_BEFORE_BATCH_COMMIT_HOOK;
if (hook != null)
hook.accept(++batchCommitAttempt);
database.commit();
onOk();
clearBatchState();
if (beginFreshTransaction) {
database.begin();
// TransactionContext.begin()/reset() never reset useWAL/walFlush, so the stamp above would
// "happen to" survive this cycle via object reuse even without this - re-applied explicitly
// anyway so the guarantee does not depend on that staying true in a different class (#6509
// review round 9).
database.getTransaction().setUseWAL(currentUseWAL);
database.getTransaction().setWALFlush(currentSync);
}
return;
} catch (final ConcurrentModificationException e) {
// TRANSIENT MVCC CONFLICT: RETRY IF ATTEMPTS REMAIN
lastFailure = e;
if (database.isTransactionActive())
database.rollback();
if (!pendingUnreplayableTasks.isEmpty())
// A replay can only reconstruct pendingBatchCommands - committing one over a batch that also
// held a write it cannot reconstruct would silently omit that write while still reporting
// success. No safe retry available: stop here and fall through to the abandon path below,
// exactly as an un-retried commit failure always has for this batch shape.
break;
} catch (final Throwable e) {
// NOT AN MVCC CONFLICT: NOT TRANSIENT, NO POINT RETRYING
lastFailure = e;
if (database.isTransactionActive())
database.rollback();
break;
}
}
notifyPendingBatchCommandsAndAbandon(lastFailure);

LocalDatabase.transaction() waits between attempts with the jittered backoff from #5587 (delayBetweenRetries, configured by TX_RETRY_DELAY and TX_RETRY_DELAY_BASE):

delayBetweenRetries(retry, retryDelayBase, retryDelay);

The batch replay does not, so a replay of 1,000 inserts races the same three workers that just caused the conflict, on the same tail page. The conflict itself is the slot rebase declining an inserted slot that a concurrent commit also used:

"Slot rebase not possible on page " + pageId + " slot " + slot + " (concurrent change to the same record). Please retry the operation");

Questions

  1. Should commitBatch() apply the same backoff between replays as transaction() does? With a backoff, three retries may be enough; without one, my runs needed five.
  2. Is a single-bucket type the expected setup for async().command() with SQL inserts at parallel level above 1? Records created through async().createRecord() go to the worker that owns their bucket (as explained in Question: for an embedded bulk load of a large document type, do you recommend async createRecord with BUCKETS set to the core count? #8478), but async().command() sends commands to workers in turn, so all workers write the same bucket. If the intended answer is "give the type as many buckets as the parallel level", a note in the async executor docs would help, since that also removed the failures here.

Activity

  1. added
    concurrency
    engine
    severity:minor
    on Oct 8, 2026
  2. self-assigned this
    on Oct 8, 2026
  3. added
    in progress
    on Oct 8, 2026
  4. added this to the 26.11.1 milestone on Oct 8, 2026
  5. added a commit that references this issue on Oct 9, 2026
  6. removed
    in progress
    on Oct 9, 2026
  7. lvca commented on Oct 9, 2026

    @lvca
    Member

    Fixed in #9535 (26.11.1).

    Confirmed: when a periodic batch commit hit a page conflict, the batch was replayed immediately, racing the same workers on the same bucket page. With several async workers writing one bucket, that could use up arcadedb.txRetries and report a whole batch through onError.

    The replay now waits the same jittered backoff that regular transaction retries use (arcadedb.txRetryDelay / arcadedb.txRetryDelayBase; txRetryDelay=0 disables it). No records are lost silently and no settings changed.

    Tip: for async().command() with SQL inserts at a parallel level above 1, giving the type as many buckets as workers (CREATE DOCUMENT TYPE X BUCKETS 4) also avoids the contention.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  8. tae898 commented on Oct 9, 2026

    @tae898
    ContributorAuthor

    Checked at the merge commit ac4f75d (CI jars, Temurin 25, 2 cores, one JVM at a time) with the repro from this issue: 9,742 INSERTs through async().command(), 4 workers, commitEvery 1000, one bucket, a per-command callback. A run counts as lost when onError fires for a batch. Runs alternated between the two builds in blocks of 1,500.

    build settings runs runs that lost a batch
    before (fd407f1) defaults 6,000 20 (0.33%)
    this PR (ac4f75d) defaults 6,000 24 (0.40%)
    before txRetryDelayBase=20 1,500 3
    this PR txRetryDelayBase=20 1,500 0
    before txRetries=10 1,500 0
    this PR txRetries=10 1,500 0

    So with the default settings the backoff does not change the loss rate here. Every lost batch is the same ConcurrentModificationException ("Slot rebase not possible on page ... slot ...") after the 3 retries are used up. With the default txRetryDelayBase=2 the three waits are drawn from 0-2, 0-4 and 0-8 ms, which is short next to a replay of 1,000 commands on a shared tail page, so the four workers still collide. A longer window (base 20) lost 0 of 1,500 with the PR against 3 of 1,500 without, which is suggestive but too few events to call. More retries (txRetries=10) lost nothing on either build.

    The backoff is still the right behaviour, and the hook-observed tests show it runs. But I would not call the loss fixed for the defaults. Options: replay a batch more times than a single record's txRetries (a batch is 1,000 commands, so a failed attempt costs far more than a single record's retry), or scale the backoff window with the batch size.

    🤖 Generated with Claude Code

  9. added a commit that references this issue on Oct 9, 2026
  10. added a commit that references this issue on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencyengineseverity:minor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions