Skip to content

Commit 607e13b

Browse files
committed
Pass log to GraphStoreCatalog on dbms startup
The log is used to warn if a listener fails
1 parent 5d2185c commit 607e13b

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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;
21+
22+
import org.neo4j.annotations.service.ServiceProvider;
23+
import org.neo4j.gds.compat.Neo4jProxy;
24+
import org.neo4j.gds.core.loading.GraphStoreCatalog;
25+
import org.neo4j.kernel.extension.ExtensionFactory;
26+
import org.neo4j.kernel.extension.ExtensionType;
27+
import org.neo4j.kernel.extension.context.ExtensionContext;
28+
import org.neo4j.kernel.lifecycle.Lifecycle;
29+
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
30+
import org.neo4j.logging.internal.LogService;
31+
32+
@ServiceProvider
33+
public class GdsLogExtension extends ExtensionFactory<GdsLogExtension.Dependencies> {
34+
35+
public GdsLogExtension() {
36+
super(ExtensionType.GLOBAL, "gds.log");
37+
}
38+
39+
@Override
40+
public Lifecycle newInstance(ExtensionContext context, Dependencies dependencies) {
41+
return LifecycleAdapter.onInit(() -> {
42+
var log = Neo4jProxy.getUserLog(dependencies.logService(), GdsLogExtension.class);
43+
GraphStoreCatalog.setLog(log);
44+
});
45+
}
46+
47+
interface Dependencies {
48+
LogService logService();
49+
}
50+
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
import org.neo4j.gds.api.GraphStore;
2727
import org.neo4j.gds.config.GraphProjectConfig;
2828
import org.neo4j.gds.utils.StringJoining;
29+
import org.neo4j.logging.Log;
2930

3031
import java.util.ArrayList;
3132
import java.util.List;
33+
import java.util.Locale;
3234
import java.util.Map;
3335
import java.util.NoSuchElementException;
3436
import java.util.Optional;
@@ -45,6 +47,10 @@ public final class GraphStoreCatalog {
4547

4648
private static final List<GraphStoreCatalogListener> listeners = new ArrayList<>();
4749

50+
// as we want to use the Neo4j log if possible and the catalog is a static instance,
51+
// we make the log injectable
52+
private static Optional<Log> log = Optional.empty();
53+
4854
private GraphStoreCatalog() { }
4955

5056
public static void registerListener(GraphStoreCatalogListener listener) {
@@ -55,6 +61,10 @@ public static void unregisterListener(GraphStoreCatalogListener listener) {
5561
listeners.remove(listener);
5662
}
5763

64+
public static void setLog(Log log) {
65+
GraphStoreCatalog.log = Optional.of(log);
66+
}
67+
5868
public static GraphStoreWithConfig get(CatalogRequest request, String graphName) {
5969
var userCatalogKey = UserCatalog.UserCatalogKey.of(request.databaseName(), graphName);
6070
var ownCatalog = getUserCatalog(request.username());
@@ -174,7 +184,18 @@ private static void set(GraphProjectConfig config, GraphStore graphStore, boolea
174184
return userCatalog;
175185
});
176186

177-
listeners.forEach(listener -> listener.onProject(config.username(), config.graphName()));
187+
listeners.forEach(listener -> {
188+
try {
189+
listener.onProject(config.username(), config.graphName());
190+
} catch (Exception e) {
191+
log.ifPresent(l -> l.warn(String.format(
192+
Locale.US,
193+
"Could not call listener %s on setting the graph %s",
194+
listener,
195+
config.graphName()
196+
), e));
197+
}
198+
});
178199
}
179200

180201
public static boolean exists(String username, String databaseName, String graphName) {

0 commit comments

Comments
 (0)