Change default keyspace of Titan DB on Cassandra

A 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.

You can find all of Cassandra specific Titan Graph Configurations here.

To change the database(I'm sorry I have used the word database instead of the 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 log in. This is how they mention 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 on 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!

Tags

  • Titan DB
  • Titan and Cassandra
  • Titan