Skip to content

Commit

Permalink
Update indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
Son-HNguyen committed Jan 22, 2025
1 parent 610c5d3 commit 13c00af
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/main/java/citykg/core/db/Neo4jDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.graphdb.schema.Schema;
import org.neo4j.io.fs.FileUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -138,9 +139,35 @@ public void setIndex(Class<?> vertexClass, String propName) {

public void waitForIndexes() {
try (Transaction tx = graphDb.beginTx()) {
logger.info("Waiting for indexes to be online");
long startTime = System.currentTimeMillis();
Schema schema = tx.schema();
schema.getIndexes().forEach(index -> schema.awaitIndexOnline(index, 3600, TimeUnit.SECONDS));

while (true) {
boolean allOnline = true;

for (IndexDefinition indexDefinition : schema.getIndexes()) {
if (schema.getIndexState(indexDefinition) != Schema.IndexState.ONLINE) {
allOnline = false;
break;
}
}

if (allOnline) {
break;
}

if (System.currentTimeMillis() - startTime > 3600 * 1000) {
throw new RuntimeException("Timeout: Not all indexes are online within the specified time.");
}

Thread.sleep(100); // Check every 100 milliseconds
}

// schema.getIndexes().forEach(index -> schema.awaitIndexOnline(index, 3600, TimeUnit.SECONDS));

tx.commit();
logger.info("All indexes are online");
} catch (Exception e) {
logger.error(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
}
Expand Down Expand Up @@ -446,8 +473,12 @@ private Object toObject(Node graphNode,
}

public void summarize() {
// Wait for all indexes to be updated
waitForIndexes();
// Mapped nodes
if (!mappedClassesTmp.isEmpty()) throw new RuntimeException("Mapping still in progress");
if (!mappedClassesTmp.isEmpty()) {
logger.warn("Mapping still in progress {}", Arrays.toString(mappedClassesTmp.stream().map(Class::getSimpleName).toArray()));
}
dbStats.startTimer();
logger.info("|--> Retrieving node and label stats");
Map<String, Long> mappedLabelCount = new HashMap<>();
Expand Down

0 comments on commit 13c00af

Please sign in to comment.