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

Configuring Partition Backups

In PARTITIONED mode, the nodes to which the keys are assigned are called primary nodes for those keys. You can also optionally 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.