|
27 | 27 | import org.neo4j.gds.core.loading.CatalogRequest; |
28 | 28 | import org.neo4j.gds.core.loading.GraphStoreCatalog; |
29 | 29 | 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; |
30 | 34 |
|
31 | 35 | import static org.neo4j.gds.core.cypher.CypherGraphStoreCatalogHelper.setWrappedGraphStore; |
32 | 36 |
|
@@ -55,11 +59,51 @@ public static void createDatabase( |
55 | 59 | var graphStoreWithConfig = GraphStoreCatalog.get(CatalogRequest.of(username, databaseService.databaseName()), graphName); |
56 | 60 | var cypherGraphStore = new CypherGraphStore(graphStoreWithConfig.graphStore()); |
57 | 61 | setWrappedGraphStore(graphStoreWithConfig.config(), cypherGraphStore); |
58 | | - StorageEngineProxy.createInMemoryDatabase(dbms, dbName, graphName, config); |
| 62 | + createAndAwaitDatabase(dbms, dbName, graphName, config); |
59 | 63 | } catch (Exception e) { |
60 | 64 | InMemoryDatabaseCreationCatalog.removeDatabaseEntry(dbName); |
61 | 65 | throw e; |
62 | 66 | } |
63 | 67 | } |
64 | 68 |
|
| 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 | + } |
65 | 109 | } |
0 commit comments