You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2021/06/05 05:11:32 UTC

[iotdb] branch rel/0.12 updated: [rel/0.12] wait for clear cache (#3348)

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

hxd pushed a commit to branch rel/0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.12 by this push:
     new a6109e9  [rel/0.12] wait for clear cache (#3348)
a6109e9 is described below

commit a6109e9b2e00b26b7240c6dae254a2f143ec435b
Author: Jackie Tien <Ja...@foxmail.com>
AuthorDate: Sat Jun 5 13:10:56 2021 +0800

    [rel/0.12] wait for clear cache (#3348)
    
    * wait for clear cache
    
    * add license claim
---
 LICENSE-binary                                     |  1 +
 .../iotdb/db/integration/IoTDBClearCacheIT.java    | 25 ++++++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/LICENSE-binary b/LICENSE-binary
index 26827b0..0c8a71b 100644
--- a/LICENSE-binary
+++ b/LICENSE-binary
@@ -230,6 +230,7 @@ com.fasterxml.jackson.core:jackson-databind:2.10.0
 javax.inject:javax.inject:1
 net.jpountz.lz4:1.3.0
 com.github.stephenc.jcip:jcip-annotations:1.0-1
+com.github.ben-manes.caffeine:caffeine:2.9.1
 org.eclipse.jetty:jetty-http:9.4.24.v20191120
 org.eclipse.jetty:jetty-io:9.4.24.v20191120
 org.eclipse.jetty:jetty-security:9.4.24.v20191120
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBClearCacheIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBClearCacheIT.java
index 07754e0..9f37e27 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBClearCacheIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBClearCacheIT.java
@@ -20,6 +20,7 @@ package org.apache.iotdb.db.integration;
 
 import org.apache.iotdb.db.engine.cache.ChunkCache;
 import org.apache.iotdb.db.engine.cache.TimeSeriesMetadataCache;
+import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
 
@@ -32,6 +33,7 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -39,7 +41,7 @@ import static org.junit.Assert.fail;
 
 public class IoTDBClearCacheIT {
 
-  private static String[] sqls =
+  private static final String[] sqls =
       new String[] {
         "set storage group to root.ln",
         "create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN",
@@ -112,6 +114,9 @@ public class IoTDBClearCacheIT {
         "flush"
       };
 
+  // the unit is ns
+  private static final long MAX_WAIT_TIME_FOR_CLEAR_CACHE = 60_000_000_000L;
+
   @BeforeClass
   public static void setUp() throws Exception {
     EnvironmentUtils.closeStatMonitor();
@@ -163,7 +168,7 @@ public class IoTDBClearCacheIT {
 
       statement.execute("CLEAR CACHE");
 
-      assertTrue(ChunkCache.getInstance().isEmpty());
+      assertTrue(waitForClearCacheFinish());
       assertTrue(TimeSeriesMetadataCache.getInstance().isEmpty());
 
     } catch (Exception e) {
@@ -171,4 +176,20 @@ public class IoTDBClearCacheIT {
       fail(e.getMessage());
     }
   }
+
+  /** wait until merge is finished */
+  private boolean waitForClearCacheFinish() throws StorageEngineException, InterruptedException {
+
+    long startTime = System.nanoTime();
+    // get the size of level 1's tsfile list to judge whether merge is finished
+    while (!ChunkCache.getInstance().isEmpty()
+        || !TimeSeriesMetadataCache.getInstance().isEmpty()) {
+      TimeUnit.MILLISECONDS.sleep(100);
+      // wait too long, just break
+      if ((System.nanoTime() - startTime) >= MAX_WAIT_TIME_FOR_CLEAR_CACHE) {
+        break;
+      }
+    }
+    return ChunkCache.getInstance().isEmpty() && TimeSeriesMetadataCache.getInstance().isEmpty();
+  }
 }