Aerospike NoSQL Database – First Contact

2 Comments

Just by pure chance I was stumbling upon Aerospike, a NoSQL data store that I had never heard of so far. Browsing a bit on the product’s homepage it sounds really interesting to me and so why not giving it a try. Quickly the plan was born to get a local installation of the community version up and running. Then on top of this installation writing some kind of Java sample-application to collect and store data to the system. And of course do some blogging on the whole thing :). Let’s see how far we come in what will probably be the first in a small series of blog posts on the topic.

In my “real life projects” big RDMS databases like DB2 and Oracle are still ruling the scenery. But as there are projects in our company running MongoDB (another NoSQL database) the concepts of NoSQL data stores are not totally new for me. And as I was blogging on MongoDB quite extensively there will be for sure one or the other comparison between the two systems in the following.

Getting Started – The Installation

After reading a bit through the “advertising parts” on the Aerospike homepage I went over to the documentation. Quickly I started to realize that my Windows PC will do me no good when trying to install Aerospike as it is requiring certain Linux distributions for installation. For a quick evaluation this is of course not so nice, but on the other hand Linux is for sure a good choice for a productive environment and thus the first thing is to get a new CentOS image up and running in my VirtualBox.

Areospike is requiring a 64-bit Linux system. I realised this when I was half through installing my 32-bit CentOS system. (From the column “learn from my mistakes”.)

Working through the installation instructions is pretty straight forward. When installing citrusleaf-tools a missing dependency needs to be resolved first. Luckily this is done pretty quickly.

The missing dependency “python-ctypes is needed by citrusleaf-tools-2.6.7.1.e15.x86_64″ could be easily resolved using “yum install python-ctypes”.

Starting the server and checking the status then shows a very nice result. So overall the installation was really smooth and without any big question marks. Of course this was only a one-node installation. Probably running Aerospikey on several nodes will require a bit more administrative work. Furthermore there are different options available for storing the data like in memory with or without persistence or on SSD with indexes in memory. In a real life project all these things must be evaluated carefully of course.

[root@centos64 opt]# /etc/init.d/citrusleaf start
Starting citrusleaf:                                       [  OK  ]
[root@centos64 opt]# /etc/init.d/citrusleaf status
cld (pid  3815) is running...
[root@centos64 opt]#

What’s next? – Inserting data!

Ok, now that it seems that we have an up and running Aerospike instance the natural next step is to try and insert some data to it. The goal of this self-experiment is to write some kind of Java application to store and read data using Aerospike. But of course the first – and usually easier – step is to use the command line interface for this.

Here the first small surprise is awaiting me. The concept of using a command line interface is very different from the one I experienced in MongoDB. While in MongoDB the shell is really powerful Aerospike has obviously different priorities here providing only very basic access to the stored data through the shell. Of course this is fine because the documentation is very clear about this point and does not raise any false expectations here.

The following excerpt from the shell is showing how to perform some basic operation to store and retrieve some data to the pre-configured “test” namespace.

[root@centos64 opt]# cli -h 127.0.0.1 -n test -o set -k codecentric -b name \
    -v "codecentric AG"
succeeded:  key = codecentric  set=   bin= name  value= codecentric AG
[root@centos64 opt]# cli -h 127.0.0.1 -n test -o set -k codecentric -b web \
    -v "www.codecentric.de"
succeeded:  key = codecentric  set=   bin= web  value= www.codecentric.de
[root@centos64 opt]# cli -h 127.0.0.1 -n test -o get -k codecentric
{'web': 'www.codecentric.de', 'name': 'codecentric AG'}

The provided functionality is indeed quite rudimentary. In principle I think it is quite nice – also as a means for troubleshooting – to have a comfortable shell to query the data. This I would miss to some extend here.

For managing the system as such there are additional tools available. clmonitor for example can be used to show information on “Nodes” and “Namespaces” (beside other information). I will not dig into the details of this as I look at the whole thing more from a programming point of view, not so much from a system administrators point of view.

Java Access – the real thing!

What we really want to do is accessing data from a Java application. So let’s get started by following the instructions for setting up the Java client for Aerospike. When building the whole thing using Maven there are some problems, but nothing related to Aerospike but more to my brand new CentOS image and some missing settings. After installing the latest Java 7 SDK and Maven 3.05 version everything is working very nicely.

With some small adjustments to the Java example provided in the documentation I am able to read out the values I stored to the system previously using the shell. As I was a little bit too lazy 😉 to setup a complete Maven project right away I only included the required JARs to my Eclipse project. This looks then basically like this:

Aerospike JAR Dependencies

Aerospike JAR Dependencies

The Java implementation for reading out the values is then quite easy when using the sample project as a template. The only thing that required short thinking was the name to be used for the “set”-parameter when creating the Key-object. Well, it was empty when I created the entry using the shell and thus … :-).

package de.mysample.aerospike;
 
import java.util.Map;
 
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.policy.WritePolicy;
 
public final class Test {
    public static void main(String[] args) {
        try {
            runTest();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void runTest() throws AerospikeException {       
        AerospikeClient client = new AerospikeClient("127.0.0.1", 3000);
 
        try {
            // Initialize policy.
            WritePolicy policy = new WritePolicy();
            policy.timeout = 50;  // 50 millisecond timeout.
 
            // Write a single value.
            Key key = new Key("test", "", "codecentric");
 
            // Read a single value.
            Record record = client.get(policy, key, "name");            
 
            if (record != null) {
                System.out.println("Got name: " + record.getValue("name"));
            }
 
            // Read multiple values.
            record = client.get(policy, key);
 
            if (record != null) {
                System.out.println("Found record: Expiration=" + record.expiration + " Generation=" + record.generation);
                for (Map.Entry<String,Object> entry : record.bins.entrySet()) {
                    System.out.println("Name=" + entry.getKey() + " Value=" + entry.getValue());
                }
            }
 
            // Delete record.
            client.delete(policy, key);        
        }
        finally {
            client.close();
        }
    }
}

Running the application then shows the following – quite expected – output:

Got name: codecentric AG
Found record: Expiration=112704333 Generation=2
Name=name Value=codecentric AG
Name=web Value=www.codecentric.de

So basically after starting around 8:00 o’clock in the morning now roughly six hours later I am having a running test installation and a first minimal Java application that is able to read some data from it. Therefore I would say that in terms of documentation and ease-of-use Aerospike has completed this first evaluation quite bravely.

The summary – So far

So far it is fun using the system. Things are mostly working as expected. The only real problem I had was when I was trying to get one additional tool to run, namely the Aerospike Monitoring Console. This was simply not working, but I will give it a try separately I guess. As the primary goal was to get the access from a Java application up and running I did not spend too much time on troubleshooting that part.

The access from Java was implemented quickly. As usual here the main issue is to get all required and dependent JAR-files, which was solved quite nicely in the installation of the Java client. Now the next step will be to try and write a bit more complex sample application to get a better idea on the implementation concepts.

Finally one feature of Aerospike that looks very promising for a NoSQL database is the guarantee of strong data consistency (ACID). Probably nothing that can be easily tested with a simple demo application, but at least something that might be relevant when evaluating NoSQL data stores more thoroughly. Some of the concepts used can also be derived from the glossary that is provided as part of the documentation.

This is to be continued hopefully not too far in the future :) and I hope you liked this short article on Aerospike.

Author

Thomas Jaspers

Share on FacebookGoogle+Share on LinkedInTweet about this on TwitterShare on RedditDigg thisShare on StumbleUpon

Kommentare

  • Thank you for testing out Aerospike Community Edition. I have taken note of the issues you faced and we are fixing the issues now. Please do not hesitate to let us know if you have any questions.

  • Certain aspects of ACID can be tested quite easily.

    – Create a new namespace
    – begin a transaction
    – insert n (n >= 1) new documents
    – rollback
    – expected result: no documemts

Comment

Your email address will not be published. Required fields are marked *