Apache Ignite Documentation

GridGain Developer Hub - Apache Ignitetm

Welcome to the Apache Ignite developer hub run by GridGain. Here you'll find comprehensive guides and documentation to help you start working with Apache Ignite as quickly as possible, as well as support if you get stuck.

 

GridGain also provides Community Edition which is a distribution of Apache Ignite made available by GridGain. It is the fastest and easiest way to get started with Apache Ignite. The Community Edition is generally more stable than the Apache Ignite release available from the Apache Ignite website and may contain extra bug fixes and features that have not made it yet into the release on the Apache website.

 

Let's jump right in!

 

Documentation     Ask a Question     Download

 

Javadoc     Scaladoc     Examples

Cache Modes

Setup different distribution models, backup copies, and near caches.

Ignite provides three different modes of cache operation: LOCAL, REPLICATED, and PARTITIONED. A cache mode is configured for each cache. Cache modes are defined in CacheMode enumeration.

Local Mode

LOCAL mode is the most light weight mode of cache operation, as no data is distributed to other cache nodes. It is ideal for scenarios where data is either read-only, or can be periodically refreshed at some expiration frequency. It also works very well with read-through behavior where data is loaded from persistent storage on misses. Other than distribution, local caches still have all the features of a distributed cache, such as automatic data eviction, expiration, disk swapping, data querying, and transactions.

Replicated Mode

In REPLICATED mode all data is replicated to every node in the cluster. This cache mode provides the utmost availability of data as it is available on every node. However, in this mode every data update must be propagated to all other nodes which can have an impact on performance and scalability.

As the same data is stored on all cluster nodes, the size of a replicated cache is limited by the amount of memory available on the node with the smallest amount of RAM. This mode is ideal for scenarios where cache reads are a lot more frequent than cache writes, and data sets are small. If your system does cache lookups over 80% of the time, then you should consider using REPLICATED cache mode.

👍

Replicated caches should be used when data sets are small and updates are infrequent.

Partitioned Mode

PARTITIONED mode is the most scalable distributed cache mode. In this mode the overall data set is divided equally into partitions and all partitions are split equally between participating nodes, essentially creating one huge distributed in-memory store for caching data. This approach allows you to store as much data as can be fit in the total memory available across all nodes, hence allowing for multi-terabytes of data in cache memory across all cluster nodes. Essentially, the more nodes you have, the more data you can cache.

Unlike REPLICATED mode, where updates are expensive because every node in the cluster needs to be updated, with PARTITIONED mode, updates become cheap because only one primary node (and optionally 1 or more backup nodes) need to be updated for every key. However, reads become somewhat more expensive because only certain nodes have the data cached.

In order to avoid extra data movement, it is important to always access the data exactly on the node that has that data cached. This approach is called affinity colocation and is strongly recommended when working with partitioned caches.

👍

Partitioned caches are ideal when working with large data sets and updates are frequent.

The picture below illustrates a simple view of a partitioned cache. Essentially we have key K1 assigned to Node1, K2 assigned to Node2, and K3 assigned to Node3.

See configuration section below for an example on how to configure cache mode.

Configuration

Cache modes are configured for each cache by setting the cacheMode property of CacheConfiguration like so:

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    ...
    <property name="cacheConfiguration">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
            <!-- Set a cache name. -->
            <property name="name" value="cacheName"/>
            
            <!-- Set cache mode. -->
                    <property name="cacheMode" value="PARTITIONED"/>
                    ... 
        </bean
    </property>
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration("myCache");

cacheCfg.setCacheMode(CacheMode.PARTITIONED);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

// Start Ignite node.
Ignition.start(cfg);

Atomic Write Order Mode

When using partitioned cache in CacheAtomicityMode.ATOMIC mode, one can configure atomic cache write order mode. Atomic write order mode determines which node will assign write version (sender or primary node) and is defined by CacheAtomicWriteOrderMode enumeration. There are 2 modes, CLOCK and PRIMARY.

In CLOCK write order mode, write versions are assigned on a sender node. CLOCK mode is automatically turned on only when CacheWriteSynchronizationMode.FULL_SYNC is used, as it generally leads to better performance since write requests to primary and backups nodes are sent at the same time.

In PRIMARY write order mode, cache version is assigned only on primary node. In this mode the sender will only send write requests to primary nodes, which in turn will assign write version and forward them to backups.

Atomic write order mode can be configured via atomicWriteOrderMode property of CacheConfiguration.

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    ...
    <property name="cacheConfiguration">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
            <!-- Set a cache name. -->
            <property name="name" value="cacheName"/>
            
            <!-- Atomic write order mode. -->
                    <property name="atomicWriteOrderMode" value="PRIMARY"/>
                    ... 
        </bean
    </property>
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setName("cacheName");

cacheCfg.setAtomicWriteOrderMode(CacheAtomicWriteOrderMode.CLOCK);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

// Start Ignite node.
Ignition.start(cfg);

📘

For more information on ATOMIC mode, refer to Transactions section.

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    ...
    <property name="cacheConfiguration">
        <bean class="org.apache.ignite.configuration.CacheConfiguration">
            <!-- Set a cache name. -->
            <property name="name" value="cacheName"/>
          
            <!-- Set cache mode. -->
                    <property name="cacheMode" value="PARTITIONED"/>
            
            <!-- Number of backup nodes. -->
                    <property name="backups" value="1"/>
                    ... 
        </bean
    </property>
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setName("cacheName");

cacheCfg.setCacheMode(CacheMode.PARTITIONED);

cacheCfg.setBackups(1);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

// Start Ignite node.
Ignition.start(cfg);

Updated less than a minute ago

Cache Modes


Setup different distribution models, backup copies, and near caches.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.