9

I use Titan 0.4.0 All, running Rexster in shared VM mode on Ubuntu 12.04.

How could I properly delete a graph in Titan which is using the Cassandra storage backend?

I have tried the TitanCleanup.clear(graph), but it does not delete everything. The indices are still there. My real issue is that I have an index which I don't want (it crashes every query), however as I understand Titan's documentation it is impossible to remove an index once it is created.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Automatico
  • 12,420
  • 9
  • 82
  • 110

4 Answers4

10

You can clear all the edges/vertices with:

g.V.remove()

but as you have found that won't clear the types/indices previously created. The most cleanly option would be to just delete the Cassandra data directory.

If you are executing the delete via a unit test you might try to do this as part of your test setup:

this.config = new BaseConfiguration(){{
    addProperty("storage.backend", "berkeleyje")
    addProperty("storage.directory", "/tmp/titan-schema-test")
}}
GraphDatabaseConfiguration graphconfig = new GraphDatabaseConfiguration(config)
graphconfig.getBackend().clearStorage()
g = (StandardTitanGraph) TitanFactory.open(config)

Be sure to call g.shutdown() in your test teardown method.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • So deleting the Cassandra data directory will completely remove the graph including the index I don't want? – Automatico Oct 20 '13 at 13:04
  • 1
    Yes...all data including indices is stored in Cassandra. I suppose you could also drop the "titan" keyspace (that's the default keyspace name anyway) in Cassandra. That would work too. – stephen mallette Oct 20 '13 at 16:41
  • I tried this, but when I delete the data folder cassandra (or possibly titan/rexster) recreates the folder and I still get the same error (some index exists that I don't want). I have tried deleting every cassandra folder I can find on the machine, rebooted the system etc. but the index is still there. Is there a way to definitively do this? Maybe cassandra console or something? – Automatico Oct 20 '13 at 20:04
  • If you deleted the correct data directory (I think the cassandra data directory is locally created in the same directory you unpack to by default, unless you changed it) I don't see how you could get an error stating that the index already exists (Titan will recreate the directory when you reopen the graph). I'd verify that you are deleting the right data directory. As I mentioned earlier you can use Cassandra CLI and simply drop the keyspace...that will work as well. – stephen mallette Oct 20 '13 at 22:55
  • 3
    Finally got this to work. I deleted every folder on the machine with the same name. I suspect ubuntu was caching the process somewhere or something like this. I am using Titan-rexster in embedded mode and there you can do: `sudo bin/titan.sh clean` to reset the database. – Automatico Oct 24 '13 at 13:49
  • 1
    Glad you got it to work. It should be noted that the "clean" option is newly available in 0.4.0. in 0.4.0 cassandra is not truly "embedded", it is just packaged together with rexster with a single `titan.sh`. – stephen mallette Oct 24 '13 at 14:21
  • Also see that when you manually delete the db/cassandra and db/es from the installed dexter or full titan, the server is not running, because it locks files, so you can't delete at less on OSX. – tyoc213 Jan 28 '14 at 03:23
5

Just to update this answer.

With Titan 1.0.0 this can be done programmatically in Java with:

TitanGraph graph = TitanFactory.open(config);
graph.close();
TitanCleanup.clear(graph);
Filipe Teixeira
  • 3,565
  • 1
  • 25
  • 45
3

For the continuation of Titan called JanusGraph, the command is JanusGraphFactory.clear(graph) but is soon to be JanusGraphCleanup.clear(graph).

rjurney
  • 4,824
  • 5
  • 41
  • 62
1

As was mentioned in one of the comments to the earlier answer DROPping a keyspace titan using cqlsh should do it:

cqlsh> DROP KEYSPACE titan;

The name of the keyspace Titan uses is set up using storage.cassandra.keyspace configuration option. You can change it to whatever name you want and is acceptable by Cassandra.

storage.cassandra.keyspace=hello_titan

When Cassandra is getting up, it prints out the keyspace's name as follows:

INFO 19:50:32 Create new Keyspace: KSMetaData{name=hello_titan, strategyClass=SimpleStrategy, strategyOptions={replication_factor=1}, cfMetaData={}, durableWrites=true, userTypes=org.apache.cassandra.config.UTMetaData@767d6a9f}

In 0.9.0-M1, the name appears in Titan's log in DEBUG (set log4j.rootLogger=DEBUG, stdout in conf/log4j-server.properties):

[DEBUG] AstyanaxStoreManager - Found keyspace titan

or the following when it doesn't:

[DEBUG] AstyanaxStoreManager - Creating keyspace titan...
[DEBUG] AstyanaxStoreManager - Created keyspace titan
Community
  • 1
  • 1
Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420