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

Atomic Types

Atomics in Ignite can be read and updated from any node in the cluster.

Overview

Ignite supports distributed atomic long and atomic reference , similar to java.util.concurrent.atomic.AtomicLong and java.util.concurrent.atomic.AtomicReference respectively.

Atomics in Ignite are distributed across the cluster, essentially enabling performing atomic operations (such as increment-and-get or compare-and-set) with the same globally-visible value. For example, you could update the value of an atomic long on one node and read it from another node.

Features

  • Retrieve current value.
  • Atomically modify current value.
  • Atomically increment or decrement current value.
  • Atomically compare-and-set the current value to new value.

Distributed atomic long and atomic reference can be obtained via IgniteAtomicLong and IgniteAtomicReference interfaces respectively, as shown below:

Ignite ignite = Ignition.ignite();
 
IgniteAtomicLong atomicLong = ignite.atomicLong(
    "atomicName", // Atomic long name.
    0,        		// Initial value.
    false     		// Create if it does not exist.
)
Ignite ignite = Ignition.ignite();

// Create an AtomicReference.
IgniteAtomicReference<Boolean> ref = ignite.atomicReference(
    "refName",  // Reference name.
    "someVal",  // Initial value for atomic reference.
    true        // Create if it does not exist.
);

Below is a usage example of IgniteAtomicLong and IgniteAtomicReference:

Ignite ignite = Ignition.ignite();

// Initialize atomic long.
final IgniteAtomicLong atomicLong = ignite.atomicLong("atomicName", 0, true);

// Increment atomic long on local node.
System.out.println("Incremented value: " + atomicLong.incrementAndGet());
Ignite ignite = Ignition.ignite();

// Initialize atomic reference.
IgniteAtomicReference<String> ref = ignite.atomicReference("refName", "someVal", true);

// Compare old value to new value and if they are equal,
//only then set the old value to new value.
ref.compareAndSet("WRONG EXPECTED VALUE", "someNewVal"); // Won't change.

All atomic operations provided by IgniteAtomicLong and IgniteAtomicReference are synchronous. The time an atomic operation will take depends on the number of nodes performing concurrent operations with the same instance of atomic long, the intensity of these operations, and network latency.

IgniteCache interface has putIfAbsent() and replace() methods, which provide the same CAS functionality as atomic types.

Atomic Configuration

Atomics in Ignite can be configured via atomicConfiguration property of IgniteConfiguration. The following configuration parameters can be used :

Setter Method
Description
Default

setBackups(int)

Set number of backups.

0

setCacheMode(CacheMode)

Set cache mode for all atomic types.

PARTITIONED

setAtomicSequenceReserveSize(int)

Sets the number of sequence values reserved for IgniteAtomicSequence instances.

1000

Example

<bean class="org.apache.ignite.configuration.IgniteConfiguration">
    ...
    <property name="atomicConfiguration">
        <bean class="org.apache.ignite.configuration.AtomicConfiguration">
            <!-- Set number of backups. -->
            <property name="backups" value="1"/>
          	
          	<!-- Set number of sequence values to be reserved. -->
          	<property name="atomicSequenceReserveSize" value="5000"/>
        </bean>
    </property>
</bean>
AtomicConfiguration atomicCfg = new AtomicConfiguration();
 
// Set number of backups.
atomicCfg.setBackups(1);

// Set number of sequence values to be reserved. 
atomicCfg.setAtomicSequenceReserveSize(5000);

IgniteConfiguration cfg = new IgniteConfiguration();
  
// Use atomic configuration in Ignite configuration.
cfg.setAtomicConfiguration(atomicCfg);
  
// Start Ignite node.
Ignition.start(cfg);