Skip to content

Commit 5d2185c

Browse files
committed
Register inserts during shutdown instead of dropping backed up graphs
This will allow us to not interrupt existing work flows but actually wait for a good time to shutdown. Also the catalog listener can be used for metrics in the future.
1 parent d8451f5 commit 5d2185c

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

core/src/main/java/org/neo4j/gds/core/loading/GraphStoreCatalog.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.neo4j.gds.config.GraphProjectConfig;
2828
import org.neo4j.gds.utils.StringJoining;
2929

30+
import java.util.ArrayList;
31+
import java.util.List;
3032
import java.util.Map;
3133
import java.util.NoSuchElementException;
3234
import java.util.Optional;
@@ -41,8 +43,18 @@ public final class GraphStoreCatalog {
4143

4244
private static final ConcurrentHashMap<String, UserCatalog> userCatalogs = new ConcurrentHashMap<>();
4345

46+
private static final List<GraphStoreCatalogListener> listeners = new ArrayList<>();
47+
4448
private GraphStoreCatalog() { }
4549

50+
public static void registerListener(GraphStoreCatalogListener listener) {
51+
listeners.add(listener);
52+
}
53+
54+
public static void unregisterListener(GraphStoreCatalogListener listener) {
55+
listeners.remove(listener);
56+
}
57+
4658
public static GraphStoreWithConfig get(CatalogRequest request, String graphName) {
4759
var userCatalogKey = UserCatalog.UserCatalogKey.of(request.databaseName(), graphName);
4860
var ownCatalog = getUserCatalog(request.username());
@@ -161,6 +173,8 @@ private static void set(GraphProjectConfig config, GraphStore graphStore, boolea
161173
);
162174
return userCatalog;
163175
});
176+
177+
listeners.forEach(listener -> listener.onProject(config.username(), config.graphName()));
164178
}
165179

166180
public static boolean exists(String username, String databaseName, String graphName) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.core.loading;
21+
22+
public interface GraphStoreCatalogListener {
23+
24+
void onProject(String user, String graphName);
25+
}

core/src/test/java/org/neo4j/gds/core/loading/GraphStoreCatalogTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package org.neo4j.gds.core.loading;
2121

22+
import org.apache.commons.lang3.mutable.MutableInt;
2223
import org.junit.jupiter.api.Assertions;
2324
import org.junit.jupiter.api.Test;
2425
import org.neo4j.gds.api.DatabaseId;
@@ -414,6 +415,28 @@ void multipleDatabaseIds() {
414415
assertFalse(GraphStoreCatalog.exists(USER_NAME, databaseId1, "graph0"));
415416
}
416417

418+
@Test
419+
void callListeners() {
420+
var listenerCalls = new MutableInt(0);
421+
422+
var listener = new GraphStoreCatalogListener() {
423+
@Override
424+
public void onProject(String user, String graphName) {
425+
listenerCalls.increment();
426+
}
427+
};
428+
429+
GraphStoreCatalog.registerListener(listener);
430+
assertThat(listenerCalls.intValue()).isZero();
431+
432+
GraphStoreCatalog.set(CONFIG, graphStore);
433+
assertThat(listenerCalls.intValue()).isEqualTo(1);
434+
435+
GraphStoreCatalog.unregisterListener(listener);
436+
GraphStoreCatalog.set(GraphProjectFromStoreConfig.emptyWithName("bob", GRAPH_NAME), graphStore);
437+
assertThat(listenerCalls.intValue()).isEqualTo(1);
438+
}
439+
417440
@Test
418441
void shouldThrowOnMissingGraph() {
419442
var dummyDatabaseId = DatabaseId.from("mydatabase");

0 commit comments

Comments
 (0)