You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by li...@apache.org on 2019/01/20 14:20:51 UTC

[incubator-iotdb] branch force-in-thread-periodically updated: consider four cases when close multiFileLogNodeManager

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

liurui pushed a commit to branch force-in-thread-periodically
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/force-in-thread-periodically by this push:
     new 71b7049  consider four cases when close multiFileLogNodeManager
71b7049 is described below

commit 71b7049a400792e91a99fb318d38bd9a4999050a
Author: liuruiyiyang <24...@qq.com>
AuthorDate: Sun Jan 20 22:20:37 2019 +0800

    consider four cases when close multiFileLogNodeManager
---
 .../writelog/manager/MultiFileLogNodeManager.java  | 32 ++++++++++++++++------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/iotdb/src/main/java/org/apache/iotdb/db/writelog/manager/MultiFileLogNodeManager.java b/iotdb/src/main/java/org/apache/iotdb/db/writelog/manager/MultiFileLogNodeManager.java
index 8b10531..4ecc6f0 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/writelog/manager/MultiFileLogNodeManager.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/writelog/manager/MultiFileLogNodeManager.java
@@ -150,20 +150,36 @@ public class MultiFileLogNodeManager implements WriteLogNodeManager, IService {
     }
   }
 
+  private boolean isThreadIneffective(Thread thread) {
+    return thread == null || !thread.isAlive();
+  }
+
   @Override
   public void close() {
-    if (syncThread == null || !syncThread.isAlive() || forceThread == null || !forceThread
-        .isAlive()) {
+    if (isThreadIneffective(syncThread) && isThreadIneffective(forceThread)) {
       logger.error("MultiFileLogNodeManager has not yet started");
       return;
     }
-
     logger.info("LogNodeManager starts closing..");
-    syncThread.interrupt();
-    forceThread.interrupt();
-    logger.info("Waiting for sync thread to stop");
-    while (syncThread.isAlive() || forceThread.isAlive()) {
-      // wait
+    if (!isThreadIneffective(syncThread) && isThreadIneffective(forceThread)) {
+      syncThread.interrupt();
+      logger.info("Waiting for sync thread to stop");
+      while (syncThread.isAlive()) {
+        // wait for syncThread
+      }
+    } else if (isThreadIneffective(syncThread) && !isThreadIneffective(forceThread)) {
+      forceThread.interrupt();
+      logger.info("Waiting for force thread to stop");
+      while (forceThread.isAlive()) {
+        // wait for forceThread
+      }
+    } else {
+      syncThread.interrupt();
+      forceThread.interrupt();
+      logger.info("Waiting for sync and force threads to stop");
+      while (syncThread.isAlive() || forceThread.isAlive()) {
+        // wait for syncThread and forceThread
+      }
     }
     logger.info("{} nodes to be closed", nodeMap.size());
     for (WriteLogNode node : nodeMap.values()) {