From 38382a9153498c10c93865031f0cc318bdac5f9b Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 6 Apr 2022 12:47:18 +0800 Subject: [PATCH 1/5] DYNAMIC_CREATE_GRAPH --- .../java/com/baidu/hugegraph/config/ServerOptions.java | 8 ++++++++ .../main/java/com/baidu/hugegraph/core/GraphManager.java | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java index 3dbbb646e9..460d2156da 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java @@ -250,4 +250,12 @@ public static synchronized ServerOptions instance() { null, "hugegraph" ); + + public static final ConfigOption DYNAMIC_CREATE_GRAPH = + new ConfigOption<>( + "dynamic_create_graph", + "Whether to create graph dynamically", + disallowEmpty(), + true + ); } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java index be36b1af4d..84ea5e6e85 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java @@ -94,7 +94,9 @@ public GraphManager(HugeConfig conf, EventHub hub) { this.rpcServer = new RpcServer(conf); this.rpcClient = new RpcClientProvider(conf); this.eventHub = hub; - this.listenChanges(); + if (conf.get(ServerOptions.DYNAMIC_CREATE_GRAPH)) { + this.listenChanges(); + } this.loadGraphs(ConfigUtil.scanGraphsDir(this.graphsDir)); // this.installLicense(conf, ""); // Raft will load snapshot firstly then launch election and replay log From 6e7b860eb091ab0e0145d729f77ca1b008ab15aa Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 6 Apr 2022 14:49:16 +0800 Subject: [PATCH 2/5] rename to DYNAMIC_LISTEN_GRAPH_CHANGES --- .../main/java/com/baidu/hugegraph/config/ServerOptions.java | 4 ++-- .../src/main/java/com/baidu/hugegraph/core/GraphManager.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java index 460d2156da..12c0053909 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java @@ -251,10 +251,10 @@ public static synchronized ServerOptions instance() { "hugegraph" ); - public static final ConfigOption DYNAMIC_CREATE_GRAPH = + public static final ConfigOption DYNAMIC_LISTEN_GRAPH_CHANGES = new ConfigOption<>( "dynamic_create_graph", - "Whether to create graph dynamically", + "Whether to listen graph changes dynamically", disallowEmpty(), true ); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java index 84ea5e6e85..2ebd28995e 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java @@ -94,7 +94,7 @@ public GraphManager(HugeConfig conf, EventHub hub) { this.rpcServer = new RpcServer(conf); this.rpcClient = new RpcClientProvider(conf); this.eventHub = hub; - if (conf.get(ServerOptions.DYNAMIC_CREATE_GRAPH)) { + if (conf.get(ServerOptions.DYNAMIC_LISTEN_GRAPH_CHANGES)) { this.listenChanges(); } this.loadGraphs(ConfigUtil.scanGraphsDir(this.graphsDir)); From c059a549972dbb6ef79b5e9b3b4877549b72f7e2 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 6 Apr 2022 15:35:16 +0800 Subject: [PATCH 3/5] fix --- .../com/baidu/hugegraph/config/ServerOptions.java | 6 +++--- .../com/baidu/hugegraph/core/GraphManager.java | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java index 12c0053909..a0c4b073fa 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java @@ -251,10 +251,10 @@ public static synchronized ServerOptions instance() { "hugegraph" ); - public static final ConfigOption DYNAMIC_LISTEN_GRAPH_CHANGES = + public static final ConfigOption ENABLE_DYNAMIC_CREATE_DROP = new ConfigOption<>( - "dynamic_create_graph", - "Whether to listen graph changes dynamically", + "graphs.enable_dynamic_create_drop", + "Whether to enable create or drop graph dynamically.", disallowEmpty(), true ); diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java index 2ebd28995e..dbc5a0e0ca 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java @@ -81,6 +81,7 @@ public final class GraphManager { private final HugeAuthenticator authenticator; private final RpcServer rpcServer; private final RpcClientProvider rpcClient; + private final HugeConfig hugeConfig; private Id server; private NodeRole role; @@ -94,9 +95,8 @@ public GraphManager(HugeConfig conf, EventHub hub) { this.rpcServer = new RpcServer(conf); this.rpcClient = new RpcClientProvider(conf); this.eventHub = hub; - if (conf.get(ServerOptions.DYNAMIC_LISTEN_GRAPH_CHANGES)) { - this.listenChanges(); - } + this.hugeConfig = conf; + this.listenChanges(); this.loadGraphs(ConfigUtil.scanGraphsDir(this.graphsDir)); // this.installLicense(conf, ""); // Raft will load snapshot firstly then launch election and replay log @@ -159,6 +159,10 @@ public HugeGraph cloneGraph(String name, String newName, } public HugeGraph createGraph(String name, String configText) { + E.checkArgument(hugeConfig.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), + "Not allowed to create graph dynamically, " + + "please set `enable_dynamic_create_drop` to true.", + name); E.checkArgument(StringUtils.isNotEmpty(name), "The graph name can't be null or empty"); E.checkArgument(!this.graphs().contains(name), @@ -173,6 +177,10 @@ public HugeGraph createGraph(String name, String configText) { public void dropGraph(String name) { HugeGraph graph = this.graph(name); + E.checkArgument(hugeConfig.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), + "Not allowed to drop graph dynamically, " + + "please set `enable_dynamic_create_drop` to true.", + name); E.checkArgumentNotNull(graph, "The graph '%s' doesn't exist", name); E.checkArgument(this.graphs.size() > 1, "The graph '%s' is the only one, not allowed to delete", From 99faff816e060783486186b2b488ed35c2620ae2 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 6 Apr 2022 15:49:03 +0800 Subject: [PATCH 4/5] update --- .../main/java/com/baidu/hugegraph/core/GraphManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java index dbc5a0e0ca..de9ecb553c 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java @@ -160,8 +160,8 @@ public HugeGraph cloneGraph(String name, String newName, public HugeGraph createGraph(String name, String configText) { E.checkArgument(hugeConfig.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), - "Not allowed to create graph dynamically, " + - "please set `enable_dynamic_create_drop` to true.", + "Not allowed to create graph '%s' dynamically, " + + "please set `enable_dynamic_create_drop` to true.", name); E.checkArgument(StringUtils.isNotEmpty(name), "The graph name can't be null or empty"); @@ -178,8 +178,8 @@ public HugeGraph createGraph(String name, String configText) { public void dropGraph(String name) { HugeGraph graph = this.graph(name); E.checkArgument(hugeConfig.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), - "Not allowed to drop graph dynamically, " + - "please set `enable_dynamic_create_drop` to true.", + "Not allowed to drop graph '%s' dynamically, " + + "please set `enable_dynamic_create_drop` to true.", name); E.checkArgumentNotNull(graph, "The graph '%s' doesn't exist", name); E.checkArgument(this.graphs.size() > 1, From 12fc59c2373c330f84d3cfedcac32c0b0a3f0de1 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 6 Apr 2022 16:00:52 +0800 Subject: [PATCH 5/5] rename conf --- .../main/java/com/baidu/hugegraph/core/GraphManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java index de9ecb553c..eed83c0cb7 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java @@ -81,7 +81,7 @@ public final class GraphManager { private final HugeAuthenticator authenticator; private final RpcServer rpcServer; private final RpcClientProvider rpcClient; - private final HugeConfig hugeConfig; + private final HugeConfig conf; private Id server; private NodeRole role; @@ -95,7 +95,7 @@ public GraphManager(HugeConfig conf, EventHub hub) { this.rpcServer = new RpcServer(conf); this.rpcClient = new RpcClientProvider(conf); this.eventHub = hub; - this.hugeConfig = conf; + this.conf = conf; this.listenChanges(); this.loadGraphs(ConfigUtil.scanGraphsDir(this.graphsDir)); // this.installLicense(conf, ""); @@ -159,7 +159,7 @@ public HugeGraph cloneGraph(String name, String newName, } public HugeGraph createGraph(String name, String configText) { - E.checkArgument(hugeConfig.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), + E.checkArgument(this.conf.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), "Not allowed to create graph '%s' dynamically, " + "please set `enable_dynamic_create_drop` to true.", name); @@ -177,7 +177,7 @@ public HugeGraph createGraph(String name, String configText) { public void dropGraph(String name) { HugeGraph graph = this.graph(name); - E.checkArgument(hugeConfig.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), + E.checkArgument(this.conf.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), "Not allowed to drop graph '%s' dynamically, " + "please set `enable_dynamic_create_drop` to true.", name);