我正在使用 Janusgraph 制作一个 Java 项目原型,但遇到了问题。如果我创建属性键并在创建索引之前提交该属性键,则索引似乎停留在 INSTALLED 状态。示例代码在这里:
@Test
public void minimalTest() throws InterruptedException {
// build in-memory backend for janusgraph
JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
graph.tx().rollback();
JanusGraphManagement mgmt = graph.openManagement();
// create test prop & commit
String testProp = "testprop";
mgmt.getOrCreatePropertyKey(testProp);
mgmt.commit();
// create test index & commit
mgmt = graph.openManagement();
String testIndex = "testIndex";
mgmt.buildIndex(testIndex, Vertex.class).addKey(mgmt.getPropertyKey(testProp)).buildCompositeIndex();
mgmt.commit();
// attempt to wait for enabled
ManagementSystem.awaitGraphIndexStatus(graph, testIndex).status(SchemaStatus.ENABLED).call();
System.out.println("Gets stuck in the await line above and never makes it here");
}
如果我注释掉提交属性密钥并重新打开图形管理,那么此代码可以正常工作。例子在这里:
@Test
public void minimalTest() throws InterruptedException {
// build in-memory backend for janusgraph
JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
graph.tx().rollback();
JanusGraphManagement mgmt = graph.openManagement();
// create test prop & commit
String testProp = "testprop";
mgmt.getOrCreatePropertyKey(testProp);
//mgmt.commit();
// create test index & commit
//mgmt = graph.openManagement();
String testIndex = "testIndex";
mgmt.buildIndex(testIndex, Vertex.class).addKey(mgmt.getPropertyKey(testProp)).buildCompositeIndex();
mgmt.commit();
// attempt to wait for enabled
ManagementSystem.awaitGraphIndexStatus(graph, testIndex).status(SchemaStatus.ENABLED).call();
System.out.println("Gets here fine");
}
我需要做什么才能让我在与索引不同的事务中创建属性键,就像上面的第一个示例一样?
我的 janusgraph-core 和 janusgraph-inmemory 版本是 1.0.0(如果这很重要的话)。谢谢!
事实证明我必须:
最终的工作代码如下所示:
@Test
public void minimalTest4() throws InterruptedException, ExecutionException {
// build in-memory backend for janusgraph
JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
JanusGraphManagement mgmt = graph.openManagement();
// create test prop & commit
String testProp = "testprop";
mgmt.getOrCreatePropertyKey(testProp);
mgmt.commit();
graph.tx().rollback();
// create test index & commit
mgmt = graph.openManagement();
String testIndex = "testIndex";
mgmt.buildIndex(testIndex, Vertex.class).addKey(mgmt.getPropertyKey(testProp)).buildCompositeIndex();
mgmt.commit();
ManagementSystem.awaitGraphIndexStatus(graph, testIndex).status(SchemaStatus.REGISTERED).call();
// enable index
mgmt = graph.openManagement();
mgmt.updateIndex(mgmt.getGraphIndex(testIndex), SchemaAction.ENABLE_INDEX).get();
mgmt.commit();
// attempt to wait for enabled
ManagementSystem.awaitGraphIndexStatus(graph, testIndex).status(SchemaStatus.ENABLED).call();
System.out.println("Gets here fine");
}