You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2023/04/27 08:51:36 UTC

[iotdb] branch multi_folder_seq_to_rel11 created (now c2ebe06e25)

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

xingtanzjr pushed a change to branch multi_folder_seq_to_rel11
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at c2ebe06e25 Change default multi_dir_strategy to SequenceStrategy and fix original bug (#9718)

This branch includes the following new commits:

     new c2ebe06e25 Change default multi_dir_strategy to SequenceStrategy and fix original bug (#9718)

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.



[iotdb] 01/01: Change default multi_dir_strategy to SequenceStrategy and fix original bug (#9718)

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

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

commit c2ebe06e25176430169cf055087f20e61ee246ba
Author: Zhang.Jinrui <xi...@gmail.com>
AuthorDate: Thu Apr 27 16:09:23 2023 +0800

    Change default multi_dir_strategy to SequenceStrategy and fix original bug (#9718)
---
 .../java/org/apache/iotdb/commons/utils/JVMCommonUtils.java  | 12 +++++++++++-
 server/src/assembly/resources/conf/iotdb-datanode.properties |  2 +-
 .../src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java  |  2 +-
 .../iotdb/db/conf/directories/strategy/SequenceStrategy.java |  2 +-
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java b/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java
index f730eeb34a..4add837b9f 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java
@@ -19,6 +19,7 @@
 
 package org.apache.iotdb.commons.utils;
 
+import org.apache.iotdb.commons.conf.CommonDescriptor;
 import org.apache.iotdb.tsfile.fileSystem.FSFactoryProducer;
 
 import java.io.File;
@@ -34,6 +35,9 @@ public class JVMCommonUtils {
 
   private static final int CPUS = Runtime.getRuntime().availableProcessors();
 
+  private static final double diskSpaceWarningThreshold =
+      CommonDescriptor.getInstance().getConfig().getDiskSpaceWarningThreshold();
+
   /**
    * get JDK version.
    *
@@ -60,8 +64,14 @@ public class JVMCommonUtils {
     return dirFile.getFreeSpace();
   }
 
+  public static double getDiskFreeRatio(String dir) {
+    File dirFile = FSFactoryProducer.getFSFactory().getFile(dir);
+    dirFile.mkdirs();
+    return 1.0 * dirFile.getFreeSpace() / dirFile.getTotalSpace();
+  }
+
   public static boolean hasSpace(String dir) {
-    return getUsableSpace(dir) > 0;
+    return getDiskFreeRatio(dir) > diskSpaceWarningThreshold;
   }
 
   public static long getOccupiedSpace(String folderPath) throws IOException {
diff --git a/server/src/assembly/resources/conf/iotdb-datanode.properties b/server/src/assembly/resources/conf/iotdb-datanode.properties
index e23b7dfcb1..e0e1c4b2c5 100644
--- a/server/src/assembly/resources/conf/iotdb-datanode.properties
+++ b/server/src/assembly/resources/conf/iotdb-datanode.properties
@@ -165,7 +165,7 @@ dn_target_config_node_list=127.0.0.1:10710
 # Set SequenceStrategy,MaxDiskUsableSpaceFirstStrategy and MinFolderOccupiedSpaceFirstStrategy to apply the corresponding strategy.
 # If this property is unset, system will use MaxDiskUsableSpaceFirstStrategy as default strategy.
 # For this property, fully-qualified class name (include package name) and simple class name are both acceptable.
-# dn_multi_dir_strategy=MaxDiskUsableSpaceFirstStrategy
+# dn_multi_dir_strategy=SequenceStrategy
 
 # consensus dir
 # If this property is unset, system will save the data in the default relative path directory under the IoTDB folder(i.e., %IOTDB_HOME%/data/datanode).
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index db3a6268d3..a073cd69fb 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -71,7 +71,7 @@ public class IoTDBConfig {
   private static final Logger logger = LoggerFactory.getLogger(IoTDBConfig.class);
   private static final String MULTI_DIR_STRATEGY_PREFIX =
       "org.apache.iotdb.db.conf.directories.strategy.";
-  private static final String DEFAULT_MULTI_DIR_STRATEGY = "MaxDiskUsableSpaceFirstStrategy";
+  private static final String DEFAULT_MULTI_DIR_STRATEGY = "SequenceStrategy";
 
   private static final String STORAGE_GROUP_MATCHER = "([a-zA-Z0-9`_.\\-\\u2E80-\\u9FFF]+)";
   public static final Pattern STORAGE_GROUP_PATTERN = Pattern.compile(STORAGE_GROUP_MATCHER);
diff --git a/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/SequenceStrategy.java b/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/SequenceStrategy.java
index 2160e8fcb5..4d305fd7b1 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/SequenceStrategy.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/directories/strategy/SequenceStrategy.java
@@ -53,10 +53,10 @@ public class SequenceStrategy extends DirectoryStrategy {
   private int tryGetNextIndex(int start) throws DiskSpaceInsufficientException {
     int index = (start + 1) % folders.size();
     while (!JVMCommonUtils.hasSpace(folders.get(index))) {
-      index = (index + 1) % folders.size();
       if (index == start) {
         throw new DiskSpaceInsufficientException(folders);
       }
+      index = (index + 1) % folders.size();
     }
     return index;
   }