Skip to content

Commit

Permalink
Add graphs.enable_dynamic_create_drop option (#1809)
Browse files Browse the repository at this point in the history
  • Loading branch information
simon824 authored Apr 6, 2022
1 parent 035a03e commit 7acd4fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,12 @@ public static synchronized ServerOptions instance() {
null,
"hugegraph"
);

public static final ConfigOption<Boolean> ENABLE_DYNAMIC_CREATE_DROP =
new ConfigOption<>(
"graphs.enable_dynamic_create_drop",
"Whether to enable create or drop graph dynamically.",
disallowEmpty(),
true
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, "");
Expand Down Expand Up @@ -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),
Expand All @@ -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",
Expand Down

0 comments on commit 7acd4fc

Please sign in to comment.