Skip to content

Commit 304b3b3

Browse files
Merge pull request #5881 from knutwalker/2.1-aura5-drop05
Add compat for 5.0.0-drop05.0
2 parents 3cdfa5b + f9c43ca commit 304b3b3

File tree

21 files changed

+235
-65
lines changed

21 files changed

+235
-65
lines changed

compatibility/4.4/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/_44/SettingProxyFactoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class SettingProxyFactoryImpl implements SettingProxyFactory {
2929

3030
@Override
3131
public boolean canLoad(Neo4jVersion version) {
32-
return version != Neo4jVersion.V_5_0_drop40;
32+
return version != Neo4jVersion.V_5_0_drop40 && version != Neo4jVersion.V_5_0_drop50;
3333
}
3434

3535
@Override

compatibility/4.4/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/_44/SettingProxyImpl.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
*/
2020
package org.neo4j.gds.compat._44;
2121

22+
import org.neo4j.configuration.Config;
23+
import org.neo4j.configuration.GraphDatabaseSettings;
2224
import org.neo4j.configuration.SettingImpl;
2325
import org.neo4j.gds.annotation.SuppressForbidden;
26+
import org.neo4j.gds.compat.DatabaseMode;
2427
import org.neo4j.gds.compat.SettingProxyApi;
28+
import org.neo4j.graphdb.GraphDatabaseService;
2529
import org.neo4j.graphdb.config.Setting;
2630

2731
public class SettingProxyImpl implements SettingProxyApi {
@@ -35,4 +39,38 @@ public <T> Setting<T> setting(org.neo4j.gds.compat.Setting<T> setting) {
3539
setting.constraints().forEach(builder::addConstraint);
3640
return builder.build();
3741
}
42+
43+
@Override
44+
public DatabaseMode databaseMode(Config config, GraphDatabaseService databaseService) {
45+
var mode = config.get(GraphDatabaseSettings.mode);
46+
switch (mode) {
47+
case SINGLE:
48+
return DatabaseMode.SINGLE;
49+
case CORE:
50+
return DatabaseMode.CORE;
51+
case READ_REPLICA:
52+
return DatabaseMode.READ_REPLICA;
53+
default:
54+
throw new IllegalStateException("Unexpected value: " + mode);
55+
}
56+
}
57+
58+
@Override
59+
public void setDatabaseMode(Config config, DatabaseMode databaseMode, GraphDatabaseService databaseService) {
60+
GraphDatabaseSettings.Mode mode;
61+
switch (databaseMode) {
62+
case SINGLE:
63+
mode = GraphDatabaseSettings.Mode.SINGLE;
64+
break;
65+
case CORE:
66+
mode = GraphDatabaseSettings.Mode.CORE;
67+
break;
68+
case READ_REPLICA:
69+
mode = GraphDatabaseSettings.Mode.READ_REPLICA;
70+
break;
71+
default:
72+
throw new IllegalStateException("Unexpected value: " + databaseMode);
73+
}
74+
config.set(GraphDatabaseSettings.mode, mode);
75+
}
3876
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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.compat;
21+
22+
public enum DatabaseMode {
23+
SINGLE,
24+
CORE,
25+
READ_REPLICA
26+
}

compatibility/api/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/SettingProxyApi.java

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

22+
import org.jetbrains.annotations.TestOnly;
23+
import org.neo4j.configuration.Config;
24+
import org.neo4j.graphdb.GraphDatabaseService;
25+
2226
public interface SettingProxyApi {
2327
// public, otherwise checkstyle complains that "'<' is preceded with whitespace."
2428
public <T> org.neo4j.graphdb.config.Setting<T> setting(Setting<T> setting);
29+
30+
DatabaseMode databaseMode(Config config, GraphDatabaseService databaseService);
31+
32+
@TestOnly
33+
void setDatabaseMode(Config config, DatabaseMode databaseMode, GraphDatabaseService databaseService);
2534
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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.compat;
21+
22+
import org.neo4j.graphdb.config.Configuration;
23+
import org.neo4j.graphdb.config.Setting;
24+
25+
import java.lang.invoke.MethodHandles;
26+
import java.util.Locale;
27+
import java.util.Optional;
28+
29+
public final class SettingsUtil {
30+
31+
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
32+
33+
public static Optional<Setting<?>> tryFind(
34+
String className,
35+
String settingName
36+
) {
37+
try {
38+
var settingsClass = Class.forName(className);
39+
var settingHandle = LOOKUP.findStaticGetter(settingsClass, settingName, Setting.class);
40+
var setting = (Setting<?>) settingHandle.invoke();
41+
return Optional.ofNullable(setting);
42+
} catch (ClassNotFoundException | NoSuchFieldException e) {
43+
// Setting is not available on this version
44+
return Optional.empty();
45+
} catch (Throwable e) {
46+
// Setting exists but accessing it failed
47+
throw new IllegalStateException(String.format(
48+
Locale.ENGLISH,
49+
"The %s setting could not be found: %s",
50+
settingName,
51+
e.getMessage()
52+
), e);
53+
}
54+
}
55+
56+
public static <T> Optional<T> tryGet(
57+
Configuration config,
58+
Class<T> settingType,
59+
Setting<?> setting
60+
) {
61+
var settingValue = config.get(setting);
62+
if (settingValue == null) {
63+
return Optional.empty();
64+
}
65+
return Optional.of(settingType.cast(settingValue));
66+
}
67+
68+
public static <T> Optional<T> tryGet(
69+
Configuration config,
70+
Class<T> settingType,
71+
String className,
72+
String settingName
73+
) {
74+
return tryFind(className, settingName).flatMap(setting -> tryGet(config, settingType, setting));
75+
}
76+
77+
public static <T, U> T tryConfigure(
78+
T builder,
79+
SetConfig<T, U> setConfig,
80+
String className,
81+
String settingName,
82+
U settingValue
83+
) {
84+
return tryFind(className, settingName).map(setting -> {
85+
//noinspection unchecked
86+
var typedSetting = (Setting<U>) setting;
87+
return setConfig.set(builder, typedSetting, settingValue);
88+
}).orElse(builder);
89+
}
90+
91+
public interface SetConfig<T, S> {
92+
T set(T config, Setting<S> setting, S value);
93+
}
94+
95+
private SettingsUtil() {
96+
throw new UnsupportedOperationException();
97+
}
98+
}

compatibility/common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/SettingProxy.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,31 @@
2020
package org.neo4j.gds.compat;
2121

2222
import org.jetbrains.annotations.Nullable;
23+
import org.jetbrains.annotations.TestOnly;
24+
import org.neo4j.configuration.Config;
2325
import org.neo4j.configuration.SettingValueParser;
26+
import org.neo4j.graphdb.GraphDatabaseService;
2427

2528
public final class SettingProxy {
2629

2730
private static final SettingProxyApi IMPL = ProxyUtil.findProxy(SettingProxyFactory.class);
2831

29-
public static <T> Setting.Builder<T> newBuilder(String name, SettingValueParser<T> parser, @Nullable T defaultValue) {
32+
public static <T> Setting.Builder<T> newBuilder(
33+
String name,
34+
SettingValueParser<T> parser,
35+
@Nullable T defaultValue
36+
) {
3037
return ImmutableSetting.builder(name, parser, defaultValue).convert(IMPL::setting);
3138
}
3239

40+
public static DatabaseMode databaseMode(Config config, GraphDatabaseService databaseService) {
41+
return IMPL.databaseMode(config, databaseService);
42+
}
43+
44+
@TestOnly
45+
public static void setDatabaseMode(Config config, DatabaseMode databaseMode, GraphDatabaseService databaseService) {
46+
IMPL.setDatabaseMode(config, databaseMode, databaseService);
47+
}
48+
3349
private SettingProxy() {}
3450
}

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ dependencies {
7676
}
7777

7878
afterEvaluate {
79-
if (ver.'neo4j' == neos.'5.0.0-drop04.0') {
79+
if (ver.'neo4j'.startsWith('5.')) {
8080
dependencies {
8181
testImplementation group: 'org.neo4j', name: 'neo4j-record-storage-engine', version: ver.'neo4j'
8282
}

core/src/main/java/org/neo4j/gds/core/Settings.java

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
import org.neo4j.configuration.helpers.SocketAddress;
2727
import org.neo4j.gds.annotation.ValueClass;
2828
import org.neo4j.gds.compat.Neo4jProxy;
29+
import org.neo4j.gds.compat.SettingsUtil;
2930
import org.neo4j.graphdb.config.Setting;
3031

31-
import java.lang.invoke.MethodHandles;
3232
import java.nio.file.Path;
3333
import java.time.ZoneId;
3434
import java.util.List;
3535

36-
import static org.neo4j.gds.utils.StringFormatting.formatWithLocale;
37-
3836
public final class Settings {
3937

4038
public static Setting<Boolean> authEnabled() {
@@ -96,8 +94,8 @@ public static Setting<Path> storeInternalLogPath() {
9694
return GraphDatabaseSettings.store_internal_log_path;
9795
}
9896

99-
public static <T> T disableOnlineBackup(T builder, SetConfig<T, Boolean> setConfig) {
100-
return tryConfigure(
97+
public static <T> T disableOnlineBackup(T builder, SettingsUtil.SetConfig<T, Boolean> setConfig) {
98+
return SettingsUtil.tryConfigure(
10199
builder,
102100
setConfig,
103101
"com.neo4j.configuration.OnlineBackupSettings",
@@ -106,15 +104,15 @@ public static <T> T disableOnlineBackup(T builder, SetConfig<T, Boolean> setConf
106104
);
107105
}
108106

109-
public static <T> T disableReplication(T builder, SetConfig<T, Boolean> setConfig) {
110-
builder = tryConfigure(
107+
public static <T> T disableReplication(T builder, SettingsUtil.SetConfig<T, Boolean> setConfig) {
108+
builder = SettingsUtil.tryConfigure(
111109
builder,
112110
setConfig,
113111
"com.neo4j.configuration.EnterpriseEditionInternalSettings",
114112
"enable_replication",
115113
Boolean.FALSE
116114
);
117-
builder = tryConfigure(
115+
builder = SettingsUtil.tryConfigure(
118116
builder,
119117
setConfig,
120118
"com.neo4j.configuration.EnterpriseEditionInternalSettings",
@@ -124,33 +122,6 @@ public static <T> T disableReplication(T builder, SetConfig<T, Boolean> setConfi
124122
return builder;
125123
}
126124

127-
public static <T, U> T tryConfigure(
128-
T builder,
129-
SetConfig<T, U> setConfig,
130-
String className,
131-
String settingName,
132-
U settingValue
133-
) {
134-
var lookup = MethodHandles.lookup();
135-
try {
136-
var settingsClass = Class.forName(className);
137-
var settingHandle = lookup.findStaticGetter(settingsClass, settingName, Setting.class);
138-
//noinspection unchecked
139-
var setting = (Setting<U>) settingHandle.invoke();
140-
return setConfig.set(builder, setting, settingValue);
141-
} catch (ClassNotFoundException | NoSuchFieldException e) {
142-
// Setting is not available on this version
143-
return builder;
144-
} catch (Throwable e) {
145-
// Actually applying the setting failed
146-
throw new IllegalStateException(formatWithLocale(
147-
"The %s setting could not be configured: %s",
148-
settingName,
149-
e.getMessage()
150-
), e);
151-
}
152-
}
153-
154125
public static Setting<List<String>> procedureUnrestricted() {
155126
return GraphDatabaseSettings.procedure_unrestricted;
156127
}
@@ -174,8 +145,4 @@ public static Setting<Long> memoryTransactionMaxSize() {
174145
private Settings() {
175146
throw new UnsupportedOperationException();
176147
}
177-
178-
public interface SetConfig<T, S> {
179-
T set(T config, Setting<S> setting, S value);
180-
}
181148
}

cypher/cypher-test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828
}
2929

3030
afterEvaluate {
31-
if (ver.'neo4j' == neos.'5.0.0-drop04.0') {
31+
if (ver.'neo4j'.startsWith('5.')) {
3232
dependencies {
3333
testImplementation group: 'org.neo4j', name: 'neo4j-record-storage-engine', version: ver.'neo4j'
3434
}

cypher/cypher-test/src/test/java/org/neo4j/gds/storageengine/InMemoryNodeCursorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ protected GraphStore graphStore() {
6666
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_9_drop10)
6767
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_8_drop10)
6868
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop40)
69+
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop50)
6970
void shouldScanSingle() {
7071
nodeCursor.single(0);
7172
assertThat(nodeCursor.next()).isTrue();
@@ -76,6 +77,7 @@ void shouldScanSingle() {
7677
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_9_drop10)
7778
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_8_drop10)
7879
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop40)
80+
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop50)
7981
void shouldScanRange() {
8082
nodeCursor.scanRange(1, 2);
8183
nodeCursor.next();
@@ -89,6 +91,7 @@ void shouldScanRange() {
8991
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_9_drop10)
9092
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_8_drop10)
9193
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop40)
94+
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop50)
9295
void shouldScanAll() {
9396
nodeCursor.scan();
9497
graphStore.nodes().forEachNode(nodeId -> {
@@ -103,6 +106,7 @@ void shouldScanAll() {
103106
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_9_drop10)
104107
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_8_drop10)
105108
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop40)
109+
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop50)
106110
void testLabels() {
107111
graphStore.nodes().forEachNode(nodeId -> {
108112
nodeCursor.single(nodeId);
@@ -128,6 +132,7 @@ void shouldHaveProperties43() {
128132
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_9_drop10)
129133
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_8_drop10)
130134
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop40)
135+
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop50)
131136
void shouldHaveProperties() {
132137
nodeCursor.next();
133138
assertThat(nodeCursor.hasProperties()).isTrue();
@@ -138,6 +143,7 @@ void shouldHaveProperties() {
138143
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_9_drop10)
139144
@DisableForNeo4jVersion(Neo4jVersion.V_4_4_8_drop10)
140145
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop40)
146+
@DisableForNeo4jVersion(Neo4jVersion.V_5_0_drop50)
141147
void shouldTraverseProperties() throws TokenNotFoundException {
142148
nodeCursor.next();
143149
var propertyCursor = StorageEngineProxy.inMemoryNodePropertyCursor(graphStore, tokenHolders);

0 commit comments

Comments
 (0)