Skip to content

A failed GraphBatch.createVertices leaves its transaction open unless the error is a NeedRetryException #9040

Closed

Description

@tae898

GraphBatch.createVertices begins its own transaction and rolls it back only when the failure is a NeedRetryException. Any other failure, such as a DuplicatedKeyException on a unique index or a SchemaException for an unknown type, leaves the transaction active: isTransactionActive() stays true after the call and after the batch is closed. A write made afterwards outside any transaction is accepted instead of refused with TransactionException: Transaction not begun (the repro prints the refusal as a control), is visible to reads, and is gone after the database is closed and reopened, because the transaction it joined never committed.

createVerticesWithRetry calls beginTx() (GraphBatch.java#L662) and has a single catch (final NeedRetryException e) (GraphBatch.java#L678-L680), whose body is the only place that rolls back. The Javadoc says the method "Handles transaction begin/commit internally" (GraphBatch.java#L596), and the documentation describes createVertices(typeName, count) as "Creates vertices in bulk within a single transaction." (Graph Batch); neither sentence says what becomes of that transaction when the call fails.

Related: #7272 and #7289 (closed and merged) fixed the same class in five importer row loops, a transaction opened before a loop and not resolved when a row throws, and #7948 (merged) did it for the GraphSON importer; #8828 (merged 2026-10-03) did it for GraphBatch.create_vertex and insert_many in the Python package, and its sweep covers that package and its Java bridge classes, not this engine method. Searches of the open and closed issues and pull requests for createVertices, createVerticesWithRetry, GraphBatch createVertices rollback, createVertices transaction left open, and GraphBatch transaction active after failure found nothing about createVertices.

Repro

# lib/ holds the engine jar built at the commit under test and its dependencies (not the shaded HA jar)
javac -cp "lib/*" CreateVerticesLeavesTransaction.java
java -XX:+UseCompactObjectHeaders --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED -cp "lib/*:." CreateVerticesLeavesTransaction ./db
import com.arcadedb.database.*;
import com.arcadedb.graph.GraphBatch;

public class CreateVerticesLeavesTransaction {
  static String first(final Exception e) {
    return e.getClass().getSimpleName() + ": " + e.getMessage().lines().findFirst().get();
  }

  public static void main(String[] args) {
    System.out.println("ArcadeDB " + com.arcadedb.Constants.getRawVersion() + " (" + com.arcadedb.Constants.getBuildNumber() + "), Java "
        + System.getProperty("java.version"));
    final DatabaseFactory factory = new DatabaseFactory(args[0]);
    try (Database db = factory.create()) {
      db.command("sql", "CREATE VERTEX TYPE Person");
      db.command("sql", "CREATE PROPERTY Person.id INTEGER");
      db.command("sql", "CREATE INDEX ON Person (id) UNIQUE");
      db.command("sql", "CREATE DOCUMENT TYPE Note");

      try {
        db.command("sql", "INSERT INTO Note SET text = 'control'");
        System.out.println("control: an INSERT outside a transaction was accepted");
      } catch (Exception e) {
        System.out.println("control: an INSERT outside a transaction -> " + first(e));
      }

      try (GraphBatch batch = GraphBatch.builder(db).build()) {
        System.out.println("before                         : isTransactionActive = " + db.isTransactionActive());
        try {
          batch.createVertices("Person", new Object[][] { { "id", 2 }, { "id", 2 } });
        } catch (Exception e) {
          System.out.println("createVertices (duplicate key) : " + first(e));
        }
        System.out.println("after the failed call          : isTransactionActive = " + db.isTransactionActive());
        if (db.isTransactionActive())
          db.rollback(); // the caller cleans up, to try the next failure from a clean state
        try {
          batch.createVertices("NoSuchType", 3);
        } catch (Exception e) {
          System.out.println("createVertices (unknown type)  : " + first(e));
        }
        System.out.println("after the failed call          : isTransactionActive = " + db.isTransactionActive());
      }
      System.out.println("after the batch is closed      : isTransactionActive = " + db.isTransactionActive());

      try {
        db.command("sql", "INSERT INTO Note SET text = 'written outside any transaction'");
        System.out.println("INSERT outside a transaction   : accepted");
      } catch (Exception e) {
        System.out.println("INSERT outside a transaction   : " + first(e));
      }
      System.out.println("Note rows visible now          : " + db.countType("Note", true));
    }
    try (Database db = factory.open()) {
      System.out.println("after close and reopen         : Person = " + db.countType("Person", true) + ", Note = " + db.countType("Note", true));
    }
  }
}

Output on main cecb369df9 (the engine jar's build stamp is 04bb03ebec, the newest commit in it that is not a merge), Temurin 25.0.4 with -XX:+UseCompactObjectHeaders. Temurin 21.0.12 printed the same lines apart from the Java version on the first line; the number in the generated index name differs from run to run.

ArcadeDB 26.10.1-SNAPSHOT (04bb03ebec07fce19101595d65ca1e3bdf516755), Java 25.0.4
control: an INSERT outside a transaction -> TransactionException: Transaction not begun
before                         : isTransactionActive = false
createVertices (duplicate key) : DuplicatedKeyException: Duplicated key [2] found on index 'Person_0_3596111279054693' already assigned to record #1:0
after the failed call          : isTransactionActive = true
createVertices (unknown type)  : SchemaException: Type with name 'NoSuchType' was not found
after the failed call          : isTransactionActive = true
after the batch is closed      : isTransactionActive = true
INSERT outside a transaction   : accepted
Note rows visible now          : 1
after close and reopen         : Person = 0, Note = 0

Versions affected: main cecb369df9 on Temurin 25 and 21, main 417314c18 (2026-09-17), and release 26.9.1 print the same lines apart from that number. The same lines print on current main, b22b5e9954 (2026-10-03, engine build stamp b22b5e99547576dc8ce804d22fe9cdca4573cf29), on Temurin 25.0.4 and 21.0.12, apart from the number in the generated index name.

Expected: after a failed createVertices the database has no active transaction that the call started, and the bare write is refused as it is in the control.

A direction, tested: createVerticesWithRetry could roll back for any other RuntimeException before rethrowing, as its NeedRetryException branch does at lines 679 and 680 (that branch rolls back whatever transaction is active, so this one would too).

         backoffBeforeRetry(attempt);
+      } catch (final RuntimeException e) {
+        if (database.isTransactionActive())
+          database.rollback();
+        throw e;
       }

I built the engine at cecb369df9 with that change alone and ran the same file with Temurin 25, which printed the following; Temurin 21 printed the same lines apart from the first (the generated index name differs). I did not run the engine's test suite with the change.

ArcadeDB 26.10.1-SNAPSHOT (04bb03ebec07fce19101595d65ca1e3bdf516755), Java 25.0.4
control: an INSERT outside a transaction -> TransactionException: Transaction not begun
before                         : isTransactionActive = false
createVertices (duplicate key) : DuplicatedKeyException: Duplicated key [2] found on index 'Person_0_3597306197529985' already assigned to record #1:0
after the failed call          : isTransactionActive = false
createVertices (unknown type)  : SchemaException: Type with name 'NoSuchType' was not found
after the failed call          : isTransactionActive = false
after the batch is closed      : isTransactionActive = false
INSERT outside a transaction   : TransactionException: Transaction not begun
Note rows visible now          : 0
after close and reopen         : Person = 0, Note = 0

Activity

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

    @lvca
    Member

    Fixed in #9163 (26.10.1). A failed GraphBatch.createVertices now rolls back the transaction it started, so no transaction is left open. A transaction you opened yourself is not touched.

    ❤️ 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.

  7. removed
    in progress
    on Oct 4, 2026
  8. tae898 commented on Oct 4, 2026

    @tae898
    ContributorAuthor

    Verified on main at 80ae6c140f (the #9163 merge) with the reproduction from the issue, unchanged, against 0bb737d458, the merge's first parent, on Temurin 25 with -XX:+UseCompactObjectHeaders and on Temurin 21. Each build printed the same lines on both JDKs apart from the generated index name:

    0bb737d458 JDK 25 0bb737d458 JDK 21 80ae6c140f JDK 25 80ae6c140f JDK 21
    isTransactionActive after the failed call (duplicate key) true true false false
    isTransactionActive after the failed call (unknown type) true true false false
    isTransactionActive after the batch is closed true true false false
    INSERT outside a transaction accepted accepted TransactionException: Transaction not begun same
    Note rows visible 1 1 0 0
    after close and reopen Person 0, Note 0 Person 0, Note 0 Person 0, Note 0 Person 0, Note 0

    A transaction the caller opened before a failing createVertices is still active afterwards on both builds, as the closing comment says. On 80ae6c140f, after a failure in a transaction the call began, the next createVertices on the same batch stores its vertices with no cleanup by the caller.

    Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengineseverity:minor

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions