I'm prototyping a java project using Janusgraph and have run into a problem. If I create a property key and commit that property key before an index is created, the index appears to be stuck in the INSTALLED state. Example code 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 stuck in the await line above and never makes it here");
}
If I comment out committing the property key & re-opening the graph management, then this code works fine. Example right 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");
}
What do I need to do which would allow me to create the property key in a different transaction from the index like in the first example above?
My janusgraph-core and janusgraph-inmemory versions are 1.0.0 if that matters at all. Thanks!
Turns out I had to:
The final code which works looks like this:
@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");
}