Let’s dive deep into Apache Ignite


Let’s first have some basic understanding of Apache Ignite and then we will look more into its life cycle with the help of a demo application.

Apache Ignite is an in-memory computing platform that is durable strongly consistent and highly available with powerful SQL, key value and processing APIs.

Features :

  • Durable Memory : Apache Ignite is based on the Durable Memory architecture that allows storing and processing data and indexes both in memory and on disk when the Ignite Native Persistent feature is enabled.
  • Ignite Persistence : Ignite native persistence is a distributed, ACID, and SQL-compliant disk store that transparently integrates with Ignite’s durable memory. Ignite persistence is optional and can be turned on and off. When turned off Ignite becomes a pure in-memory store.With the the native persistence enabled, Ignite always stores a superset of data on disk, and as much as possible in RAM.
  • ACID Compliance : Data stored in Ignite is ACID-compliant both in memory and on disk, making Ignite a strongly consistent system. Ignite transactions work across the network and can span multiple servers. This makes Ignite stand out from the eventually consistent NoSQL systems that hardly support any type of transactions.

Installation Steps :

For installation of Apache Ignite, refer to the following steps:

Step 1 : Download Apache Ignite as ZIP archive from https://ignite.apache.org/

Step 2 : Unzip ZIP archive into the installation folder in your system

Step 3 : Set IGNITE_HOME environment variable to point to the installation folder (Optional)

Step 4 : Go to IGNITE_HOME and hit the following command from terminal:

i) To start a grid node with default configuration,

                       bin/ignite.sh

ii) To pass configuration file explicitly,

                      bin/ignite.sh examples/config/example-ignite.xml

    apache-ignite

When another server is up, below is the screenshot of its result.

apache-ignite-2

The last line tells the number of server and client nodes up. We can have as many nodes up as per our use case.

Common Dependencies

<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-core</artifactId>
    <version>${ignite.version}</version>
</dependency>


There are other dependencies which are available.

  • ignite-indexing (optional, add if you need SQL indexing)
  • ignite-spring (optional, add if you plan to use Spring configuration)
<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-spring</artifactId>
    <version>${ignite.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.ignite</groupId>
    <artifactId>ignite-indexing</artifactId>
    <version>${ignite.version}</version>
</dependency>

 Before moving to the demo application, let’s first have a look at the Ignite Life Cycle.

Ignite Life Cycle

Ignite is JVM-based. JVM represents one or more logical Ignite nodes. Therefore

Ignite runtime == JVM process == Ignite node (in most cases)

The Ignition class starts individual Ignite nodes in the network topology. Note that a physical server (like a computer on the network) can have multiple Ignite nodes running on it. Create cache on all the existing and future server nodes. Now, you can add put and get data from the cache.

Practical Application

My demo application consists of :

  1. Student – This is a POJO.
public Student(Integer rollNumber, String firstName, String lastName) {
    setRollNumber(rollNumber);
    setFirstName(firstName);
    setLastName(lastName);
}
  1. StudentData – It is an interface in which data of student is stored temporarily. From this, the data is fetched and saved into the cache.
public interface StudentData {
    static Student student1 = new Student(1,"Akhil","Singh");
    static Student student2 = new Student(2,"Ajay","Kapoor");
    static Student student3 = new Student(3,"Kunal","Malhotra");
}
  1. ExtractData – It creates an ignite node.Cache is created where the data of student is added using the method putStudentData. The data is then retrieved from the cache using getStudentData. Then it is simply displayed using displayStudentData. Although all these operations can be performed in a single method, I have created different since it is just a demo code and further creates clarification.
public class ExtractData implements StudentData {
    private static Ignite ignite = null;
    public static void main(String[] args) {
        // Enable client mode locally.
        Ignition.setClientMode(true);
        // Start Ignite in client mode.
        ignite = Ignition.start("/home/jasmine/Documents/Softwares/apache-ignite-fabric-1.9.0-bin/examples/config/example-ignite.xml");
        // Create cache on all the existing and future server nodes.
        IgniteCache<integer, string=""> cache = ignite.getOrCreateCache("demoCache");
        putStudentData(cache);
        List firstNameList = getStudentData(cache);
        displayStudentData(firstNameList);
    }
    /**
     * To put the data in the cache.
     * @param cache
     */
    private static void putStudentData(IgniteCache<integer, string=""> cache) {
        cache.put(student1.getRollNumber(), student1.getFirstName());
        cache.put(student2.getRollNumber(), student2.getFirstName());
        cache.put(student3.getRollNumber(), student3.getFirstName());
    }
    /**
     * To get the data from the cache.
     * @param cache
     * @return
     */
    private static List getStudentData(IgniteCache<integer, string=""> cache) {
        List firstNameList = new ArrayList();
        ClusterGroup clientGroup = ignite.cluster().forClients();
        IgniteCompute clientCompute = ignite.compute(clientGroup);
        // Execute computation on the client nodes.
        clientCompute.broadcast(() ->
        {
            firstNameList.add(cache.get(student1.getRollNumber()));
            firstNameList.add(cache.get(student2.getRollNumber()));
            firstNameList.add(cache.get(student3.getRollNumber()));
        });
        return firstNameList;
    }
    /**
     * To display that data.
     * @param firstNameList
     */
    private static void displayStudentData(List firstNameList){
        System.out.println("First Name of students in ascending order of roll number : \n");
        System.out.println(firstNameList.get(0));
        System.out.println(firstNameList.get(1));
        System.out.println(firstNameList.get(2));
    }
}

When you run the code, the output will be as follows:

Output

Here the number of server node and client node is one each.

The link for the above demo code is : https://github.com/jasmine-k/apache-ignite-demo

Reference : https://ignite.apache.org/

Advertisements
This entry was posted in Functional Programming, Java and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s