Remove reindexing logic from graphadmin schema-creation script 88/139688/1 1.15.3
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 6 Dec 2024 14:20:04 +0000 (15:20 +0100)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 6 Dec 2024 14:20:04 +0000 (15:20 +0100)
- reindexing is not performantly working

Issue-ID: AAI-4082
Change-Id: I8066857577cda7ed884506fb5012e3d0a77402bc
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
src/main/java/org/onap/aai/schema/GenTester.java

index ea18288..69e55a1 100644 (file)
@@ -46,7 +46,7 @@ public class GenTester {
        private static Logger LOGGER;
        private static boolean historyEnabled;
        private static boolean isSchemaInitialized;
-    private static final String SCHEMA_INITIALIZED = "schema-initialized";
+       private static final String SCHEMA_INITIALIZED = "schema-initialized";
        private static final String bySchemaInitialized = "bySchemaInitialized";
 
        /**
@@ -143,42 +143,19 @@ public class GenTester {
                                // Setting property schema-initialized to false as vertex is already there
                                LOGGER.debug("-- Vertex with property 'schema-initialized' present in db. Updating it to false");
                                graph.traversal().V().has(SCHEMA_INITIALIZED).property(SCHEMA_INITIALIZED, false).next();
-               
-                               // Reindexing the existing index
-                               LOGGER.debug("-- Reindexing existing schema-initialized index");
+                       } else {
+                               LOGGER.debug("-- Adding a new vertex with property schema-initialized as false");
                                JanusGraphManagement mgmt = graph.openManagement();
-                       try {
-                               if (mgmt.getGraphIndex(bySchemaInitialized) != null) {
-                                       LOGGER.info("Reindexing 'bySchemaInitialized' to include existing vertices.");
-                                       mgmt.updateIndex(mgmt.getGraphIndex(bySchemaInitialized), SchemaAction.REINDEX).get();
+                               try {
+                                       createSchemaInitializedIndex(graph, mgmt);
+                               } catch (Exception e) {
+                                       mgmt.rollback();
+                                       LOGGER.error("Problems creating an index for schema-initialized vertex " + e.getMessage());
+                                       throw e;
                                }
-                               mgmt.commit();
-                       } catch (Exception e) {
-                               mgmt.rollback();
-                               LOGGER.error("Error during reindexing: " + e.getMessage());
-                               throw e;
-                       }
-               } else {
-                       LOGGER.debug("-- Adding a new vertex with property schema-initialized as false");
-                       JanusGraphManagement mgmt = graph.openManagement();
-                       try{
-                               //creating  a composite index
-                               PropertyKey schemaInitialized = mgmt.makePropertyKey(SCHEMA_INITIALIZED).dataType(Boolean.class).make();
-                               mgmt.buildIndex(bySchemaInitialized, Vertex.class)
-                                                                               .addKey(schemaInitialized)
-                                                                               .buildCompositeIndex();
-                               mgmt.commit();
-
-                               //Wait for the index to become available
-                               ManagementSystem.awaitGraphIndexStatus(graph, bySchemaInitialized).call();
-                       }catch(Exception e) {
-                               mgmt.rollback();
-                               LOGGER.error("Problems creating an index for schema-initialized vertex " + e.getMessage());
-                               throw e;
+                               // Adding a new vertex
+                               graph.addVertex(SCHEMA_INITIALIZED, false);
                        }
-                       //Adding a new vertex
-                       graph.addVertex(SCHEMA_INITIALIZED, false);
-               }
 
                        GraphAdminDBUtils.logConfigs(graph.configuration());
 
@@ -206,7 +183,7 @@ public class GenTester {
                        graph.traversal().V().has(SCHEMA_INITIALIZED).property(SCHEMA_INITIALIZED, true).next();
                        LOGGER.debug("-- committing transaction ");
                        graph.tx().commit();
-                       
+
                        graph.close();
                        LOGGER.info("Closed the graph");
 
@@ -219,6 +196,18 @@ public class GenTester {
                System.exit(0);
        }
 
+       private static void createSchemaInitializedIndex(JanusGraph graph, JanusGraphManagement mgmt) throws InterruptedException {
+               // creating a composite index
+               PropertyKey schemaInitialized = mgmt.makePropertyKey(SCHEMA_INITIALIZED).dataType(Boolean.class).make();
+               mgmt.buildIndex(bySchemaInitialized, Vertex.class)
+                               .addKey(schemaInitialized)
+                               .buildCompositeIndex();
+               mgmt.commit();
+
+               // Wait for the index to become available
+               ManagementSystem.awaitGraphIndexStatus(graph, bySchemaInitialized).call();
+       }
+
        /**
         * Radical approach to avoiding index update failures.
         * Indexes can get stuck in INSTALLED state, when there are stale transactions
@@ -244,7 +233,7 @@ public class GenTester {
                LOGGER.info("Currently open instances: [{}]", instances);
                instances.stream()
                                .filter(instance -> !instance.contains("graphadmin")) // Potentially comment this out, should there be
-                                                                                                                                               // issues with the schema creation job
+                               // issues with the schema creation job
                                .filter(instance -> !instance.contains("(current)"))
                                .forEach(instance -> {
                                        LOGGER.debug("Closing open JanusGraph instance [{}] before reindexing procedure", instance);