asdf2014 commented on a change in pull request #10203:
URL: https://github.com/apache/druid/pull/10203#discussion_r462263540



##########
File path: 
core/src/main/java/org/apache/druid/java/util/common/HumanReadableBytes.java
##########
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.java.util.common;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+@JsonSerialize(using = HumanReadableBytesSerializer.class)
+public class HumanReadableBytes
+{
+  public static final HumanReadableBytes ZERO = new HumanReadableBytes(0L);
+
+  private final long bytes;
+
+  public HumanReadableBytes(String bytes)
+  {
+    this.bytes = HumanReadableBytes.parse(bytes);
+  }
+
+  public HumanReadableBytes(long bytes)
+  {
+    this.bytes = bytes;
+  }
+
+  public long getBytes()
+  {
+    return bytes;
+  }
+
+  public int getBytesInInt()
+  {
+    if (bytes > Integer.MAX_VALUE) {
+      throw new ISE("Number overflow");
+    }
+
+    return (int) bytes;
+  }
+
+  @Override
+  public boolean equals(Object thatObj)
+  {
+    if (thatObj == null) {
+      return false;
+    }
+    if (thatObj instanceof HumanReadableBytes) {
+      return bytes == ((HumanReadableBytes) thatObj).bytes;
+    } else {
+      return false;
+    }
+  }
+
+  @Override
+  public int hashCode()
+  {
+    return Long.hashCode(bytes);
+  }
+
+  @Override
+  public String toString()
+  {
+    return String.valueOf(bytes);
+  }
+
+  public static HumanReadableBytes valueOf(int bytes)
+  {
+    return new HumanReadableBytes(bytes);
+  }
+
+  public static HumanReadableBytes valueOf(long bytes)
+  {
+    return new HumanReadableBytes(bytes);
+  }
+
+  public static long parse(String number)
+  {
+    if (number == null) {
+      throw new IAE("Invalid format of number: number is null");
+    }
+
+    number = number.trim();
+    if (number.length() == 0) {
+      throw new IAE("Invalid format of number: Number is empty");

Review comment:
       The error message is best to be consistent with the previous one. In 
addition, perhaps it is more appropriate to use `blank` instead of `empty` here.

##########
File path: docs/configuration/human-readable-byte.md
##########
@@ -0,0 +1,85 @@
+---
+id: human-readable-byte
+title: "Human-readable Byte Configuration Reference"
+---
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+
+This page documents all configuration properties related to bytes.
+
+These properties can be configured through 2 ways: 
+1. a simple number in byte
+2. a number with a unit suffix
+
+## A number in byte
+
+Given the cache size is 3G, there's a configuration as below
+
+````

Review comment:
       There should not be four ` symbols but three.

##########
File path: docs/configuration/human-readable-byte.md
##########
@@ -0,0 +1,85 @@
+---
+id: human-readable-byte
+title: "Human-readable Byte Configuration Reference"
+---
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+
+This page documents all configuration properties related to bytes.
+
+These properties can be configured through 2 ways: 
+1. a simple number in byte
+2. a number with a unit suffix
+
+## A number in byte
+
+Given the cache size is 3G, there's a configuration as below
+
+````
+druid.cache.sizeInBytes=3000000000 #3 * 1000_000_000
+````
+
+
+## A number with a unit suffix
+
+Sometimes value in bytes could be very large in Druid, it's counterintuitive 
to set value of these properties as above.
+Here comes another way, a number with a unit suffix.
+
+Given the total size of disks is 1T, the configuration can be
+
+````

Review comment:
       The type of code block should be specified as `properties`. The others 
should be the same.

##########
File path: website/.spelling
##########
@@ -1771,3 +1774,17 @@ CVE-2019-17571
 CVE-2019-12399
 CVE-2018-17196
 bin.tar.gz
+ - ../docs/configuration/human-readable-byte.md
+3G
+1000_000
+1000_000_000
+1000_000_000_000
+1000_000_000_000_000
+Giga
+Tera
+Peta
+KiB
+MiB
+GiB
+TiB
+PiB

Review comment:
       Please keep this blank line.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to