SQL Transactions
Overview
SQL Transactions are supported for caches that use the TRANSACTIONAL_SNAPSHOT
atomicity mode. The TRANSACTIONAL_SNAPSHOT
mode is the implementation of multiversion concurrency control (MVCC) for GridGain caches. For more information about MVCC and current limitations, visit the Multiversion Concurrency Control page.
See the Transactions page for the transaction syntax supported by GridGain.
Enabling MVCC
To enable MVCC for a cache, use the TRANSACTIONAL_SNAPSHOT
atomicity mode in the cache configuration. If you create a table with the CREATE TABLE
command, specify the atomicity mode as a parameter in the WITH
part of the command:
CREATE TABLE Person WITH "ATOMICITY=TRANSACTIONAL_SNAPSHOT"
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="cacheConfiguration">
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="myCache"/>
<property name="atomicityMode" value="TRANSACTIONAL_SNAPSHOT"/>
</bean>
</property>
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration<>();
cacheCfg.setName("myCache");
cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT);
var cacheCfg = new CacheConfiguration
{
Name = "myCache",
AtomicityMode = CacheAtomicityMode.TransactionalSnapshot
};
Limitations
Cross-Cache Transactions
The TRANSACTIONAL_SNAPSHOT
mode is enabled per cache and does not permit caches with different atomicity modes within one transaction. Thus, if you want to cover multiple tables in one SQL transaction, all tables must be created with the TRANSACTIONAL_SNAPSHOT
mode.
Nested Transactions
Ignite supports three modes of handling nested SQL transactions that can be enabled via a JDBC/ODBC connection parameter.
jdbc:ignite:thin://127.0.0.1/?nestedTransactionsMode=COMMIT
When a nested transaction occurs within another transaction, the system behavior depends on the nestedTransactionsMode
parameter:
-
ERROR
— When the nested transaction is encountered, an error is thrown and the enclosing transaction is rolled back. This is the default behavior. -
COMMIT
— The enclosing transaction is committed; the nested transaction starts and is committed when its COMMIT statement is encountered. The rest of the statements in the enclosing transaction are executed as implicit transactions. -
IGNORE
— DO NOT USE THIS MODE. The beginning of the nested transaction is ignored, statements within the nested transaction will be executed as part of the enclosing transaction, and all changes will be committed with the commit of the nested transaction. The subsequent statements of the enclosing transaction will be executed as implicit transactions.