Skip to content

Commit 6116e01

Browse files
Await in memory database start when creating
1 parent 42ea42f commit 6116e01

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

compatibility/common/storage-engine-adapter/src/main/java/org/neo4j/gds/storageengine/InMemoryDatabaseCreator.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
import org.neo4j.gds.core.loading.CatalogRequest;
2828
import org.neo4j.gds.core.loading.GraphStoreCatalog;
2929
import org.neo4j.graphdb.GraphDatabaseService;
30+
import org.neo4j.graphdb.event.DatabaseEventContext;
31+
import org.neo4j.graphdb.event.DatabaseEventListener;
32+
33+
import java.util.concurrent.CountDownLatch;
3034

3135
import static org.neo4j.gds.core.cypher.CypherGraphStoreCatalogHelper.setWrappedGraphStore;
3236

@@ -55,11 +59,51 @@ public static void createDatabase(
5559
var graphStoreWithConfig = GraphStoreCatalog.get(CatalogRequest.of(username, databaseService.databaseName()), graphName);
5660
var cypherGraphStore = new CypherGraphStore(graphStoreWithConfig.graphStore());
5761
setWrappedGraphStore(graphStoreWithConfig.config(), cypherGraphStore);
58-
StorageEngineProxy.createInMemoryDatabase(dbms, dbName, graphName, config);
62+
createAndAwaitDatabase(dbms, dbName, graphName, config);
5963
} catch (Exception e) {
6064
InMemoryDatabaseCreationCatalog.removeDatabaseEntry(dbName);
6165
throw e;
6266
}
6367
}
6468

69+
private static void createAndAwaitDatabase(DatabaseManagementService dbms, String dbName, String graphName, Config config) {
70+
var databaseCreationLatch = new CountDownLatch(1);
71+
dbms.registerDatabaseEventListener(new DatabaseEventListener() {
72+
@Override
73+
public void databaseStart(DatabaseEventContext eventContext) {
74+
if (eventContext.getDatabaseName().equals(dbName)) {
75+
databaseCreationLatch.countDown();
76+
}
77+
}
78+
79+
@Override
80+
public void databaseShutdown(DatabaseEventContext eventContext) {
81+
82+
}
83+
84+
@Override
85+
public void databasePanic(DatabaseEventContext eventContext) {
86+
if (eventContext.getDatabaseName().equals(dbName)) {
87+
databaseCreationLatch.countDown();
88+
}
89+
}
90+
91+
@Override
92+
public void databaseCreate(DatabaseEventContext eventContext) {
93+
94+
}
95+
96+
@Override
97+
public void databaseDrop(DatabaseEventContext eventContext) {
98+
99+
}
100+
});
101+
102+
StorageEngineProxy.createInMemoryDatabase(dbms, dbName, graphName, config);
103+
try {
104+
databaseCreationLatch.await();
105+
} catch (InterruptedException e) {
106+
throw new RuntimeException(e);
107+
}
108+
}
65109
}

0 commit comments

Comments
 (0)