June 11, 2013

Change default keyspace of Titan DB on Cassandra

Long time ago I have posted about how to use Titan with Cassandra. But it will only use a database called "titan". Sometimes you may want to use two different databases in Cassandra backend. In that case we have to use Cassandra Specific Configurations.


To change the database(I'm sorry I have used the word database instead of keyspace.), I'll change storage.keyspace. But this is not a modifiable setting. That means once you have used one value for a graph, you can't change it next time when you login. This is how they mention about it.

It is very important to note that some configuration options should NEVER be modified after the TitanGraph is first initialized. Doing so may corrupt the graph or lead to unexpected behavior.-- https://github.com/thinkaurelius/titan/wiki/Graph-Configuration
I'll give code how to connect to a Titan DB with different keyspace(database). First go to cassandra bin and run.
Linux:
bash cassandra

Windows:
cassandra.bat

Then take gremlin from titan bin.

Linux:
bash gremlin.sh
Windows:
gremlin.bat
Then you have to configure storage backend. for that use following commands on gremlin.
cnf = new BaseConfiguration();
cnf.setProperty('storage.backend','cassandra');
cnf.setProperty('storage.hostname','127.0.0.1');
cnf.setProperty('storage.keyspace','graph1');
g = TitanFactory.open(cnf);
 In this case I have used Cassandra Local host instance. And the keyspace that I'm going to use with graph database is "graph1". You don't need to get limited to one keyspace on one instance!

Those two links will help you if you are going to try Titan for the first time!
Enjoy Graphs!

2 comments:

  1. Very useful information.

    Do you have any example of how to use Blueprint API with Titan Graph?


    ReplyDelete