【问题标题】:TitanDB Index not changing stateTitanDB 索引不改变状态
【发布时间】:2016-04-11 03:36:34
【问题描述】:

我想删除现有索引并按照文档中的步骤进行操作。我现在没有配置单独的索引后端。但是,当我到达您必须使用 m.awaitGraphIndexStatus 等待索引状态更改的步骤时,它会永远等待更改并超时并出现以下错误:

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

当我尝试创建一个新的时,也会发生同样的情况。 有什么想法会导致这种情况吗?

我正在使用以下代码 sn-p 创建 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()

【问题讨论】:

  • 您可以发布您用于更改索引的步骤/代码吗?
  • 我在上面编辑了我的帖子。

标签: titan gremlin tinkerpop


【解决方案1】:

当我尝试创建一个新的时也会发生这种情况。我使用脚本在包含一些数据的属性下创建一个新索引。脚本来自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()}

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

【讨论】:

    【解决方案2】:

    正如 Dan 在此 gremlin-users post 中所描述的,您需要确保没有针对图表的未结交易。请记住,这包括来自其他连接的事务,以防您针对图表打开多个客户端或线程。

    您可以使用StandardTitanGraph 中定义的graph.getOpenTransactions() 检查未结交易,如果没有,则返回null。如果有未结交易,您需要commit()rollback() 全部处理。

    这是我在 Gremlin 控制台中成功使用的一个 sn-p。

    // 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 服务器来支持大量并发事务,我需要在对任何 indizes 进行维护之前将它们全部关闭,对吗?
    • 还有一个后续问题:如果我要在用于创建索引的同一管理事务中创建属性,我是否还需要停止所有机器?
    • 如果在同一个管理事务中创建新的属性键和索引,我认为应该在提交后立即启用索引。
    猜你喜欢
    • 2016-01-23
    • 1970-01-01
    • 2021-07-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多