// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements.  See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License.  You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
= 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`.

CAUTION: If you configure multiple caches within one link:configuring-caches/cache-groups[cache group], the caches must be either all atomic, or all transactional. You cannot have both TRANSACTIONAL and ATOMIC caches in one cache group.

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

[cols="30%,70%",opts="autowidth"]
|===
| 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
a| Enables support for ACID-compliant transactions executed via the key-value API.
SQL transactions are not supported.
Transactions in this mode can have different link:key-value-api/transactions#concurrency-modes-and-isolation-levels[concurrency modes and isolation levels].
Enable this mode only if you need support for ACID-compliant operations.
For more information about transactions, see link:key-value-api/transactions[Performing Transactions].

[NOTE]
====
[discrete]
=== Performance Considerations
The `TRANSACTIONAL` mode adds a performance cost to cache operations and should be enabled only if you need transactions.
|===


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

[tabs]
--
tab:XML[]
[source,xml]
----
<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>
----
tab:Java[]
[source,java]
----
include::{javaCodeDir}/PerformingTransactions.java[tags=enabling,!exclude,indent=0]
----
tab:C#/.NET[]
[source,csharp]
----
var cfg = new IgniteConfiguration
{
    CacheConfiguration = new[]
    {
        new CacheConfiguration("txCache")
        {
            AtomicityMode = CacheAtomicityMode.Transactional
        }
    },
    TransactionConfiguration = new TransactionConfiguration
    {
        DefaultTransactionConcurrency = TransactionConcurrency.Optimistic
    }
};
----
tab:C++[unsupported]
--
