From 255a202817ce341882397ee6f78c794d4794abba Mon Sep 17 00:00:00 2001 From: Jiang Haiting Date: Sat, 18 Sep 2021 16:45:28 +0800 Subject: [PATCH] add path empty check to avoid error log in org.apache.rocketmq.store.DefaultMessageStore#getRuntimeInfo --- .../main/java/org/apache/rocketmq/common/UtilAll.java | 5 +++++ .../org/apache/rocketmq/store/DefaultMessageStore.java | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java index 457deb8d..9971f334 100644 --- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java @@ -198,6 +198,11 @@ public class UtilAll { cal.get(Calendar.SECOND)); } + public static boolean isPathExists(final String path) { + File file = new File(path); + return file.exists(); + } + public static double getDiskPartitionSpaceUsedPercent(final String path) { if (null == path || path.isEmpty()) { log.error("Error when measuring disk space usage, path is null or empty, path : {}", path); diff --git a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java index 8543ae4d..5b4fb7aa 100644 --- a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java +++ b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java @@ -788,21 +788,23 @@ public class DefaultMessageStore implements MessageStore { double minPhysicsUsedRatio = Double.MAX_VALUE; String[] paths = commitLogStorePath.trim().split(MessageStoreConfig.MULTI_PATH_SPLITTER); for (String clPath : paths) { - double physicRatio = UtilAll.getDiskPartitionSpaceUsedPercent(clPath); + double physicRatio = UtilAll.isPathExists(clPath) ? + UtilAll.getDiskPartitionSpaceUsedPercent(clPath) : -1; result.put(RunningStats.commitLogDiskRatio.name() + "_" + clPath, String.valueOf(physicRatio)); minPhysicsUsedRatio = Math.min(minPhysicsUsedRatio, physicRatio); } result.put(RunningStats.commitLogDiskRatio.name(), String.valueOf(minPhysicsUsedRatio)); } else { String storePathPhysic = DefaultMessageStore.this.getMessageStoreConfig().getStorePathCommitLog(); - double physicRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathPhysic); + double physicRatio = UtilAll.isPathExists(storePathPhysic) ? + UtilAll.getDiskPartitionSpaceUsedPercent(storePathPhysic) : -1; result.put(RunningStats.commitLogDiskRatio.name(), String.valueOf(physicRatio)); } { - String storePathLogics = StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()); - double logicsRatio = UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogics); + double logicsRatio = UtilAll.isPathExists(storePathLogics) ? + UtilAll.getDiskPartitionSpaceUsedPercent(storePathLogics) : -1; result.put(RunningStats.consumeQueueDiskRatio.name(), String.valueOf(logicsRatio)); } -- GitLab