janusgraph-创建索引出现GraphIndexStatusReport[success=false, indexName='mixedvlabel', targetStatus=[REGISTERED], notConverged={vlabel=INSTALLED}, converged={}, elapsed=PT1M0.07S]

参考网址:

https://www.cnblogs.com/Uglthinx/p/9630779.html

原因:我的是事务没有完全关闭

解决办法:

创建一个混合索引:

// 在graph中有事务执行时绝不能创建索引(否则可能导致死锁)
mgmt = graph.openManagement()
vlabel = mgmt.getPropertyKey('vlabel')
// 构建索引
mgmt.buildIndex('mixedvlabel',Vertex.class).addKey(vlabel).buildMixedIndex("search")
mgmt.commit()
//等待索引生效
mgmt.awaitGraphIndexStatus(graph,'mixedvlabel').call()
//对已有数据重新索引
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("mixedvlabel"),SchemaAction.REINDEX).get()
mgmt.commit()

在执行(索引生效的时候出现如下错误)

mgmt.awaitGraphIndexStatus(graph,'mixedvlabel').call()

错误

GraphIndexStatusReport[success=false, indexName='mixedvlabel', targetStatus=[REGISTERED], notConverged={vlabel=INSTALLED}, converged={}, elapsed=PT1M0.07S]

事务没有完全关闭

解决办法

1. 执行关闭事务命令 : graph.tx().rollback()

但是无法完全关闭事务

2. 查看事务 :graph.getOpenTransactions()

3.使用关闭事务命令

for(i=0;i<size;i++) {graph.getOpenTransactions().getAt(0).rollback()}  //size替换为事务的数量

4.执行 REGISTER_INDEX ACTION,使索引状态INSTALLED 转为 REGISTERED

非常关键的一步

mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex('mixedvlabel'),SchemaAction.REGISTER_INDEX).get()
mgmt.commit()

5.查看索引新的转态

vlabel = mgmt.getPropertyKey('vlabel')
mixedvlabel=mgmt.getGraphIndex('mixedvlabel')
status=mixedvlabel.getIndexStatus(vlabel)

结果为

GraphIndexStatusReport[success=true, indexName='mixedvlabel', targetStatus=[REGISTERED], notConverged={}, converged={vlabel=REGISTERED}, elapsed=PT0S]

6.执行REINDEX与ENABLE_INDEX,完成索引

m = graph.openManagement()
m.updateIndex(m.getGraphIndex('mixedvlabel'), SchemaAction.ENABLE_INDEX).get() 
m.commit() 

ManagementSystem.awaitGraphIndexStatus(graph, 'mixedvlabel').status(SchemaStatus.ENABLED).call()

7.返回结果

GraphIndexStatusReport[success=true, indexName='mixedvlabel', targetStatus=[ENABLED], notConverged={}, converged={vlabel=ENABLED}, elapsed=PT0.006S]

8.更新已有数据的索引

mgmt.updateIndex(mgmt.getGraphIndex("mixedvlabel"),SchemaAction.REINDEX).get()

注:如果数据量很大的话,需要时间长

原文地址:https://www.cnblogs.com/learndata/p/10757661.html