Transactions
Perform explicit and implicit transactions in GridGain 9 — lifecycle, isolation, read-only transactions, timeouts, labels, and runInTransaction.
All queries in GridGain 9 are transactional. You can provide an explicit transaction as a first argument of any Table and SQL API call. If you do not provide an explicit transaction, an implicit one will be created for every call.
Transaction Lifecycle
Thin client transactions start lazily. Creating a transaction sends nothing to the cluster: the transaction begins on the server when you perform the first operation in it. Until then, it holds no locks and consumes no cluster resources.
The transaction coordinator is chosen when the transaction begins, that is, when you perform that first operation. The coordinator finds the required partitions and sends the read or write requests to the nodes holding primary partitions. For correct transaction operation, all nodes in cluster must have similar time that can be different by no more than schemaSync.maxClockSkewMillis.
Lazy start has two consequences to plan for:
Connection and cluster errors surface on the first operation in the transaction, not when you create it.
Committing or rolling back a transaction that was never used sends no request and reports success.
If the key is not locked by a different transaction, the node gets the locks on the involved keys, and attempts to apply the changes in the transaction. When the operation finishes, the lock is removed. This way, several transactions can work on the same partition, while changing separate keys. Additionally, some operations may perform short-term locks on the keys in advance, to ensure operations proceed correctly.
If the node with primary replica of the partition involved in the transaction fail, the transaction is eventually automatically rolled back. GridGain will return TransactionException on commit attempt.
Transaction Isolation and Concurrency
All read-write transactions in GridGain acquire locks during the first read or write access, and hold the lock until the transaction is committed or rolled back. All read-write transactions are SERIALIZABLE, so as long as the lock persists, no other transaction can make changes to locked data, however data can still be read by Read-Only Transactions.
Deadlock Prevention
GridGain 9 uses the WOUND_WAIT deadlock prevention algorithm. When a transaction requests data that is already locked by a newer (younger) transaction, the newer transaction is cancelled and retried, so that the older transaction can proceed. When a transaction requests data locked by an older transaction, it waits for the lock to be freed.
Executing Transactions
Here is how you can provide a transaction explicitly:
Transaction Management
You can also manage transactions by using the runInTransaction method. When using it, the following will be done automatically:
The transaction is started and substituted to the closure.
The transaction is committed if no exceptions were thrown during the closure.
The transaction will be retried in case of recoverable error. Closure must be purely functional - not causing side effects.
You can run transactions both synchronously and asynchronously.
This example shows how to update an account’s balance synchronously:
And this example performs the same logic in an asynchronous manner:
Read-Only Transactions
When starting a transaction, you can configure the transaction as a read-only transaction. In these transactions, no data modification can be performed, but they also do not secure locks and can be performed on non-primary partitions, further improving their performance. Read-only transactions always check the data for the moment they were started, even if new data was written to the database. The read timestamp is fixed when you create the transaction, not when its first operation runs.
Here is how you can make a read-only transaction:
Transaction Timeout
In certain scenarios, it is preferable to drop the transaction if it is taking too long. When the timeout is reached, the transaction is automatically rolled back.
Here is how you can configure transaction timeout:
Transaction Labels
You can assign custom labels to transactions to help identify and track them. Once set, a transaction label remains unchanged for the lifetime of the transaction and is propagated across all nodes involved in the transaction.
Here is how you can set a transaction label:
Transaction label will be visible in:
Log messages - When transactions timeout, fail, or produce warnings, the label is included in log output for easy identification
System views - Labels are visible in transaction system views for monitoring active and historical transactions
Diagnostic outputs - Labels help correlate transaction activity across distributed nodes
See Also
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

