TitanDB索引状态未改变。

5

我想删除一个现有的索引,到目前为止我已经按照文档中的步骤做了。目前我没有单独的索引后端配置。然而,在执行 m.awaitGraphIndexStatus 等待索引状态发生变化的步骤时,它会无限期地等待变化,并在超时时出现以下错误:

GraphIndexStatusReport[success=false, indexName='usernameComposite', targetStatus=DISABLED, notConverged={username=INSTALLED}, converged={}, elapsed=PT1M0.092S]

当我尝试创建新的索引时,出现了同样的情况。有什么想法是什么原因导致的?
我使用以下代码段来创建索引:
graph.tx().rollback()
mgmt = graph.openManagement()
name = mgmt.getPropertyKey('username')
mgmt.buildIndex('username-composite', Vertex.class).addKey(name).unique().buildCompositeIndex()
mgmt.commit()
mgmt.awaitGraphIndexStatus(graph, 'username-composite').call()

你能否发布一下你用来更改索引的步骤/代码? - Filipe Teixeira
我在上面编辑了我的帖子。 - Tim Specht
2个回答

6

当我尝试创建新的索引时,也会发生这种情况。我使用脚本在某个属性下创建一个带有一些数据的新索引。该脚本来自于Titan 1.0.0文档

graph.tx().rollback() //Never create new indexes while a transaction is active
mgmt = graph.openManagement()
name = mgmt.getPropertyKey('name')
age = mgmt.getPropertyKey('age')
mgmt.buildIndex('byNameComposite', Vertex.class).addKey(name).buildCompositeIndex()
mgmt.buildIndex('byNameAndAgeComposite', Vertex.class).addKey(name).addKey(age).buildCompositeIndex()
mgmt.commit()
//Wait for the index to become available
mgmt.awaitGraphIndexStatus(graph, 'byNameComposite').call()
mgmt.awaitGraphIndexStatus(graph, 'byNameAndAgeComposite').call()
//Reindex the existing data
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX).get()
mgmt.updateIndex(mgmt.getGraphIndex("byNameAndAgeComposite"), SchemaAction.REINDEX).get()
mgmt.commit()

经过多次实验,我发现graph.tx().rollback()不能正常工作。

gremlin> :> graph.getOpenTransactions()
==>standardtitantx[0x1e14c346]
==>standardtitantx[0x7a0067f2]
==>standardtitantx[0x0de3ee40]
==>standardtitantx[0x47e19812]
==>standardtitantx[0x27b20549]
==>standardtitantx[0x0ee46d99]
gremlin> :> graph.tx().rollback()
==>null
gremlin> :> graph.getOpenTransactions()
==>standardtitantx[0x1e14c346]
==>standardtitantx[0x7a0067f2]
==>standardtitantx[0x0de3ee40]
==>standardtitantx[0x47e19812]
==>standardtitantx[0x093ac20f]
==>standardtitantx[0x27b20549]
==>standardtitantx[0x0ee46d99]

这就是为什么我无法创建一个新索引。因此,我用graph.tx().rollback()替换了它。
// rollback all exist transactions
int size = graph.getOpenTransactions().size();
for(i=0;i<size;i++) {graph.getOpenTransactions().getAt(0).rollback()}

现在它运行良好。如果您使用集群,则需要确保仅一个实例生存。否则,您必须确保集群中所有实例的事务都回滚或提交。

希望这对其他人有所帮助。


4
如Dan在这篇gremlin-users帖子中所述,您需要确保没有打开的事务与图形相关联。请记住,这包括来自其他连接的事务,以防您对图形打开了多个客户端或线程。

您可以使用graph.getOpenTransactions()检查是否有未关闭的事务,该方法定义在StandardTitanGraph中,如果没有则返回null。如果有未关闭的事务,则需要将它们全部commit()rollback()

以下是我在Gremlin Console中成功使用过的代码片段。

// Disable the index. Once the able is DISABLED, it cannot be re-enabled again!
// Instead, you could build a new index with the same properties.
future = null
if (graph.getOpenTransactions()) graph.tx().rollback()
mgmt = graph.openManagement()
name = mgmt.getPropertyKey('name')
nameIndex = mgmt.getGraphIndex('nameIndex')
nameIndexStatus = nameIndex.getIndexStatus(name) // must be ENABLED, INSTALLED, or REGISTERED
if (nameIndexStatus == SchemaStatus.INSTALLED || nameIndexStatus == SchemaStatus.ENABLED) future = mgmt.updateIndex(nameIndex, SchemaAction.DISABLE_INDEX)
nameIndexStatus = nameIndex.getIndexStatus(name) // should be INSTALLED here
mgmt.commit()

// Block until disabling index is complete (ENABLED -> INSTALLED -> DISABLED), no metrics are reported (null)
if (graph.getOpenTransactions()) graph.tx().rollback()
t = System.currentTimeMillis(); metrics = future.get(); 'disabled in '+(System.currentTimeMillis()-t)+' ms'
if (nameIndexStatus == SchemaStatus.ENABLED) mgmt.awaitGraphIndexStatus(graph, 'nameIndex').status(SchemaStatus.INSTALLED).call()
if (nameIndexStatus == SchemaStatus.INSTALLED) mgmt.awaitGraphIndexStatus(graph, 'nameIndex').status(SchemaStatus.DISABLED).call()

换句话说,如果我正在运行多个Gremlin服务器以支持大量并发事务,那么在对任何索引进行维护之前,我需要将它们全部关闭,是吗? - Tim Specht
还有一个跟进的问题:如果我在使用相同管理事务创建索引的同时创建属性,是否也需要停止所有机器? - Tim Specht
如果您在同一管理事务中创建新的属性键和索引,则我认为提交后应立即启用该索引。 - Jason Plurad

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