持久化数据、并发访问和清除 Titan DB

Posted

技术标签:

【中文标题】持久化数据、并发访问和清除 Titan DB【英文标题】:Persistent data, concurrent access and clear Titan DB 【发布时间】:2014-07-10 09:21:17 【问题描述】:

我对 Titan Graph 蓝图和 gremlin 有不同的疑问。实际上,我尝试在 Ubuntu 上的 java 程序中实现 Titan 图,但我有不同的问题。我使用的是titanGraph v0.4.4。

第一次,你可以在 Java 程序中看到我的 Titan 配置:

        BaseConfiguration config = new BaseConfiguration();
        Configuration storage = config.subset(GraphDatabaseConfiguration.STORAGE_NAMESPACE);

        // configuring local backend
        storage.setProperty(GraphDatabaseConfiguration.STORAGE_BACKEND_KEY, "local");
        storage.setProperty(GraphDatabaseConfiguration.STORAGE_DIRECTORY_KEY, "/tmp/testdbtitan");

        // configuring elastic search index
        Configuration index = storage.subset(GraphDatabaseConfiguration.INDEX_NAMESPACE).subset(INDEX_NAME);
        index.setProperty(INDEX_BACKEND_KEY, "elasticsearch");
        index.setProperty("local-mode", true);
        index.setProperty("client-only", false);
        index.setProperty(STORAGE_DIRECTORY_KEY, directory + File.separator + INDEX_NAME);

        TitanGraph graph = TitanFactory.open(config);
        graph.createKeyIndex("uuid", Vertex.class);

        return graph;

之后,我创建一个顶点:

Vertex r = graph.addVertex(null);
r.setProperty("name", "akrogames");
graph.commit();

所以,我的 Java 程序中有一个顶点,但使用 gremlin 我看不到这个顶点:

gremlin> g = TitanFactory.open('/tmp/testdbtitan') 
gremlin> g.V.count()
==>0

我不明白为什么我有这个问题......

然后,我尝试使用我的 java 程序的不同实例访问我的数据库,但这不可能,因为 Titan 中有一个锁。这对我来说是个问题,因为我想访问不同的用户。请帮帮我...

最后,我无法清理我的 Titan DB,因为我有一个例外:

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

我有这个例外:

Exception in thread "main" com.thinkaurelius.titan.core.TitanException: Unexpected exception
 during backend operation
        at com.thinkaurelius.titan.diskstorage.util.BackendOperation.execute(BackendOperation.java:67)
        at com.thinkaurelius.titan.core.util.TitanCleanup.clear(TitanCleanup.java:32)
        at xxxx.xxxx.xxxxxx.xxxxx.xxxxxx.clearDB(XXXXXXX.java:365)
     Caused by: java.lang.NullPointerException
        at com.thinkaurelius.titan.util.system.IOUtils.deleteDirectory(IOUtils.java:24)
        at com.thinkaurelius.titan.util.system.IOUtils.deleteDirectory(IOUtils.java:26)
        at com.thinkaurelius.titan.util.system.IOUtils.deleteFromDirectory(IOUtils.java:17)
        at com.thinkaurelius.titan.diskstorage.berkeleyje.BerkeleyJEStoreManager.clearStorage(BerkeleyJEStoreManager.java:169)
        at com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.OrderedKeyValueStoreManagerAdapter.clearStorage(OrderedKeyValueStoreManagerAdapter.java:59)
        at com.thinkaurelius.titan.diskstorage.Backend.clearStorage(Backend.java:465)
        at com.thinkaurelius.titan.core.util.TitanCleanup$1.call(TitanCleanup.java:35)
        at com.thinkaurelius.titan.core.util.TitanCleanup$1.call(TitanCleanup.java:32)
        at com.thinkaurelius.titan.diskstorage.util.BackendOperation.execute(BackendOperation.java:62)
        ... 5 more

我有这个异常,但是我的数据库被清理了......这很奇怪

谢谢。

【问题讨论】:

【参考方案1】:

我觉得这很可疑:

gremlin> g = TitanFactory.open('/tmp/testdbtitan') 
gremlin> g.V.count()
==>0

当我打开 TitanGraph 时,它看起来像这样:

gremlin> g = TitanFactory.open('/tmp/titan')
==>titangraph[local:/tmp/titan]

不确定您是否剪切并粘贴了 Gremlin 会话 sn-p 错误或其他问题,但如果 g 没有打印任何内容,则显然有问题。除此之外,为什么不通过构建 Configuration 对象(或使用属性文件)在 Gremlin 控制台中打开图形,就像在 Java 中一样?这似乎特别重要,因为您使用 ElasticSearch 作为您正在使用的速记方法不会连接到它。

我尝试使用我的 java 程序的不同实例访问我的数据库 但这是不可能的,因为泰坦中有一把锁。它是 对我来说有问题,因为我想与不同的用户一起访问。

BerkeleyDB 不是为这个用例设计的。它适用于单个 JVM 进程。你有两个选择:

    使用 Rexster,这将有效地让您共享对它的访问权限

    使用不同的后端,例如 Cassandra 或 Hbase

    我无法清理我的 Titan DB,因为我有一个异常

此错误是否可重复?可以用一个简单的 Gremlin 会话复制它吗?如果是这样,请提供此类信息。如您所见,它似乎对我有用,听起来与您正在做的事情并没有太大不同:

gremlin> g = TitanFactory.open('/tmp/titan044')
==>titangraph[local:/tmp/titan044]
gremlin> g.shutdown()
==>null
gremlin> TitanCleanup.clear(g)
==>null
gremlin> g = TitanFactory.open('/tmp/titan044')
==>titangraph[local:/tmp/titan044]
gremlin> g.addVertex()
==>v[4]
gremlin> g.commit()
==>null
gremlin> g.shutdown()
==>null
gremlin> g = TitanFactory.open('/tmp/titan044')
==>titangraph[local:/tmp/titan044]
gremlin> g.V.count()
WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [()]. For better performance, use indexes
==>1
gremlin> g.shutdown()
==>null
gremlin> TitanCleanup.clear(g)
==>null

【讨论】:

您好斯蒂芬,感谢您的回复。所以,我很抱歉我没有剪切和粘贴小精灵。我有这个结果:gremlin> g = TitanFactory.open('/tmp/testdbtitan'); ==>titangraph[local:/tmp/testdbtitan] gremlin> g.V.count() ==>2 但是使用我的 java 程序,我列出了所有顶点,我得到了这个结果:4 40004 80004 120004 160004 200004 240004 With :for(Vertex vertex : this.model.query().vertices()) System.out.println(vertex.getId()); 我不知道为什么会这样,但我的印象是有 2 个数据库......但我有一个相同的目录......当我只使用 gremlin 时,效果很好...... . 不知道为什么 - 我再次建议您将配置转换为属性文件并使用相同的文件在两种环境中打开数据库。看看能不能解决问题。此外,如果您以后不想出现问题,请不要使用:graph.createKeyIndex("uuid", Vertex.class); 来定义索引。使用 Titan 原生方法:github.com/thinkaurelius/titan/wiki/Type-Definition-Overview 好的,斯蒂芬,在为我的 Java 程序和 gremlin 环境创建了一个属性文件之后,它就可以工作了。但这很奇怪。您有存储和索引系统的 Java 配置示例吗?对于索引,您使用 Elasticsearch 吗? 好...很高兴消除了差异。 Titan 发行版的conf 目录中有示例属性文件。我不会在日常使用中使用 ES,但如果我确实需要这样的解决方案,我希望使用 ES 而不是其他选项。

以上是关于持久化数据、并发访问和清除 Titan DB的主要内容,如果未能解决你的问题,请参考以下文章