Reindexing using the Mgmt System

Hi all! we have an internal debate on how to best perform a reindex, after adding a new index. On JanusGraph 0.6, which of those options is preferred? and why?
mgmt.buildIndex('IDX_NAME', Vertex.class).addKey(key1, Mapping.STRING.asParameter()).addKey(key2, Mapping.TEXTSTRING.asParameter()).addKey(key3).buildMixedIndex("search")
mgmt.commit()

ManagementSystem.awaitGraphIndexStatus(graph, 'IDX_NAME').status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call()
mgmt.updateIndex('IDX_NAME', SchemaAction.REINDEX).get()
mgmt.commit()
mgmt.buildIndex('IDX_NAME', Vertex.class).addKey(key1, Mapping.STRING.asParameter()).addKey(key2, Mapping.TEXTSTRING.asParameter()).addKey(key3).buildMixedIndex("search")
mgmt.commit()

ManagementSystem.awaitGraphIndexStatus(graph, 'IDX_NAME').status(SchemaStatus.REGISTERED, SchemaStatus.ENABLED).call()
mgmt.updateIndex('IDX_NAME', SchemaAction.REINDEX).get()
mgmt.commit()
vs (this looks more like the examples in the documentation)
mgmt.buildIndex('IDX_NAME', Vertex.class).addKey(key1, Mapping.STRING.asParameter()).addKey(key2, Mapping.TEXTSTRING.asParameter()).addKey(key3).buildMixedIndex("search")
mgmt.commit()

ManagementSystem.awaitGraphIndexStatus(graph, 'IDX_NAME').status(SchemaStatus.REGISTERED).call()
mgmt.updateIndex('IDX_NAME', SchemaAction.REINDEX).get()
mgmt.commit()
ManagementSystem.awaitGraphIndexStatus(graph, 'IDX_NAME').status(SchemaStatus.ENABLED).call()
mgmt.buildIndex('IDX_NAME', Vertex.class).addKey(key1, Mapping.STRING.asParameter()).addKey(key2, Mapping.TEXTSTRING.asParameter()).addKey(key3).buildMixedIndex("search")
mgmt.commit()

ManagementSystem.awaitGraphIndexStatus(graph, 'IDX_NAME').status(SchemaStatus.REGISTERED).call()
mgmt.updateIndex('IDX_NAME', SchemaAction.REINDEX).get()
mgmt.commit()
ManagementSystem.awaitGraphIndexStatus(graph, 'IDX_NAME').status(SchemaStatus.ENABLED).call()
a followup question - what happens to the index while the index job is running? is it usable? does it transition states? Thanks!
3 Replies
aschwartz
aschwartz7mo ago
A piece of information that might be relevant is that key1, key2, are part of an another index, that we DISABLE and REMOVE, before creating IDX_NAME.
shivam.choudhary
Hi @aschwartz if you use the first approach then your queries which are eligible for that index usage will not run as expected. After you enable the index and the reindexing is not yet done, then all the queries which are eligible for that index will try to use the index which is non existent resulting in empty result. While in the second approach the index won't be eligible for usage until the reindexing job is completed after which it will automatically move to enabled state. https://docs.janusgraph.org/schema/index-management/index-lifecycle/#:~:text=.commit()%3B-,Index%20states%20and%20transitions,-The%20diagram%20below
aschwartz
aschwartz7mo ago
thanks @shivam.choudhary