You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2020/12/09 07:46:12 UTC
[GitHub] [ozone] captainzmc commented on a change in pull request #1647: HDDS-4265. Refactor OzoneQuota to make it easy to support more quota …
captainzmc commented on a change in pull request #1647:
URL: https://github.com/apache/ozone/pull/1647#discussion_r539066086
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -43,13 +43,25 @@
public static final String OZONE_QUOTA_TB = "TB";
/** Quota Units.*/
- public enum Units {UNDEFINED, BYTES, KB, MB, GB, TB}
+ public enum Units {BYTES, KB, MB, GB, TB}
// Quota to decide how many buckets can be created.
private long quotaInCounts;
// Quota to decide how many storage space will be used in bytes.
private long quotaInBytes;
private RawQuotaInBytes rawQuotaInBytes;
+ // Data class of Quota.
+ private static QuotaList quotaList;
Review comment:
we can Initialize quotaList in static {}
```suggestion
private static QuotaList quotaList;
static {
quotaList = new QuotaList();
quotaList.addQuotaList(OZONE_QUOTA_TB, Units.TB, TB);
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);
}
```
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -164,45 +171,21 @@ public static OzoneQuota parseQuota(String quotaInBytes,
long quotaMultiplyExact = 0;
try {
- if (uppercase.endsWith(OZONE_QUOTA_KB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_KB.length());
- currUnit = Units.KB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), KB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_MB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_MB.length());
- currUnit = Units.MB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), MB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_GB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_GB.length());
- currUnit = Units.GB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), GB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_TB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_TB.length());
- currUnit = Units.TB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), TB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_BYTES)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_BYTES.length());
- currUnit = Units.BYTES;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), 1L);
+ for(String quota:quotaList.getOzoneQuotaArray()){
Review comment:
space
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -72,24 +84,18 @@ public long getSize() {
}
/**
- * Returns size in Bytes or -1 if there is no Quota.
+ * Returns size in Bytes or negative num if there is no Quota.
*/
public long sizeInBytes() {
- switch (this.unit) {
- case BYTES:
- return this.getSize();
- case KB:
- return this.getSize() * KB;
- case MB:
- return this.getSize() * MB;
- case GB:
- return this.getSize() * GB;
- case TB:
- return this.getSize() * TB;
- case UNDEFINED:
- default:
- return -1;
+ long sQuote = -1L;
+ setQuotaList();
+ for(Units quota:quotaList.getUnitQuotaArray()){
Review comment:
space
```suggestion
for(Units quota : quotaList.getUnitQuotaArray()){
```
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -227,24 +210,15 @@ public static OzoneQuota parseQuota(String quotaInBytes,
* @return OzoneQuota object
*/
public static OzoneQuota getOzoneQuota(long quotaInBytes,
- long quotaInCounts) {
- long size;
- Units unit;
- if (quotaInBytes % TB == 0) {
- size = quotaInBytes / TB;
- unit = Units.TB;
- } else if (quotaInBytes % GB == 0) {
- size = quotaInBytes / GB;
- unit = Units.GB;
- } else if (quotaInBytes % MB == 0) {
- size = quotaInBytes / MB;
- unit = Units.MB;
- } else if (quotaInBytes % KB == 0) {
- size = quotaInBytes / KB;
- unit = Units.KB;
- } else {
- size = quotaInBytes;
- unit = Units.BYTES;
+ long quotaInCounts) {
Review comment:
indentation
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -164,45 +171,21 @@ public static OzoneQuota parseQuota(String quotaInBytes,
long quotaMultiplyExact = 0;
try {
- if (uppercase.endsWith(OZONE_QUOTA_KB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_KB.length());
- currUnit = Units.KB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), KB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_MB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_MB.length());
- currUnit = Units.MB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), MB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_GB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_GB.length());
- currUnit = Units.GB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), GB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_TB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_TB.length());
- currUnit = Units.TB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), TB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_BYTES)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_BYTES.length());
- currUnit = Units.BYTES;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), 1L);
+ for(String quota:quotaList.getOzoneQuotaArray()){
+ if (uppercase.endsWith((quota))){
+ size = uppercase
+ .substring(0, uppercase.length() - quota.length());
+ currUnit = quotaList.getUnits(quota);
+ quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size),
+ quotaList.getQuotaSize(currUnit));
Review comment:
indentation
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -227,24 +210,15 @@ public static OzoneQuota parseQuota(String quotaInBytes,
* @return OzoneQuota object
*/
public static OzoneQuota getOzoneQuota(long quotaInBytes,
- long quotaInCounts) {
- long size;
- Units unit;
- if (quotaInBytes % TB == 0) {
- size = quotaInBytes / TB;
- unit = Units.TB;
- } else if (quotaInBytes % GB == 0) {
- size = quotaInBytes / GB;
- unit = Units.GB;
- } else if (quotaInBytes % MB == 0) {
- size = quotaInBytes / MB;
- unit = Units.MB;
- } else if (quotaInBytes % KB == 0) {
- size = quotaInBytes / KB;
- unit = Units.KB;
- } else {
- size = quotaInBytes;
- unit = Units.BYTES;
+ long quotaInCounts) {
+ long size = 1L;
+ Units unit = Units.BYTES;
+ setQuotaList();
+ for (Long quota:quotaList.getSizeQuotaArray()){
Review comment:
space
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -164,45 +171,21 @@ public static OzoneQuota parseQuota(String quotaInBytes,
long quotaMultiplyExact = 0;
try {
- if (uppercase.endsWith(OZONE_QUOTA_KB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_KB.length());
- currUnit = Units.KB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), KB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_MB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_MB.length());
- currUnit = Units.MB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), MB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_GB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_GB.length());
- currUnit = Units.GB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), GB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_TB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_TB.length());
- currUnit = Units.TB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), TB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_BYTES)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_BYTES.length());
- currUnit = Units.BYTES;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), 1L);
+ for(String quota:quotaList.getOzoneQuotaArray()){
+ if (uppercase.endsWith((quota))){
+ 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).");
+ " that the Quota format is legal(supported values are BYTES, " +
+ " KB, MB, GB and TB).");
Review comment:
indentation
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -164,45 +171,21 @@ public static OzoneQuota parseQuota(String quotaInBytes,
long quotaMultiplyExact = 0;
try {
- if (uppercase.endsWith(OZONE_QUOTA_KB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_KB.length());
- currUnit = Units.KB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), KB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_MB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_MB.length());
- currUnit = Units.MB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), MB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_GB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_GB.length());
- currUnit = Units.GB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), GB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_TB)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_TB.length());
- currUnit = Units.TB;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), TB);
- }
-
- if (uppercase.endsWith(OZONE_QUOTA_BYTES)) {
- size = uppercase
- .substring(0, uppercase.length() - OZONE_QUOTA_BYTES.length());
- currUnit = Units.BYTES;
- quotaMultiplyExact = Math.multiplyExact(Long.parseLong(size), 1L);
+ for(String quota:quotaList.getOzoneQuotaArray()){
+ if (uppercase.endsWith((quota))){
+ size = uppercase
+ .substring(0, uppercase.length() - quota.length());
Review comment:
indentation
##########
File path: hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
##########
@@ -72,24 +84,18 @@ public long getSize() {
}
/**
- * Returns size in Bytes or -1 if there is no Quota.
+ * Returns size in Bytes or negative num if there is no Quota.
*/
public long sizeInBytes() {
- switch (this.unit) {
- case BYTES:
- return this.getSize();
- case KB:
- return this.getSize() * KB;
- case MB:
- return this.getSize() * MB;
- case GB:
- return this.getSize() * GB;
- case TB:
- return this.getSize() * TB;
- case UNDEFINED:
- default:
- return -1;
+ long sQuote = -1L;
Review comment:
Should it be sQuota?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org