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/06 14:50:28 UTC

[incubator-hugegraph] branch shutdown-exception-override created (now 239543aed)

This is an automated email from the ASF dual-hosted git repository.

jermy pushed a change to branch shutdown-exception-override
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


      at 239543aed fix: shutdown exception overrides the original exception

This branch includes the following new commits:

     new 239543aed fix: shutdown exception overrides the original exception

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-hugegraph] 01/01: fix: shutdown exception overrides the original exception

Posted by je...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jermy pushed a commit to branch shutdown-exception-override
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit 239543aedde7dceff38bd5dcbbdf880435a51526
Author: Jermy Li <je...@apache.org>
AuthorDate: Fri Jan 6 22:48:31 2023 +0800

    fix: shutdown exception overrides the original exception
    
    Change-Id: I8398ae50197cab7ffe06fa17781300303e385dc9
---
 .../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 ++++----
 4 files changed, 28 insertions(+), 23 deletions(-)

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;
         }