From 7acd4fc0e4fd4eee19c121df9ef84f2d4c89772d Mon Sep 17 00:00:00 2001 From: Simon <3656562@qq.com> Date: Wed, 6 Apr 2022 17:46:42 +0800 Subject: [PATCH] Add `graphs.enable_dynamic_create_drop` option (#1809) --- .../java/com/baidu/hugegraph/config/ServerOptions.java | 8 ++++++++ .../java/com/baidu/hugegraph/core/GraphManager.java | 10 ++++++++++ 2 files changed, 18 insertions(+) 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..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 @@ -250,4 +250,12 @@ public static synchronized ServerOptions instance() { null, "hugegraph" ); + + public static final ConfigOption ENABLE_DYNAMIC_CREATE_DROP = + new ConfigOption<>( + "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 be36b1af4d..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,6 +81,7 @@ public final class GraphManager { private final HugeAuthenticator authenticator; private final RpcServer rpcServer; private final RpcClientProvider rpcClient; + private final HugeConfig conf; private Id server; private NodeRole role; @@ -94,6 +95,7 @@ public GraphManager(HugeConfig conf, EventHub hub) { this.rpcServer = new RpcServer(conf); this.rpcClient = new RpcClientProvider(conf); this.eventHub = hub; + this.conf = conf; this.listenChanges(); this.loadGraphs(ConfigUtil.scanGraphsDir(this.graphsDir)); // this.installLicense(conf, ""); @@ -157,6 +159,10 @@ public HugeGraph cloneGraph(String name, String newName, } public HugeGraph createGraph(String name, String configText) { + 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); E.checkArgument(StringUtils.isNotEmpty(name), "The graph name can't be null or empty"); E.checkArgument(!this.graphs().contains(name), @@ -171,6 +177,10 @@ public HugeGraph createGraph(String name, String configText) { public void dropGraph(String name) { HugeGraph graph = this.graph(name); + 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); 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",