2016-01-06 59 views
3

我想放弃一个现有的索引,并按照文档中的步骤到目前为止。我目前没有单独的索引后端配置。然而,当我到达步骤,你必须等待索引状态使用m.awaitGraphIndexStatus它永远等待变化并且不与下面的错误次数改变:TitanDB索引不变状态

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

非常相同的,当我尝试发生创建一个新的。 任何想法可能导致这种情况?

我用下面的代码片段创建indizes:

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() 
+0

您可以发布您用来更改索引的步骤/代码吗? –

+0

我编辑过我的帖子。 –

回答

3

正如丹在这个gremlin-users post介绍,您需要确保有对图形没有打开的事务。请记住,这包括来自其他连接的事务,以防您有多个客户端或线程在图上打开。

您可以检查在StandardTitanGraph中定义的graph.getOpenTransactions()的未清交易,如果没有,则返回null。如果有公开交易,您需要commit()rollback()这些。

这是我在Gremlin控制台中成功使用的代码片段。

// 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() 
+0

换句话说,如果我运行多个gremlin服务器来支持大量的并发事务,那么在对任何指示符进行维护之前,我需要将它们全部放在一起,对吗? –

+0

听起来像它蒂姆。 –

+0

好的,非常感谢这个澄清。 –

2

它也发生在我尝试创建一个新的。我使用脚本在包含某些数据的属性下创建新的索引。该脚本来自Titan 1.0.0 Document

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()} 

现在工作正常。如果你使用集群,那么你需要确保只有一个实例才能生存。或者您必须确保群集中的所有实例事务都回滚或提交。 我希望这对他人有帮助。