如何在使用Cassandra存储后端的Titan中删除图形?

9
我使用Titan 0.4.0 All,在Ubuntu 12.04上以共享VM模式运行Rexster。
如何正确删除使用Cassandra存储后端的Titan图形?
我尝试了TitanCleanup.clear(graph),但它并没有删除所有内容。索引仍然存在。我的真正问题是我有一个不想要的索引(每次查询都会崩溃),但据我所知,根据Titan的文档一旦创建就无法删除索引
4个回答

10

您可以使用以下方法清除所有边缘/顶点:

g.V.remove()

但是,正如您发现的那样,这不会清除先前创建的类型/索引。最干净的选择是仅删除Cassandra数据目录。

如果您正在通过单元测试执行删除操作,可以尝试将其作为测试设置的一部分执行:

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)

在测试的拆卸方法中一定要调用g.shutdown()


那么删除Cassandra数据目录将完全删除图形,包括索引,这是我不想要的吗? - Automatico
1
是的...所有数据,包括索引,都存储在Cassandra中。我想你也可以在Cassandra中删除“titan”键空间(那是默认的键空间名称)。那也可以。 - stephen mallette
如果您删除了正确的数据目录(我认为Cassandra数据目录默认情况下是在您解压缩到的同一目录中创建的,除非您更改了它),我不明白您如何会收到指示索引已经存在的错误(当您重新打开图形时,Titan将重新创建该目录)。 我会验证您是否正在删除正确的数据目录。 正如我之前提到的,您可以使用Cassandra CLI并简单地删除keyspace ... 这也可以起作用。 - stephen mallette
3
最终做到了这个。我删除了机器上所有同名文件夹。我猜想Ubuntu在某处缓存了该进程或者类似的东西。我在嵌入模式下使用Titan-rexster,你可以运行 sudo bin/titan.sh clean 来重置数据库。 - Automatico
1
很高兴你让它工作了。需要注意的是,“clean”选项在0.4.0中是新推出的。在0.4.0中,Cassandra并不真正“嵌入”,它只是与Rexster一起打包在一个titan.sh中。 - stephen mallette
显示剩余2条评论

5

仅更新此回答。

使用 Titan 1.0.0,可以通过Java程序来完成:

TitanGraph graph = TitanFactory.open(config);
graph.close();
TitanCleanup.clear(graph);

救了我的命,呼! - jayant
对于新的Titan数据库JanusGraph,清除命令是JanusGraphCleanup.clear(),但很快将变为JanusGraphCleanup.clear()。 - rjurney

3

如果要继续使用名为JanusGraph的Titan,命令是JanusGraphFactory.clear(graph),但很快将改为JanusGraphCleanup.clear(graph)


1

正如早期回答的评论之一所提到的那样,使用cqlsh删除titan keyspace 应该可以通过DROP命令实现:

cqlsh> DROP KEYSPACE titan;

Titan使用的keyspace名称是通过storage.cassandra.keyspace配置选项设置的。您可以将其更改为任何您想要的名称,并且该名称应该被Cassandra接受。
storage.cassandra.keyspace=hello_titan

当Cassandra启动时,它会打印出keyspace的名称,如下所示:

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

0.9.0-M1中,名称出现在Titan的日志中,调试信息(在conf/log4j-server.properties中设置log4j.rootLogger=DEBUG, stdout):
[DEBUG] AstyanaxStoreManager - Found keyspace titan

当它不这样做时,请参考以下内容:
[DEBUG] AstyanaxStoreManager - Creating keyspace titan...
[DEBUG] AstyanaxStoreManager - Created keyspace titan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接