Wednesday, 23 May 2012

Cassandra Rescue Guide

You see, things can
go worse...
If you're using Cassandra to store your data, I guess you do it because they are a lot! In that case you wouldn't risk losing them because something went wrong... This post is a short rescue guide for Cassandra going a bit further from how to backup and restore your data (read this). This post is mostly concerned with more extreme situations where you restart your server to find out that your precious keyspace is not there!!! Don't panic! As you see in the picture (left) things can go much worse...

 

 Before it happens

In order to avoid loss of data, it's good to keep a copy of your schema generation code somewhere. You can create it from within cqlsh (CQL Shell) or using the Cassandra Client (cassandra-cli). Export your KS generation code in a file and keep it under lock and key. For example, using cli, create a file called schema_export and add in it the following lines:

Monday, 21 May 2012

Cassandra and Hector #1

Hector and Andromache
by Giorgio de Chirico, 1917
Galleria Nazionale d'Arte Moderna
Rome, Italy, Oil on canvas
Following the previous post on Apache Cassandra, this one will serve as a step-by-step beginner's guide to Hector; a Java API for accessing the Cassandra Key-Value Store. [It is assumed that you have already installed Cassandra, version 1.1.0.]. We will learn how to create a Keyspace and a Column Family, how to register data and retrieve values given their key.

Thrift

Thrift is a client API to the Cassandra database. Thrift is a low-level API not intended to be used directly by developers unless they need to build their own library for accessing Cassandra (for example for a not-supported programming language). In this tutorial we'll be using Hector - a high-level API for Java; but before that we need to install Thrift. For that download version 0.8.0 from http://thrift.apache.org/download/ or from the terminal:

Thursday, 17 May 2012

Cassandra - The Legend

According to the myth, Cassandra, the daughter of Priam - king of Troy - and Hecuba, was asked by the god Apollo for her love and devotion. Cassandra had resorted to giving divination as a freelancer after a long period in unemployment. Her decline to Apollo's proposal provoked the god's wrath who cursed her to have a bad lot as a prophet; her divination would not be believed any longer. A long period of frustration followed; but Cassandra was cunning and along with some native Americans, the Apache, they built a Key-Value store called after their names... That's more or less how Apache Cassandra was created.  

Wednesday, 16 May 2012

Tips on Java and SSL Certificates

It is often the case that one needs to connect to a secure location over HTTP from within Java. Unless java knows that the host should be trusted, the connection will be dropped and an exception will be thrown. For that reason you need to add the host's SSL certificate to the keystore of your JVM.

Following these instructions you will be able to install to your local keystore the SSL certificates that your application needs to connect to a remote server over SSL. First download and unzip the archive InstallCert from http://opentox.ntua.gr/files/InstallCert.zip.

Tuesday, 15 May 2012

Pairs of entities in a NoSQL database

In this blog post we address the problem of many-to-many self references in a relational database and how one can handle it using caching with emphasis on the theoretical and implementational aspects of the program using Java and MySQL.

Let us assume that you need to register some entities in your database (e.g. Person) and pairs of them (e.g. Friendship). 

Respective ER Diagram




Monday, 14 May 2012

Bitset to String and vice versa

A Bit Set - Nothing to do
with the Java class...
BitSet ("a vector of bits that grows as needed") can easily be serialized into String. In case one needs to convert the serialized String back to a BitSet object, here's a snippet:

Tuesday, 8 May 2012

The amazing ByteArrayOutputStream

The use of streams can boost
the performance of your application.

It is often the case that a method writes its output to an OutputStream, but, it happens that you simply want the output as a String. This is the case when you need to make use of the class ByteArrayOutputStream.