Skip to content

Async executor: with the default settings a batch can still run out of retries after #9535 (24 of 6,000 runs lose 1,000 records on a one-bucket type at parallel level 4) #9694

Closed

Description

@tae898

Follow-up to #9529 and #9535 (and #7615 / #7625). I posted the measurement below as a comment on #9529 on 2026-10-09 and, as that issue is closed and the comment has had no reply, I am repeating it here as its own issue: after #9535 the default settings still lose a batch in about 0.4% of runs of the #7615 scenario, and the backoff does not change the loss rate at the defaults.

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.

Reproduction

The program runs the #7615 scenario (9,742 INSERTs through async().command(), 4 workers, commitEvery 1000, one bucket) many times, each in a fresh database, and counts the runs in which onError fires for a batch. Usage: java --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED -cp '<lib>/*:classes' AsyncBatchLoss <dbDir> <runs> <perCommandCallback:true|false>; the table above used true.

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.io.File;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

// Usage: java AsyncBatchLoss <dbDir> <runs> <perCommandCallback:true|false> [typeBuckets]
public class AsyncBatchLoss {
  static final int ROWS = 9_742;

  public static void main(final String[] args) throws Exception {
    final String dir = args[0];
    final int runs = Integer.parseInt(args[1]);
    final boolean perCommand = Boolean.parseBoolean(args[2]);
    final int typeBuckets = args.length > 3 ? Integer.parseInt(args[3]) : 0;
    int failed = 0;
    System.out.println("# availableProcessors=" + Runtime.getRuntime().availableProcessors() + " java=" + System.getProperty("java.version"));
    for (int run = 0; run < runs; run++) {
      final String path = dir + "/run" + run;
      deleteTree(new File(path));
      final AtomicInteger executorErrors = new AtomicInteger();
      final AtomicInteger commandErrors = new AtomicInteger();
      final AtomicInteger commandOk = new AtomicInteger();
      final StringBuilder firstError = new StringBuilder();
      long stored;
      int buckets;
      try (DatabaseFactory factory = new DatabaseFactory(path); Database db = factory.create()) {
        db.command("sql", typeBuckets > 0 ? "CREATE DOCUMENT TYPE Bulk4 BUCKETS " + typeBuckets : "CREATE DOCUMENT TYPE Bulk4");
        buckets = db.getSchema().getType("Bulk4").getBuckets(false).size();
        final DatabaseAsyncExecutor async = db.async();
        async.setParallelLevel(4);
        async.setCommitEvery(1_000);
        async.onError(e -> {
          executorErrors.incrementAndGet();
          synchronized (firstError) {
            if (firstError.length() == 0)
              firstError.append(String.valueOf(e)).setLength(Math.min(firstError.length(), 200));
          }
        });
        final AsyncResultsetCallback cb = perCommand ? new AsyncResultsetCallback() {
          @Override
          public void onComplete(final ResultSet rs) {
            commandOk.incrementAndGet();
          }

          @Override
          public void onError(final Exception e) {
            commandErrors.incrementAndGet();
          }
        } : null;
        for (int i = 0; i < ROWS; i++)
          async.command("sql", "INSERT INTO Bulk4 SET id = :id", cb, 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();
      }
      deleteTree(new File(path));
      final boolean bad = stored != ROWS || executorErrors.get() != 0;
      if (bad)
        failed++;
      System.out.printf("run=%d buckets=%d stored=%d executorOnError=%d commandOnComplete=%d commandOnError=%d%s%s%n", run, buckets, stored,
          executorErrors.get(), commandOk.get(), commandErrors.get(), bad ? " FAIL " : "", bad ? firstError : "");
    }
    System.out.printf("# SUMMARY runs=%d failed=%d perCommand=%s%n", runs, failed, perCommand);
  }

  static void deleteTree(final File f) {
    if (!f.exists())
      return;
    final File[] kids = f.listFiles();
    if (kids != null)
      for (File k : kids)
        deleteTree(k);
    f.delete();
  }
}

Activity

  1. added
    concurrency
    engine
    severity:minor
    on Oct 10, 2026
  2. added this to the 26.11.1 milestone on Oct 10, 2026
  3. self-assigned this
    on Oct 10, 2026
  4. added
    in progress
    on Oct 10, 2026
  5. added 8 commits that reference this issue on Oct 10, 2026
  6. 7 remaining items

  7. added a commit that references this issue on Oct 11, 2026
  8. added 11 commits that reference 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