This is an automated email from the ASF dual-hosted git repository. jiangtian pushed a commit to branch fix_load_directory_full in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 7befb81fdba99d4f34992e5a3cf0cfbe267c426b Author: Tian Jiang <[email protected]> AuthorDate: Fri Jul 12 17:33:09 2024 +0800 fix compute and add more logs --- .../rescon/disk/strategy/SequenceStrategy.java | 16 +++++--- .../apache/iotdb/commons/utils/JVMCommonUtils.java | 44 +++++++++++++++++++--- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/strategy/SequenceStrategy.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/strategy/SequenceStrategy.java index cea874fe331..82420ca2c15 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/strategy/SequenceStrategy.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/rescon/disk/strategy/SequenceStrategy.java @@ -18,15 +18,16 @@ */ package org.apache.iotdb.db.storageengine.rescon.disk.strategy; -import java.io.File; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.apache.iotdb.commons.utils.JVMCommonUtils; import org.apache.iotdb.db.exception.DiskSpaceInsufficientException; -import java.util.List; import org.apache.tsfile.fileSystem.FSFactoryProducer; +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + public class SequenceStrategy extends DirectoryStrategy { private static final long PRINT_INTERVAL_MS = 3600 * 1000L; @@ -66,8 +67,11 @@ public class SequenceStrategy extends DirectoryStrategy { if (System.currentTimeMillis() - lastPrintTime > PRINT_INTERVAL_MS) { long freeSpace = dirFile.getFreeSpace(); long totalSpace = dirFile.getTotalSpace(); - LOGGER.warn("{} is above the warning threshold, free space {}, total space{}", dir, - freeSpace, totalSpace); + LOGGER.warn( + "{} is above the warning threshold, free space {}, total space{}", + dir, + freeSpace, + totalSpace); dirLastPrintTimeMap.put(index, System.currentTimeMillis()); } if (index == start) { diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java index 04472f840dc..5649dc052c5 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java @@ -22,6 +22,8 @@ package org.apache.iotdb.commons.utils; import org.apache.iotdb.commons.conf.CommonDescriptor; import org.apache.tsfile.fileSystem.FSFactoryProducer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -29,12 +31,11 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class JVMCommonUtils { private static final Logger LOGGER = LoggerFactory.getLogger(JVMCommonUtils.class); + /** Default executor pool maximum size. */ public static final int MAX_EXECUTOR_POOL_SIZE = Math.max(100, getCpuCores() * 5); @@ -70,10 +71,41 @@ public class JVMCommonUtils { } public static double getDiskFreeRatio(String dir) { - File dirFile = FSFactoryProducer.getFSFactory().getFile(dir); - if (!dirFile.mkdirs() && !dirFile.isDirectory()) { - LOGGER.error("Cannot create directory {}", dir); - } + File dirFile = + new File(dir) { + public boolean mkdirs() { + if (exists()) { + LOGGER.warn("File {} already exists", dir); + return false; + } + if (mkdir()) { + return true; + } + File canonFile = null; + try { + canonFile = getCanonicalFile(); + } catch (IOException e) { + LOGGER.warn("Cannot get canon file of {} ", dir, e); + return false; + } + + File parent = canonFile.getParentFile(); + if (parent == null) { + LOGGER.warn("Cannot get parent file of {} ", canonFile); + return false; + } + if (!parent.mkdirs() && !parent.exists()) { + LOGGER.warn("Cannot create parent file {} ", parent); + return false; + } + if (!canonFile.mkdir()) { + LOGGER.warn("Cannot create canon file {}", canonFile); + return false; + } + return true; + } + }; + dirFile.mkdirs(); return 1.0 * dirFile.getFreeSpace() / dirFile.getTotalSpace(); }
