How to delete graph in Titan with Cassandra storage backend?
Asked Answered
R

4

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.

Rompish answered 20/10, 2013 at 12:43 Comment(0)
M
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.

Melisma answered 20/10, 2013 at 13:2 Comment(7)
So deleting the Cassandra data directory will completely remove the graph including the index I don't want?Rompish
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.Melisma
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?Rompish
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.Melisma
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.Rompish
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.Melisma
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.Grimace
G
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);
Gorky answered 21/7, 2016 at 15:38 Comment(2)
Saved my life phew.Joker
For the new Titan, JanusGraph, the command is JanusGraphCleanup.clear() but is soon to be JanusGraphCleanup.clear()Selfreliance
S
3

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

Selfreliance answered 15/2, 2018 at 1:0 Comment(0)
V
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
Varicella answered 23/1, 2015 at 20:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.