You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by sa...@apache.org on 2021/01/18 07:00:27 UTC

[ozone] branch master updated: change quota unit suffix from BYTES to B (#1813)

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

sammichen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 5a35cbd  change quota unit suffix from BYTES to B (#1813)
5a35cbd is described below

commit 5a35cbd501a7e44578f618b9cf8f89fa44281426
Author: micah zhao <mi...@tencent.com>
AuthorDate: Mon Jan 18 15:00:17 2021 +0800

    change quota unit suffix from BYTES to B (#1813)
---
 .../org/apache/hadoop/hdds/client/OzoneQuota.java  | 22 ++++++++--------------
 .../java/org/apache/hadoop/ozone/OzoneConsts.java  |  2 +-
 .../client/rpc/TestOzoneRpcClientAbstract.java     | 14 +++++++-------
 .../hadoop/ozone/shell/TestOzoneShellHA.java       | 16 ++++++++--------
 .../hadoop/ozone/freon/RandomKeyGenerator.java     |  2 +-
 5 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
index e6aa0aa..92a44ec 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
@@ -36,14 +36,14 @@ public final class OzoneQuota {
   public static final Logger LOG =
       LoggerFactory.getLogger(OzoneQuota.class);
 
-  public static final String OZONE_QUOTA_BYTES = "BYTES";
+  public static final String OZONE_QUOTA_B = "B";
   public static final String OZONE_QUOTA_KB = "KB";
   public static final String OZONE_QUOTA_MB = "MB";
   public static final String OZONE_QUOTA_GB = "GB";
   public static final String OZONE_QUOTA_TB = "TB";
 
   /** Quota Units.*/
-  public enum Units {BYTES, KB, MB, GB, TB}
+  public enum Units {B, KB, MB, GB, TB}
 
   // Quota to decide how many buckets can be created.
   private long quotaInNamespace;
@@ -60,7 +60,7 @@ public final class OzoneQuota {
     quotaList.addQuotaList(OZONE_QUOTA_GB, Units.GB, GB);
     quotaList.addQuotaList(OZONE_QUOTA_MB, Units.MB, MB);
     quotaList.addQuotaList(OZONE_QUOTA_KB, Units.KB, KB);
-    quotaList.addQuotaList(OZONE_QUOTA_BYTES, Units.BYTES, 1L);
+    quotaList.addQuotaList(OZONE_QUOTA_B, Units.B, 1L);
   }
 
   /**
@@ -183,7 +183,6 @@ public final class OzoneQuota {
     String size = "";
     long nSize = 0;
     Units currUnit = Units.MB;
-    long quotaMultiplyExact = 0;
 
     try {
       for (String quota : quotaList.getOzoneQuotaArray()) {
@@ -191,20 +190,15 @@ public final class OzoneQuota {
           size = uppercase
               .substring(0, uppercase.length() - quota.length());
           currUnit = quotaList.getUnits(quota);
-          quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size),
-              quotaList.getQuotaSize(currUnit));
           break;
         }
       }
       nSize = Long.parseLong(size);
     } catch (NumberFormatException e) {
       throw new IllegalArgumentException("Invalid values for quota, to ensure" +
-          " that the Quota format is legal(supported values are BYTES, " +
-          " KB, MB, GB and TB).");
-    } catch (ArithmeticException e) {
-      LOG.debug("long overflow:\n{}", quotaMultiplyExact);
-      throw new IllegalArgumentException("Invalid values for quota, the quota" +
-          " value cannot be greater than Long.MAX_VALUE BYTES");
+          " that the Quota format is legal(supported values are B," +
+          " KB, MB, GB and TB). And the quota value cannot be greater than " +
+          "Long.MAX_VALUE BYTES");
     }
 
     if (nSize <= 0) {
@@ -233,7 +227,7 @@ public final class OzoneQuota {
       throw new IllegalArgumentException(
           "Invalid values for namespace quota: " + nameSpaceQuota);
     }
-    return new OzoneQuota(nameSpaceQuota, new RawQuotaInBytes(Units.BYTES, -1));
+    return new OzoneQuota(nameSpaceQuota, new RawQuotaInBytes(Units.B, -1));
   }
 
   /**
@@ -262,7 +256,7 @@ public final class OzoneQuota {
   public static OzoneQuota getOzoneQuota(long quotaInBytes,
       long quotaInNamespace) {
     long size = 1L;
-    Units unit = Units.BYTES;
+    Units unit = Units.B;
     for (Long quota : quotaList.getSizeQuotaArray()) {
       if (quotaInBytes % quota == 0) {
         size = quotaInBytes / quota;
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
index c62c1da..527b6dd 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java
@@ -201,7 +201,7 @@ public final class OzoneConsts {
   /**
    * Quota Units.
    */
-  public enum Units {TB, GB, MB, KB, BYTES}
+  public enum Units {TB, GB, MB, KB, B}
 
   /**
    * Max number of keys returned per list buckets operation.
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java
index e977990..07d6be8 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java
@@ -429,7 +429,7 @@ public abstract class TestOzoneRpcClientAbstract {
     LambdaTestUtils.intercept(IllegalArgumentException.class,
         "Invalid values for quota",
         () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota(
-            "9223372036854775808 BYTES", "1000")));
+            "9223372036854775808 B", "1000")));
 
     // The value cannot be negative.
     LambdaTestUtils.intercept(IllegalArgumentException.class,
@@ -848,11 +848,11 @@ public abstract class TestOzoneRpcClientAbstract {
 
     // Test bucket quota.
     store.getVolume(volumeName).setQuota(
-        OzoneQuota.parseQuota(Long.MAX_VALUE + " Bytes", "100"));
+        OzoneQuota.parseQuota(Long.MAX_VALUE + " B", "100"));
     bucketName = UUID.randomUUID().toString();
     volume.createBucket(bucketName);
     bucket = volume.getBucket(bucketName);
-    bucket.setQuota(OzoneQuota.parseQuota("1 Bytes", "100"));
+    bucket.setQuota(OzoneQuota.parseQuota("1 B", "100"));
 
     // Test bucket quota: write key.
     // The remaining quota does not satisfy a block size, so the write fails.
@@ -881,7 +881,7 @@ public abstract class TestOzoneRpcClientAbstract {
     // Test bucket quota: write large key(with five blocks), the first four
     // blocks will succeed,while the later block will fail.
     bucket.setQuota(OzoneQuota.parseQuota(
-        4 * blockSize + " Bytes", "100"));
+        4 * blockSize + " B", "100"));
 
     try {
       OzoneOutputStream out = bucket.createKey(UUID.randomUUID().toString(),
@@ -908,7 +908,7 @@ public abstract class TestOzoneRpcClientAbstract {
 
     // key with 0 bytes, usedBytes should not increase.
     bucket.setQuota(OzoneQuota.parseQuota(
-        5 * blockSize + " Bytes", "100"));
+        5 * blockSize + " B", "100"));
     OzoneOutputStream out = bucket.createKey(UUID.randomUUID().toString(),
         valueLength, STAND_ALONE, ONE, new HashMap<>());
     out.close();
@@ -983,7 +983,7 @@ public abstract class TestOzoneRpcClientAbstract {
     volume = store.getVolume(volumeName);
     volume.createBucket(bucketName);
     bucket = volume.getBucket(bucketName);
-    bucket.setQuota(OzoneQuota.parseQuota(Long.MAX_VALUE + " Bytes", "2"));
+    bucket.setQuota(OzoneQuota.parseQuota(Long.MAX_VALUE + " B", "2"));
 
     writeKey(bucket, key1, ONE, value, value.length());
     Assert.assertEquals(1L,
@@ -1006,7 +1006,7 @@ public abstract class TestOzoneRpcClientAbstract {
 
     // Reset bucket quota, the original usedNamespace needs to remain the same
     bucket.setQuota(
-        OzoneQuota.parseQuota(Long.MAX_VALUE + " Bytes", "100"));
+        OzoneQuota.parseQuota(Long.MAX_VALUE + " B", "100"));
     Assert.assertEquals(2L,
         store.getVolume(volumeName).getBucket(bucketName).getUsedNamespace());
 
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
index f0e6943..28882fd 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java
@@ -549,7 +549,7 @@ public class TestOzoneShellHA {
             .getQuotaInNamespace());
 
     // Test --quota option.
-    args = new String[]{"volume", "create", "vol1", "--quota", "100BYTES"};
+    args = new String[]{"volume", "create", "vol1", "--quota", "100B"};
     execute(ozoneShell, args);
     assertEquals(100, objectStore.getVolume("vol1").getQuotaInBytes());
     assertEquals(-1,
@@ -557,7 +557,7 @@ public class TestOzoneShellHA {
     out.reset();
 
     args =
-        new String[]{"bucket", "create", "vol1/buck1", "--quota", "10BYTES"};
+        new String[]{"bucket", "create", "vol1/buck1", "--quota", "10B"};
     execute(ozoneShell, args);
     assertEquals(10,
         objectStore.getVolume("vol1").getBucket("buck1").getQuotaInBytes());
@@ -567,7 +567,7 @@ public class TestOzoneShellHA {
 
     // Test --space-quota option.
     args = new String[]{"volume", "create", "vol2", "--space-quota",
-        "100BYTES"};
+        "100B"};
     execute(ozoneShell, args);
     assertEquals(100, objectStore.getVolume("vol2").getQuotaInBytes());
     assertEquals(-1,
@@ -575,7 +575,7 @@ public class TestOzoneShellHA {
     out.reset();
 
     args = new String[]{"bucket", "create", "vol2/buck2", "--space-quota",
-        "10BYTES"};
+        "10B"};
     execute(ozoneShell, args);
     assertEquals(10,
         objectStore.getVolume("vol2").getBucket("buck2").getQuotaInBytes());
@@ -603,7 +603,7 @@ public class TestOzoneShellHA {
 
     // Test both --space-quota and --namespace-quota option.
     args = new String[]{"volume", "create", "vol4", "--space-quota",
-        "100BYTES", "--namespace-quota", "100"};
+        "100B", "--namespace-quota", "100"};
     execute(ozoneShell, args);
     assertEquals(100, objectStore.getVolume("vol4").getQuotaInBytes());
     assertEquals(100,
@@ -611,7 +611,7 @@ public class TestOzoneShellHA {
     out.reset();
 
     args = new String[]{"bucket", "create", "vol4/buck4",
-        "--space-quota", "10BYTES", "--namespace-quota", "10"};
+        "--space-quota", "10B", "--namespace-quota", "10"};
     execute(ozoneShell, args);
     assertEquals(10,
         objectStore.getVolume("vol4").getBucket("buck4").getQuotaInBytes());
@@ -655,7 +655,7 @@ public class TestOzoneShellHA {
 
     // Test set volume spaceQuota or nameSpaceQuota to normal value.
     String[] volumeArgs3 = new String[]{"volume", "setquota", "vol4",
-        "--space-quota", "1000BYTES"};
+        "--space-quota", "1000B"};
     execute(ozoneShell, volumeArgs3);
     out.reset();
     assertEquals(1000, objectStore.getVolume("vol4").getQuotaInBytes());
@@ -687,7 +687,7 @@ public class TestOzoneShellHA {
 
     // Test set bucket spaceQuota or nameSpaceQuota to normal value.
     String[] bucketArgs3 = new String[]{"bucket", "setquota", "vol4/buck4",
-        "--space-quota", "1000BYTES"};
+        "--space-quota", "1000B"};
     execute(ozoneShell, bucketArgs3);
     out.reset();
     assertEquals(1000, objectStore.getVolume("vol4")
diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java
index 74a8e1e..affb36e 100644
--- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java
+++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/RandomKeyGenerator.java
@@ -845,7 +845,7 @@ public final class RandomKeyGenerator implements Callable<Void> {
         unit = OzoneConsts.Units.KB;
       } else {
         size = value;
-        unit = OzoneConsts.Units.BYTES;
+        unit = OzoneConsts.Units.B;
       }
       return size + " " + unit;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org