GridGain Developers Hub

Atomicity Modes

By default, a cache supports only atomic operations, and bulk operations such as putAll() or removeAll() are executed as a sequence of individual puts and removes. You can enable transactional support and group multiple cache operations, on one or more keys, into a single atomic transaction. These operations are executed without any other interleaved operations on the specified keys, and either all succeed or all fail. There is no partial execution of the operations.

To enable support for transactions for a cache, set the atomicityMode parameter in the cache configuration to TRANSACTIONAL.

GridGain supports 3 atomicity modes, which are described in the following table.

Atomicity Mode Description

ATOMIC

The default mode. All operations are performed atomically, one at a time. Transactions are not supported. The ATOMIC mode provides better performance by avoiding transactional locks, whilst providing data atomicity and consistency for each single operation. Bulk writes, such as the putAll(…​) and removeAll(…​) methods, are not executed in one transaction and can partially fail. If this happens, a CachePartialUpdateException is thrown and contains a list of keys for which the update failed.

TRANSACTIONAL

Enables support for ACID-compliant transactions executed via the key-value API. SQL transactions are not supported. Transactions in this mode can have different concurrency modes and isolation levels. Enable this mode only if you need support for ACID-compliant operations. For more information about transactions, see Performing Transactions.

TRANSACTIONAL_SNAPSHOT

An experimental mode that implements multiversion concurrency control (MVCC) and supports both key-value transactions and SQL transactions. See Multiversion Concurrency Control for details about and limitations of this mode.

You can enable transactions for a cache in the cache configuration.

<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"/>
        </bean>
    </property>

    <!-- Optional transaction configuration. -->
    <property name="transactionConfiguration">
        <bean class="org.apache.ignite.configuration.TransactionConfiguration">
            <!-- Configure TM lookup here. -->
        </bean>
    </property>
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setName("cacheName");

cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg = Util.getIgniteCfg();
cfg.setCacheConfiguration(cacheCfg);

// Optional transaction configuration. Configure TM lookup here.
TransactionConfiguration txCfg = new TransactionConfiguration();

cfg.setTransactionConfiguration(txCfg);

// Start a node
Ignition.start(cfg);
var cfg = new IgniteConfiguration
{
    CacheConfiguration = new[]
    {
        new CacheConfiguration("txCache")
        {
            AtomicityMode = CacheAtomicityMode.Transactional
        }
    },
    TransactionConfiguration = new TransactionConfiguration
    {
        DefaultTransactionConcurrency = TransactionConcurrency.Optimistic
    }
};
This API is not presently available for C++. You can use XML configuration.