Skip to content

RemoteGraphBatch ignores unique edge constraint #4113

Closed

Description

@ruslan-butyk-fntext

ArcadeDB version: 26.4.2
Steps to reproduce:

  • Create a simple scheme with edge unique constraint:
CREATE VERTEX TYPE zone;
CREATE VERTEX TYPE device;
CREATE PROPERTY zone.id STRING;
CREATE PROPERTY device.id STRING;
CREATE EDGE TYPE zone_device;
CREATE PROPERTY zone_device.from_id STRING;
CREATE INDEX ON zone_device (from_id) NOTUNIQUE;
CREATE PROPERTY zone_device.to_id STRING;
CREATE INDEX ON zone_device (to_id) NOTUNIQUE;
CREATE INDEX ON zone_device (from_id,to_id) UNIQUE;
  • Using RemoteGraphBatch create two vertexes and the same edge twice:
try (RemoteGraphBatch batch = remoteDb.batch().build()) {
  String zoneId = "zone1";
  String deviceId = "device1";
  String from = batch.createVertex("zone", "id", zoneId);
  String to = batch.createVertex("device", "id", deviceId);
  batch.flush();
  batch.createEdge("zone_device", from, to, "from_id", zoneId, "to_id", deviceId);
  batch.createEdge("zone_device", from, to, "from_id", zoneId, "to_id", deviceId);
  batch.flush();
}

Actual behavior: Edge is successfully created twice.
Expected behavior: Edge should not be created the second time because it violates unique constraint [from_id,to_id]

P.S.
Also worth to mention that RemoteGraphBatch doesn't support RemoteDatabase transactions. I'm not sure if it should support it, but there might be some confusions since RemoteGraphBatch is created out of RemoteDatabase.

Activity

  1. self-assigned this
    on May 6, 2026
  2. added this to the 26.5.1 milestone on May 6, 2026
  3. added theissue type on May 6, 2026
  4. lvca commented on May 6, 2026

    @lvca
    Member

    Fixed.

    Root cause: GraphBatch.createEdgeRecordsBulk writes edge records straight to pages via LocalBucket.createRecordsBulk, bypassing LocalDatabase.createRecord and therefore DocumentIndexer.createDocument. Since indexes were never updated, unique constraints on edge types were silently ignored. RemoteGraphBatch is just the HTTP front-end for the same code path, so the bug surfaced through both APIs.

    Fix (engine/src/main/java/com/arcadedb/graph/GraphBatch.java):

    • After the bulk write, iterate the indexes registered for the edge bucket (getPolymorphicBucketIndexByBucketId) and call index.put for each new edge, mirroring the DocumentIndexer.createDocument logic with @out/@in pseudo-property handling.
    • Wrapped flush() in try/catch: on RuntimeException, roll back the transaction (only if started by this flush), discard the buffered edges and rethrow so the caller sees the duplicate-key error and the database is left clean.
    • Updated close() to capture the trailing flush() failure but still drain the deferred IN buffer for already-persisted edges, otherwise the integrity checker would flag missing back-pointers.
  5. added 2 commits that reference this issue on Jul 30, 2026
  6. added a commit that references this issue on Aug 14, 2026
  7. added 2 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions