rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinrongt...@apache.org
Subject [rocketmq] branch develop updated: [ISSUE #3245] Use df algorithm to calculate the disk used ratio
Date Sun, 12 Sep 2021 08:50:56 GMT
This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 53c55f7  [ISSUE #3245] Use df algorithm to calculate the disk used ratio
53c55f7 is described below

commit 53c55f7dc55f4b815e0918918a04eb29712b1697
Author: aaron ai <yangkunai@outlook.com>
AuthorDate: Sun Sep 12 16:50:48 2021 +0800

    [ISSUE #3245] Use df algorithm to calculate the disk used ratio
---
 .../src/main/java/org/apache/rocketmq/common/UtilAll.java   | 13 +++++++++----
 1 file changed, 9 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 776c991..6318be0 100644
--- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
+++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java
@@ -218,10 +218,15 @@ public class UtilAll {
             long totalSpace = file.getTotalSpace();
 
             if (totalSpace > 0) {
-                long freeSpace = file.getFreeSpace();
-                long usedSpace = totalSpace - freeSpace;
-
-                return usedSpace / (double) totalSpace;
+                long usedSpace = totalSpace - file.getFreeSpace();
+                long usableSpace = file.getUsableSpace();
+                long entireSpace = usedSpace + usableSpace;
+                long roundNum = 0;
+                if (usedSpace * 100 % entireSpace != 0) {
+                    roundNum = 1;
+                }
+                long result = usedSpace * 100 / entireSpace + roundNum;
+                return result / 100.0;
             }
         } catch (Exception e) {
             log.error("Error when measuring disk space usage, got exception: :", e);

Mime
View raw message