You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by vj...@apache.org on 2020/03/13 14:16:13 UTC

[hbase] branch branch-1 updated: HBASE-23967 Improve the accuracy of the method sizeToString (#1273)

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

vjasani pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1 by this push:
     new 200bf3d  HBASE-23967 Improve the accuracy of the method sizeToString (#1273)
200bf3d is described below

commit 200bf3de865722af0166569078efca807342426d
Author: xuqinya1 <45...@users.noreply.github.com>
AuthorDate: Fri Mar 13 22:11:48 2020 +0800

    HBASE-23967 Improve the accuracy of the method sizeToString (#1273)
    
    Signed-off-by: Viraj Jasani <vj...@apache.org>
    Signed-off-by: Jan Hentschel <ja...@ultratendency.com>
---
 .../apache/hadoop/hbase/quotas/QuotaSettings.java  | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java
index 58f4a62..993f224 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaSettings.java
@@ -96,12 +96,22 @@ public abstract class QuotaSettings {
   }
 
   protected static String sizeToString(final long size) {
-    if (size >= (1L << 50)) return String.format("%dP", size / (1L << 50));
-    if (size >= (1L << 40)) return String.format("%dT", size / (1L << 40));
-    if (size >= (1L << 30)) return String.format("%dG", size / (1L << 30));
-    if (size >= (1L << 20)) return String.format("%dM", size / (1L << 20));
-    if (size >= (1L << 10)) return String.format("%dK", size / (1L << 10));
-    return String.format("%dB", size);
+    if (size >= (1L << 50)) {
+      return String.format("%.2fP", (double)size / (1L << 50));
+    }
+    if (size >= (1L << 40)) {
+      return String.format("%.2fT", (double)size / (1L << 40));
+    }
+    if (size >= (1L << 30)) {
+      return String.format("%.2fG", (double)size / (1L << 30));
+    }
+    if (size >= (1L << 20)) {
+      return String.format("%.2fM", (double)size / (1L << 20));
+    }
+    if (size >= (1L << 10)) {
+      return String.format("%.2fK", (double)size / (1L << 10));
+    }
+    return String.format("%.2fB", (double)size);
   }
 
   protected static String timeToString(final TimeUnit timeUnit) {