Skip to main content
Loading
Version: Graph 2.5.0

Data consistency and isolation

This page describes how to manage data consistency and isolation with Aerospike Graph Service (AGS).

Overviewโ€‹

Aerospike Graph Service (AGS) supports different transaction isolation levels for read-only queries and for Gremlin mutation queries. The classification of a Gremlin query depends on whether it modifies graph data:

  • Read-only queries do not alter data.

  • Mutation queries modify the graph using operations. If a query contains any of the following mutation steps, it is classified and executed as a mutation query. Otherwise, it is treated as a read-only query.

    OperationGremlin step
    Create edgeaddE()
    Create vertexaddV()
    Merge edgemergeE()
    Merge vertexmergeV()
    Update vertex propertyv(<>).property("key", "value")
    Update edge propertye(<>).property("key", "value")
    Delete vertexv(<>).drop()
    Delete edgee(<>).drop()
    Delete vertex propertyv(<>).properties("key").drop()
    Delete edge propertye(<>).properties("key").drop()

Read-only queriesโ€‹

Read-only queries follow an eventual consistency model. This means that if updates occur concurrently on the same vertex or edge, the query results may temporarily reflect stale or inconsistent data due to ongoing mutations during query execution.

Mutation queriesโ€‹

The consistency of mutation queries depends on whether the Aerospike database namespace is configured with Strong Consistency (SC) mode or Available and Partition-tolerant (AP) mode.

  • In SC mode and with AGS transactions enabled, all mutation queries are atomic and isolated, guaranteeing no data loss, even during a cluster split. The only exception is the drop() step for a supernode vertex.

  • In AP mode some writes may be lost during a cluster split. However, mutations which use the following gremlin steps are atomic and isolated:

    OperationGremlin step
    Create vertexaddV()
    Update vertex propertyv(<>).property("key", "value")
    Update edge propertye(<>).property("key", "value")
    Delete vertex propertyv(<>).properties("key").drop()
    Delete edge propertye(<>).properties("key").drop()
    Merge vertexmergeV()

Enabling transactionsโ€‹

To ensure write consistency across all supported mutation operations in AGS transactions, you must meet the following requirements and set a configuration option as described in this section.

Prerequisitesโ€‹

Enable transactions in AGSโ€‹

To enable transactions in AGS, set the following configuration options:

Application code considerationsโ€‹

AGS transactions prevent concurrent writes to the same graph elements. Use retry patterns in client code to handle concurrent write situations.

The following code example demonstrates a retry pattern:


for (int i = 0; i < RETRY_COUNT; i++) {
try {
// Write operation which may throw an exception from concurrent update.
g.V(1).drop().iterate();
break;
} catch (final Exception e) {
// Back off exponentially.
Thread.sleep(Math.min(Math.pow(10, i), 5000));
}
}