GridGain Developers Hub
GitHub logo GridGain iso GridGain.com
GridGain Software Documentation

Configuring Partition Backups

By default, GridGain keeps a single copy of each partition (a single copy of the entire data set). In this case, if one or multiple nodes become unavailable, you lose access to partitions stored on these nodes. To avoid this, you can configure GridGain to maintain back-up copies of each partition.

Backup copies are configured per cache (table). If you configure 2 backup copies, the cluster will maintain 3 copies of each partition. One of the partitions is called the primary partition, and the other two backup partitions. By extension, the node that has the primary partition is called the primary node for the keys stored in the partition. The node with backup partitions is called the backup node.

Backup partitions increase availability of your data and in some cases the speed of read operations, since GridGain will read data from backed-up partitions if they are available on the local node. However, they also increase memory consumption or the size of the persistent storage (if enabled).

You can configure any number of backup nodes for cached data. If the number of backups is greater than 0, then Ignite will automatically assign backup nodes for each individual key. For example if the number of backups is 1, then every key cached in the data grid will have 2 copies, 1 primary and 1 backup.

Configuring Backups

<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 the node.
Ignition.start(cfg);

Synchronous and Asynchronous Backups

You can configure whether updates of primary and backup copies should be synchronous or asynchronous by specifying a write synchronization mode. Write synchronization mode can be set in the cache configuration:

<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 write synchronization mode. -->
          <property name="writeSynchronizationMode" value="FULL_SYNC"/>
        </bean>
    </property>
</bean>
CacheConfiguration cacheCfg = new CacheConfiguration();

cacheCfg.setName("cacheName");

cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

IgniteConfiguration cfg = new IgniteConfiguration();

cfg.setCacheConfiguration(cacheCfg);

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

The write synchronization mode can be set to the following values:

Value Description

FULL_SYNC

Client node will wait for write or commit to complete on all participating remote nodes (primary and backup).

FULL_ASYNC

Client node does not wait for responses from participating nodes, in which case remote nodes may get their state updated slightly after any of the cache write methods complete or after the Transaction.commit() method completes.

PRIMARY_SYNC

This is the default mode. Client node will wait for write or commit to complete on primary node, but will not wait for backups to be updated.