You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2021/08/04 09:26:15 UTC

[iotdb] branch autoai_debug updated: rollback 3 wait

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

tanxinyu pushed a commit to branch autoai_debug
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/autoai_debug by this push:
     new 0165837  rollback 3 wait
0165837 is described below

commit 01658374cfed3e14a4243bce1c7f1a6270140760
Author: LebronAl <TX...@gmail.com>
AuthorDate: Wed Aug 4 17:25:46 2021 +0800

    rollback 3 wait
---
 .../db/writelog/node/ExclusiveWriteLogNode.java    | 43 +++++++++++++++++++---
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/writelog/node/ExclusiveWriteLogNode.java b/server/src/main/java/org/apache/iotdb/db/writelog/node/ExclusiveWriteLogNode.java
index b05b5c8..d696bb2 100644
--- a/server/src/main/java/org/apache/iotdb/db/writelog/node/ExclusiveWriteLogNode.java
+++ b/server/src/main/java/org/apache/iotdb/db/writelog/node/ExclusiveWriteLogNode.java
@@ -278,6 +278,16 @@ public class ExclusiveWriteLogNode implements WriteLogNode, Comparable<Exclusive
       }
       ILogWriter currWriter = getCurrentFileWriter();
       FLUSH_BUFFER_THREAD_POOL.submit(() -> flushBuffer(currWriter));
+      start = System.nanoTime();
+      switchBufferIdleToWorking();
+      elapse = System.nanoTime() - start;
+      if (elapse > 3_000_000_000L) {
+        logger.warn(
+            "[WAL] {} switch buffer Idle -> Working cost {}ms",
+            this.hashCode(),
+            elapse / 1_000_000L);
+      }
+
       bufferedLogNum = 0;
       logger.debug("Log node {} ends sync.", identifier);
     } catch (InterruptedException e) {
@@ -309,10 +319,10 @@ public class ExclusiveWriteLogNode implements WriteLogNode, Comparable<Exclusive
 
     // switch buffer flushing to idle and notify the sync thread
     long start = System.nanoTime();
-    synchronized (switchBufferCondition) {
-      logBufferIdle = logBufferFlushing;
-      logBufferFlushing = null;
-      switchBufferCondition.notifyAll();
+    try {
+      switchBufferFlushingToIdle();
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
     }
     long elapse = System.nanoTime() - start;
     if (elapse > 3_000_000_000L) {
@@ -326,7 +336,7 @@ public class ExclusiveWriteLogNode implements WriteLogNode, Comparable<Exclusive
   private void switchBufferWorkingToFlushing() throws InterruptedException {
     synchronized (switchBufferCondition) {
       while (logBufferFlushing != null && !deleted.get()) {
-        switchBufferCondition.wait(100);
+        switchBufferCondition.wait();
       }
       logBufferFlushing = logBufferWorking;
       logBufferWorking = logBufferIdle;
@@ -335,6 +345,29 @@ public class ExclusiveWriteLogNode implements WriteLogNode, Comparable<Exclusive
     }
   }
 
+  private void switchBufferIdleToWorking() throws InterruptedException {
+    synchronized (switchBufferCondition) {
+      while (logBufferIdle == null && !deleted.get()) {
+        switchBufferCondition.wait();
+      }
+      logBufferWorking = logBufferIdle;
+      logBufferIdle = null;
+      switchBufferCondition.notifyAll();
+    }
+  }
+
+  private void switchBufferFlushingToIdle() throws InterruptedException {
+    synchronized (switchBufferCondition) {
+      while (logBufferIdle != null && !deleted.get()) {
+        switchBufferCondition.wait();
+      }
+      logBufferIdle = logBufferFlushing;
+      logBufferIdle.clear();
+      logBufferFlushing = null;
+      switchBufferCondition.notifyAll();
+    }
+  }
+
   private ILogWriter getCurrentFileWriter() throws FileNotFoundException {
     if (currentFileWriter == null) {
       nextFileWriter();