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.
Operation Gremlin step Create edge addE()
Create vertex addV()
Merge edge mergeE()
Merge vertex mergeV()
Update vertex property v(<>).property("key", "value")
Update edge property e(<>).property("key", "value")
Delete vertex v(<>).drop()
Delete edge e(<>).drop()
Delete vertex property v(<>).properties("key").drop()
Delete edge property e(<>).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:
Operation Gremlin step Create vertex addV()
Update vertex property v(<>).property("key", "value")
Update edge property e(<>).property("key", "value")
Delete vertex property v(<>).properties("key").drop()
Delete edge property e(<>).properties("key").drop()
Merge vertex mergeV()
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โ
Use Aerospike Enterprise Edition v8.0 and later on your database cluster.
Configure the namespace of your Aerospike database to use strong consistency.
Enable transactions in AGSโ
To enable transactions in AGS, set the following configuration options:
Set this value to
true
.Optional value in seconds for transaction timeouts. Maximum allowable value is 120.
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));
}
}