+ LOGGER.info("-- About to call graphMgmt commit");
+ if (backend != null) {
+ LOGGER.info("Successfully loaded the schema to {}", backend);
+ }
+
+ graphMgmt.commit();
+ return elementsToReindex;
+ }
+
+ public static void reindexEdgeIndexes(final JanusGraph graph, Collection<String> edgeLabels) {
+ graph.tx().rollback();
+ if(edgeLabels.isEmpty()) {
+ LOGGER.info("Nothing to reindex.");
+ return;
+ }
+
+ ensureValidIndexState(graph, edgeLabels);
+
+ awaitRelationIndexStatus(graph, edgeLabels,SchemaStatus.REGISTERED);
+
+ LOGGER.info("Attempting to transition indexes in REGISTERED state to ENABLED");
+ updateRelationIndexes(graph, edgeLabels, SchemaAction.REINDEX);
+
+ ensureEnabledIndexState(graph, edgeLabels);
+ }
+
+ /**
+ * Indices need to be in status REGISTERED or ENABLED to allow reindexing.
+ * @param graph
+ * @param edgeLabels
+ */
+ private static void ensureEnabledIndexState(final JanusGraph graph, Collection<String> edgeLabels) {
+ JanusGraphManagement graphMgmt = graph.openManagement();
+ List<String> registeredIndexes = new ArrayList<>();
+ for(String label: edgeLabels) {
+ EdgeLabel relation = graphMgmt.getEdgeLabel(label);
+ RelationTypeIndex index = graphMgmt.getRelationIndex(relation, label);
+ SchemaStatus indexStatus = index.getIndexStatus();
+ if(indexStatus.equals(SchemaStatus.REGISTERED)) {
+ LOGGER.info("Detected relation index [{}] that is not yet in ENABLED state", relation.name());
+ registeredIndexes.add(label);
+ }
+ }
+ graphMgmt.commit();
+
+ if(indexRecoveryRetryCounter <= 8 && !registeredIndexes.isEmpty()) {
+ indexRecoveryRetryCounter++;
+ LOGGER.info("[{}] indexes not yet in ENABLED state", registeredIndexes.size());
+ awaitRelationIndexStatus(graph, registeredIndexes,SchemaStatus.ENABLED);
+
+ ensureEnabledIndexState(graph, edgeLabels); // recursively call to make sure there is no invalid state
+ } else {
+ LOGGER.info("All indexes are in ENABLED state, exiting.");
+ return;
+ }
+ }
+
+ /**
+ * Indices need to be in status REGISTERED or ENABLED to allow reindexing.
+ * @param graph
+ * @param edgeLabels
+ */
+ private static void ensureValidIndexState(final JanusGraph graph, Collection<String> edgeLabels) {
+ JanusGraphManagement graphMgmt = graph.openManagement();
+ List<String> installedIndexes = new ArrayList<>();
+ List<String> disabledIndexes = new ArrayList<>();
+ for(String label: edgeLabels) {
+ EdgeLabel relation = graphMgmt.getEdgeLabel(label);
+ RelationTypeIndex index = graphMgmt.getRelationIndex(relation, label);
+ SchemaStatus indexStatus = index.getIndexStatus();
+ if(indexStatus.equals(SchemaStatus.INSTALLED)) {
+ LOGGER.info("Detected relation index [{}] with invalid status [{}]", relation.name(), indexStatus);
+ installedIndexes.add(label);
+ } else if(indexStatus.equals(SchemaStatus.DISABLED)) {
+ LOGGER.info("Detected relation index [{}] with invalid status [{}]", relation.name(), indexStatus);
+ disabledIndexes.add(label);
+ }
+ }
+ graphMgmt.commit();
+
+ if(indexRecoveryRetryCounter <= 300 && (!installedIndexes.isEmpty() || !disabledIndexes.isEmpty())) {
+ indexRecoveryRetryCounter++;
+ if(!installedIndexes.isEmpty()) {
+ LOGGER.info("Attempting to transition indexes in INSTALLED state to REGISTERED");
+ updateRelationIndexes(graph, installedIndexes, SchemaAction.REGISTER_INDEX);
+ awaitRelationIndexStatus(graph, edgeLabels,SchemaStatus.REGISTERED);
+ }
+ if(!disabledIndexes.isEmpty()) {
+ LOGGER.info("Attempting to transition indexes in DISABLED state to ENABLED");
+ updateRelationIndexes(graph, disabledIndexes, SchemaAction.ENABLE_INDEX);
+ awaitRelationIndexStatus(graph, edgeLabels,SchemaStatus.ENABLED);
+ }
+ ensureValidIndexState(graph, edgeLabels); // recursively call to make sure there is no invalid state
+ } else {
+ return;
+ }
+ }
+
+ private static void createSchemaForObject(final JanusGraphManagement graphMgmt, Map<String, PropertyKey> seenProps,
+ Introspector obj) {
+ for (String propName : obj.getProperties()) {
+ String dbPropName = propName;
+ Optional<String> alias = obj.getPropertyMetadata(propName, PropertyMetadata.DB_ALIAS);
+ if (alias.isPresent()) {
+ dbPropName = alias.get();
+ }
+ if (graphMgmt.containsRelationType(dbPropName)) {
+ LOGGER.debug(" PropertyKey [{}] already existed in the DB. ", dbPropName);
+ } else {
+ Class<?> type = obj.getClass(propName);
+ Cardinality cardinality = Cardinality.SINGLE;
+ boolean process = false;
+ if (obj.isListType(propName) && obj.isSimpleGenericType(propName)) {
+ cardinality = Cardinality.SET;
+ type = obj.getGenericTypeClass(propName);
+ process = true;
+ } else if (obj.isSimpleType(propName)) {
+ process = true;