Skip to content

Instantly share code, notes, and snippets.

@disruptek
Created July 11, 2017 22:00
Show Gist options
  • Save disruptek/98ed066933d05f22850329c5efc1d7b4 to your computer and use it in GitHub Desktop.
Save disruptek/98ed066933d05f22850329c5efc1d7b4 to your computer and use it in GitHub Desktop.
example of progressive index installation/enablement with inspection so you can confirm behavior
graph = JanusGraphFactory.open("conf/gremlin-server/janusgraph-cassandra-es-server.properties")
prop = 'some_property_name'
name = 'by' + prop
size = graph.getOpenTransactions().size()
if(size>0) {for(i=0;i<size;i++) {graph.getOpenTransactions().getAt(0).rollback()}}
graph.getOpenTransactions()
m = graph.openManagement()
m.getOpenInstances()
propkey = m.getPropertyKey(prop)
index = m.getGraphIndex(name)
if(index == null) {m.buildIndex(name, Vertex.class).addKey(propkey).buildCompositeIndex()}
if(index == null) {index = m.getGraphIndex(name)}
status = index.getIndexStatus(propkey)
if(status == SchemaStatus.INSTALLED) {m.updateIndex(index, SchemaAction.REGISTER_INDEX).get(); 'registering'}
if(status == SchemaStatus.REGISTERED) {m.updateIndex(index, SchemaAction.ENABLE_INDEX).get(); 'enabling'}
m.commit()
graph.tx().commit()
graph.getOpenTransactions()
m = graph.openManagement()
index = m.getGraphIndex(name)
status = index.getIndexStatus(propkey)
m.commit()
graph.tx().commit()
graph.getOpenTransactions()
if(status == SchemaStatus.INSTALLED) {m.awaitGraphIndexStatus(graph, name).status(SchemaStatus.REGISTERED).call()}
if(status == SchemaStatus.REGISTERED) {m.awaitGraphIndexStatus(graph, name).status(SchemaStatus.ENABLED).call()}
graph.getOpenTransactions()
status = index.getIndexStatus(propkey)
if(status == SchemaStatus.ENABLED) {m.updateIndex(index, SchemaAction.REINDEX).get()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment