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

Partition Loss Policies

It may happen that throughout the cluster’s lifecycle that some of the data partitions get lost due to a failure of all primary and backup nodes that held a copy of the partitions. This situation leads to a partial data loss and needs to be addressed according to your use case. For instance, some applications treat this as an urgent issue blocking all write operations that go to the lost partitions while the others might ignore this event because the lost data can be repopulated over the time.

Policies

Ignite supports the following PartitionLossPolicies:

  • READ_ONLY_SAFE - all writes to a cache/table will fail with an exception. Reads will only be allowed for entries belonging to survived/alive partitions. Reads from lost partitions will fail with an exception.
  • READ_ONLY_ALL - reads are allowed from any partition including the lost ones. An exception is thrown in an attempt to write to any partition. The result of reading from a lost partition is undefined and may be different on different nodes in the cluster.
  • READ_WRITE_SAFE - all reads and writes are allowed for entries in survived/alive partitions. All reads and writes of entries belonging to the lost partitions will fail with an exception.
  • READ_WRITE_ALL - all reads and writes will proceed as if all partitions were in a consistent state (as if no partition loss happened). The result of reading from a lost partition is undefined and may be different on different nodes in the cluster.
  • IGNORE - this mode never marks a lost partition as lost, pretending that no partition loss has happened and clearing the partition loss state right away. Technically, the partition will not be added to the collection of lostPartitions which is the main difference from READ_WRITE_ALL mode. The result of reading from a lost partition is undefined and may be different on different nodes in the cluster. IGNORE mode is used by default.

The partition loss policy is configured per cache:

<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 partition loss policy. -->
            <property name="partitionLossPolicy" value="READ_ONLY_SAFE"/>
            <!-- Other cache configurations. -->
            ... 
        </bean>
    </property>
</bean>
CacheConfiguration cfg = new CacheConfiguration("cacheName");

// Set partition loss policy to READ_ONLY_SAFE
cfg.setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE);

Processing Partition Loss Events

Apache Ignite provides several facilities for handling partition loss events.

First, make sure to subscribe to the EVT_CACHE_REBALANCE_PART_DATA_LOST event to receive a notification every time a partition is lost:

Ignite ignite = Ignition.ignite();

// Local listener that listenes to local events.
IgnitePredicate<CacheEvent> locLsnr = evt -> {
  System.out.println("Received event [evt=" + evt.name() + "]");

  return true; // Continue listening.
};

// Subscribe to specified cache events occuring on local node.
ignite.events().localListen(locLsnr,
  EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST);

Next, if the application logic requires getting all the lost partitions at some point in time, then make sure to use the IgniteCache.lostPartitions() method:

// Cache reference
IgniteCache cache;

// Getting a list of the lost partitions.
Collection<Integer> lostPartitions = cache.lostPartitions();

// Performing some actions upon the partitions.
...

Finally, once you are sure that all the lost partitions are recovered (for example, after the previously​ failed primary and backup nodes that stored partitions' data in Ignite persistence are booted) use the Ignite.resetLostPartitions(...) method to clear the lost flag making all partitions fully operational:

// Clear partition's lost state and moves caches to a normal mode.
ignite.resetLostPartitions(Arrays.asList("cache1", "cache2"));

// check that there are no more lost partitions
boolean lostPartiion = cache.lostPartitions().isEmpty()

Updated 10 months ago

Partition Loss Policies


Suggested Edits are limited on API Reference Pages

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