Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix close exception and server-info EXPIRED_INTERVAL #1804

Merged
merged 5 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class ContextGremlinServer extends GremlinServer {

private final EventHub eventHub;

static {
HugeGraphAuthProxy.setContext(Context.admin());
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
}

public ContextGremlinServer(final Settings settings, EventHub eventHub) {
/*
* pass custom Executor https://github.com/apache/tinkerpop/pull/813
Expand Down
21 changes: 17 additions & 4 deletions hugegraph-core/src/main/java/com/baidu/hugegraph/HugeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
Expand All @@ -43,20 +44,24 @@ public class HugeFactory {

private static final Logger LOG = Log.logger(HugeGraph.class);

private static final Thread shutdownHook = new Thread(() -> {
LOG.info("HugeGraph is shutting down");
HugeFactory.shutdown(30L);
}, "hugegraph-shutdown");

static {
SerialEnum.registerInternalEnums();
HugeGraph.registerTraversalStrategies(StandardHugeGraph.class);

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOG.info("HugeGraph is shutting down");
HugeFactory.shutdown(30L);
}, "hugegraph-shutdown"));
Runtime.getRuntime().addShutdownHook(shutdownHook);
}

private static final String NAME_REGEX = "^[A-Za-z][A-Za-z0-9_]{0,47}$";

private static final Map<String, HugeGraph> graphs = new HashMap<>();

private static final AtomicBoolean shutdown = new AtomicBoolean(false);

public static synchronized HugeGraph open(Configuration config) {
HugeConfig conf = config instanceof HugeConfig ?
(HugeConfig) config : new HugeConfig(config);
Expand Down Expand Up @@ -138,6 +143,9 @@ public static PropertiesConfiguration getRemoteConfig(URL url) {
* @param timeout seconds
*/
public static void shutdown(long timeout) {
if (!shutdown.compareAndSet(false, true)) {
return;
}
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
try {
if (!EventHub.destroy(timeout)) {
throw new TimeoutException(timeout + "s");
Expand All @@ -146,7 +154,12 @@ public static void shutdown(long timeout) {
OltpTraverser.destroy();
} catch (Throwable e) {
LOG.error("Error while shutdown", e);
shutdown.compareAndSet(true, false);
throw new HugeException("Failed to shutdown", e);
}
}

public static void removeShutdownHook() {
Runtime.getRuntime().removeShutdownHook(shutdownHook);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class HugeServerInfo {

// Unit millisecond
private static final long EXPIRED_INTERVAL =
TaskManager.SCHEDULE_PERIOD * 1000L * 3;
TaskManager.SCHEDULE_PERIOD * 10;

private Id id;
private NodeRole role;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,11 @@ public static void main(String[] args) throws Exception {
server.stop();
LOG.info("HugeGraphServer stopped");
}, "hugegraph-server-shutdown"));
/*
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
* HugeFactory shutdown hook be invoked before server stop, so that
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
* eventHub execute notify event on a shutdown executor, so here
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
* remove the HugeFactory shutdown hook.
*/
HugeFactory.removeShutdownHook();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add graph.tx().close() to checkVersionOrExit()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now, threadpool wait graph close, but close check tx all close(need threadpool shutdown), so here is a conflict, so we resolve this problem must close before notify thread close tx(AOP threadpool), maybe i can do it after java11 code be merged

}
}