You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by je...@apache.org on 2023/01/11 14:52:37 UTC
[incubator-hugegraph] branch master updated: fix: shutdown exception overrides the original exception (#2072)
This is an automated email from the ASF dual-hosted git repository.
jermy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
The following commit(s) were added to refs/heads/master by this push:
new 62d52a20b fix: shutdown exception overrides the original exception (#2072)
62d52a20b is described below
commit 62d52a20bafc31cca46499a540df22783d4a1682
Author: Jermy Li <je...@apache.org>
AuthorDate: Wed Jan 11 22:52:31 2023 +0800
fix: shutdown exception overrides the original exception (#2072)
Change-Id: I8398ae50197cab7ffe06fa17781300303e385dc9
---
.../hugegraph/auth/ContextGremlinServer.java | 20 ++++++++++--------
.../java/org/apache/hugegraph/HugeFactory.java | 24 ++++++++++++++--------
.../java/org/apache/hugegraph/cmd/InitStore.java | 9 ++++----
.../java/org/apache/hugegraph/cmd/StoreDumper.java | 9 ++++----
.../org/apache/hugegraph/dist/HugeGraphServer.java | 9 ++++----
5 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/ContextGremlinServer.java b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/ContextGremlinServer.java
index 1f6fcffb2..ae1ef816c 100644
--- a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/ContextGremlinServer.java
+++ b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/ContextGremlinServer.java
@@ -23,15 +23,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
-import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.server.GraphManager;
-import org.apache.tinkerpop.gremlin.server.GremlinServer;
-import org.apache.tinkerpop.gremlin.server.Settings;
-import org.apache.tinkerpop.gremlin.server.util.ThreadFactoryUtil;
-import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.slf4j.Logger;
-
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.auth.HugeGraphAuthProxy.Context;
@@ -41,6 +32,14 @@ import org.apache.hugegraph.event.EventHub;
import org.apache.hugegraph.testutil.Whitebox;
import org.apache.hugegraph.util.Events;
import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.server.GraphManager;
+import org.apache.tinkerpop.gremlin.server.GremlinServer;
+import org.apache.tinkerpop.gremlin.server.Settings;
+import org.apache.tinkerpop.gremlin.server.util.ThreadFactoryUtil;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.slf4j.Logger;
/**
* GremlinServer with custom ServerGremlinExecutor, which can pass Context
@@ -84,6 +83,9 @@ public class ContextGremlinServer extends GremlinServer {
}
private void unlistenChanges() {
+ if (this.eventHub == null) {
+ return;
+ }
this.eventHub.unlisten(Events.GRAPH_CREATE);
this.eventHub.unlisten(Events.GRAPH_DROP);
}
diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/HugeFactory.java b/hugegraph-core/src/main/java/org/apache/hugegraph/HugeFactory.java
index fc726a4d1..d41a195d1 100644
--- a/hugegraph-core/src/main/java/org/apache/hugegraph/HugeFactory.java
+++ b/hugegraph-core/src/main/java/org/apache/hugegraph/HugeFactory.java
@@ -31,15 +31,14 @@ import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.hugegraph.config.CoreOptions;
-import org.apache.hugegraph.task.TaskManager;
-import org.apache.hugegraph.type.define.SerialEnum;
-import org.slf4j.Logger;
-
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.event.EventHub;
+import org.apache.hugegraph.task.TaskManager;
import org.apache.hugegraph.traversal.algorithm.OltpTraverser;
+import org.apache.hugegraph.type.define.SerialEnum;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
+import org.slf4j.Logger;
public class HugeFactory {
@@ -47,7 +46,7 @@ public class HugeFactory {
private static final Thread SHUT_DOWN_HOOK = new Thread(() -> {
LOG.info("HugeGraph is shutting down");
- HugeFactory.shutdown(30L);
+ HugeFactory.shutdown(30L, true);
}, "hugegraph-shutdown");
static {
@@ -142,11 +141,16 @@ public class HugeFactory {
}
}
+ public static void shutdown(long timeout) {
+ shutdown(timeout, false);
+ }
+
/**
* Stop all the daemon threads
- * @param timeout seconds
+ * @param timeout wait in seconds
+ * @param ignoreException don't throw exception if true
*/
- public static void shutdown(long timeout) {
+ public static void shutdown(long timeout, boolean ignoreException) {
if (!SHUT_DOWN.compareAndSet(false, true)) {
return;
}
@@ -159,7 +163,11 @@ public class HugeFactory {
} catch (Throwable e) {
LOG.error("Error while shutdown", e);
SHUT_DOWN.compareAndSet(true, false);
- throw new HugeException("Failed to shutdown", e);
+ if (ignoreException) {
+ return;
+ } else {
+ throw new HugeException("Failed to shutdown", e);
+ }
}
LOG.info("HugeFactory shutdown");
diff --git a/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/InitStore.java b/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/InitStore.java
index beef26ed6..e78f2da51 100644
--- a/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/InitStore.java
+++ b/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/InitStore.java
@@ -25,10 +25,6 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.collections.map.MultiValueMap;
-import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
-import org.apache.hugegraph.dist.RegisterUtil;
-import org.slf4j.Logger;
-
import org.apache.hugegraph.HugeFactory;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.auth.StandardAuthenticator;
@@ -36,9 +32,12 @@ import org.apache.hugegraph.backend.store.BackendStoreInfo;
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.config.ServerOptions;
+import org.apache.hugegraph.dist.RegisterUtil;
import org.apache.hugegraph.util.ConfigUtil;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
+import org.slf4j.Logger;
public class InitStore {
@@ -87,7 +86,7 @@ public class InitStore {
for (HugeGraph graph : graphs) {
graph.close();
}
- HugeFactory.shutdown(30L);
+ HugeFactory.shutdown(30L, true);
}
}
diff --git a/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/StoreDumper.java b/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/StoreDumper.java
index 7d19ae485..35209b712 100644
--- a/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/StoreDumper.java
+++ b/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/StoreDumper.java
@@ -21,19 +21,18 @@ package org.apache.hugegraph.cmd;
import java.util.Iterator;
-import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
-import org.apache.hugegraph.dist.RegisterUtil;
-import org.slf4j.Logger;
-
import org.apache.hugegraph.HugeFactory;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.query.Query;
import org.apache.hugegraph.backend.store.BackendEntry;
import org.apache.hugegraph.backend.store.BackendStore;
+import org.apache.hugegraph.dist.RegisterUtil;
import org.apache.hugegraph.testutil.Whitebox;
import org.apache.hugegraph.type.HugeType;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;
+import org.slf4j.Logger;
public class StoreDumper {
@@ -90,7 +89,7 @@ public class StoreDumper {
dumper.close();
// Stop daemon thread
- HugeFactory.shutdown(30L);
+ HugeFactory.shutdown(30L, true);
}
private static String arg(String[] args, int index, String deflt) {
diff --git a/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java b/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java
index 58244ed74..44643f171 100644
--- a/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java
+++ b/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java
@@ -21,10 +21,6 @@ package org.apache.hugegraph.dist;
import java.util.concurrent.CompletableFuture;
-import org.apache.logging.log4j.LogManager;
-import org.apache.tinkerpop.gremlin.server.GremlinServer;
-import org.slf4j.Logger;
-
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeFactory;
import org.apache.hugegraph.config.HugeConfig;
@@ -33,6 +29,9 @@ import org.apache.hugegraph.event.EventHub;
import org.apache.hugegraph.server.RestServer;
import org.apache.hugegraph.util.ConfigUtil;
import org.apache.hugegraph.util.Log;
+import org.apache.logging.log4j.LogManager;
+import org.apache.tinkerpop.gremlin.server.GremlinServer;
+import org.slf4j.Logger;
public class HugeGraphServer {
@@ -122,7 +121,7 @@ public class HugeGraphServer {
try {
server = new HugeGraphServer(args[0], args[1]);
} catch (Throwable e) {
- HugeFactory.shutdown(30L);
+ HugeFactory.shutdown(30L, true);
throw e;
}