Beliebte Suchanfragen

Cloud Native

DevOps

IT-Security

Agile Methoden

Java

//

Aerospike NoSQL Database – First Contact

27.6.2013 | 7 minutes of reading time

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.

1[root@centos64 opt]# /etc/init.d/citrusleaf start
2Starting citrusleaf:                                       [  OK  ]
3[root@centos64 opt]# /etc/init.d/citrusleaf status
4cld (pid  3815) is running...
5[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.

1[root@centos64 opt]# cli -h 127.0.0.1 -n test -o set -k codecentric -b name \
2    -v "codecentric AG"
3succeeded:  key = codecentric  set=   bin= name  value= codecentric AG
4[root@centos64 opt]# cli -h 127.0.0.1 -n test -o set -k codecentric -b web \
5    -v "www.codecentric.de"
6succeeded:  key = codecentric  set=   bin= web  value= www.codecentric.de
7[root@centos64 opt]# cli -h 127.0.0.1 -n test -o get -k codecentric
8{'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

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 … :-).

1package de.mysample.aerospike;
2 
3import java.util.Map;
4 
5import com.aerospike.client.AerospikeClient;
6import com.aerospike.client.AerospikeException;
7import com.aerospike.client.Key;
8import com.aerospike.client.Record;
9import com.aerospike.client.policy.WritePolicy;
10 
11public final class Test {
12    public static void main(String[] args) {
13        try {
14            runTest();
15        }
16        catch (Exception e) {
17            e.printStackTrace();
18        }
19    }
20 
21    public static void runTest() throws AerospikeException {       
22        AerospikeClient client = new AerospikeClient("127.0.0.1", 3000);
23 
24        try {
25            // Initialize policy.
26            WritePolicy policy = new WritePolicy();
27            policy.timeout = 50;  // 50 millisecond timeout.
28 
29            // Write a single value.
30            Key key = new Key("test", "", "codecentric");
31 
32            // Read a single value.
33            Record record = client.get(policy, key, "name");            
34 
35            if (record != null) {
36                System.out.println("Got name: " + record.getValue("name"));
37            }
38 
39            // Read multiple values.
40            record = client.get(policy, key);
41 
42            if (record != null) {
43                System.out.println("Found record: Expiration=" + record.expiration + " Generation=" + record.generation);
44                for (Map.Entry<String,Object> entry : record.bins.entrySet()) {
45                    System.out.println("Name=" + entry.getKey() + " Value=" + entry.getValue());
46                }
47            }
48 
49            // Delete record.
50            client.delete(policy, key);        
51        }
52        finally {
53            client.close();
54        }
55    }
56}

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.

share post

Likes

0

//

More articles in this subject area

Discover exciting further topics and let the codecentric world inspire you.

//

Gemeinsam bessere Projekte umsetzen.

Wir helfen deinem Unternehmen.

Du stehst vor einer großen IT-Herausforderung? Wir sorgen für eine maßgeschneiderte Unterstützung. Informiere dich jetzt.

Hilf uns, noch besser zu werden.

Wir sind immer auf der Suche nach neuen Talenten. Auch für dich ist die passende Stelle dabei.