Skip to content

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Mar 31, 2022
1 parent f141447 commit 5a851d7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public synchronized CompletableFuture<Void> stop() {
}

public void injectAuthGraph() {
HugeGraphAuthProxy.setContext(Context.admin());

GraphManager manager = this.getServerGremlinExecutor()
.getGraphManager();
for (String name : manager.getGraphNames()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,28 +337,33 @@ private void checkBackendVersionOrExit(HugeConfig config) {
for (String graph : this.graphs()) {
// TODO: close tx from main thread
HugeGraph hugegraph = this.graph(graph);
if (!hugegraph.backendStoreFeatures().supportsPersistence()) {
hugegraph.initBackend();
if (this.requireAuthentication()) {
String token = config.get(ServerOptions.AUTH_ADMIN_TOKEN);
try {
this.authenticator.initAdminUser(token);
} catch (Exception e) {
throw new BackendException(
"The backend store of '%s' can't " +
"initialize admin user", hugegraph.name());
try {
if (!hugegraph.backendStoreFeatures().supportsPersistence()) {
hugegraph.initBackend();
if (this.requireAuthentication()) {
String token = config.get(
ServerOptions.AUTH_ADMIN_TOKEN);
try {
this.authenticator.initAdminUser(token);
} catch (Exception e) {
throw new BackendException(
"The backend store of '%s' can't " +
"initialize admin user", hugegraph.name());
}
}
}
}
BackendStoreSystemInfo info = hugegraph.backendStoreSystemInfo();
if (!info.exists()) {
throw new BackendException(
BackendStoreSystemInfo info = hugegraph.backendStoreSystemInfo();
if (!info.exists()) {
throw new BackendException(
"The backend store of '%s' has not been initialized",
hugegraph.name());
}
if (!info.checkVersion()) {
throw new BackendException(
"The backend store version is inconsistent");
}
if (!info.checkVersion()) {
throw new BackendException(
"The backend store version is inconsistent");
}
} finally {
hugegraph.tx().close();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public static void shutdown(long timeout) {
shutdown.compareAndSet(true, false);
throw new HugeException("Failed to shutdown", e);
}

LOG.info("HugeFactory shutdown");
}

public static void removeShutdownHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.baidu.hugegraph.util.ConfigUtil;
import com.baidu.hugegraph.util.Log;

import java.util.concurrent.CompletableFuture;

public class HugeGraphServer {

private static final Logger LOG = Log.logger(HugeGraphServer.class);
Expand Down Expand Up @@ -117,16 +119,19 @@ public static void main(String[] args) throws Exception {
HugeGraphServer.register();

HugeGraphServer server = new HugeGraphServer(args[0], args[1]);
/*
* HugeFactory.shutdown hook may be invoked before server stop,
* causes event-hub can't execute notification events for another
* shutdown executor such as gremling-stop-shutdown
*/
HugeFactory.removeShutdownHook();
CompletableFuture<?> serverStopped = new CompletableFuture<>();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOG.info("HugeGraphServer stopping");
server.stop();
LOG.info("HugeGraphServer stopped");
serverStopped.complete(null);
}, "hugegraph-server-shutdown"));
/*
* HugeFactory shutdown hook be invoked before server stop, so that
* eventHub execute notify event on a shutdown executor, so here
* remove the HugeFactory shutdown hook.
*/
HugeFactory.removeShutdownHook();
serverStopped.get();
}
}

0 comments on commit 5a851d7

Please sign in to comment.