kerneltime commented on code in PR #3532:
URL: https://github.com/apache/ozone/pull/3532#discussion_r906912426


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/VolumeInfo.java:
##########
@@ -134,25 +135,45 @@ public VolumeInfo build() throws IOException {
   }
 
   private long getReserved(ConfigurationSource conf) {
+    final float defaultValue = Float.MAX_VALUE;

Review Comment:
   Here is a simpler version (by adding a new interface in 
`ConfigurationSource` interface 
   ```
   private long getReserved(ConfigurationSource conf) {
       if (conf.isConfigured(HDDS_DATANODE_VOLUME_RESERVED) &&
       conf.isConfigured(HDDS_DATANODE_DIR_DU_RESERVED)) {
         LOG.error("Both {} and {} are set. Set either one, not both. " +
                 "Setting reserved to 0.", HDDS_DATANODE_VOLUME_RESERVED,
             HDDS_DATANODE_DIR_DU_RESERVED);
         return 0;
       }
       if (conf.isConfigured(HDDS_DATANODE_VOLUME_RESERVED)) {
         final float defaultValue = 0;
         float percentage = conf.getFloat(HDDS_DATANODE_VOLUME_RESERVED,
             defaultValue);
         if (0 <= percentage && percentage <= 1) {
           return (long) Math.ceil(this.usage.getCapacity() * percentage);
         }
         //If it comes here then the percentage is not between 0-1.
         LOG.error("The value of {} should be between 0 to 1. Defaulting to 0.",
             HDDS_DATANODE_VOLUME_RESERVED);
         return 0;
       }
       
       Collection<String> reserveList = conf.getTrimmedStringCollection(
           HDDS_DATANODE_DIR_DU_RESERVED);
       //Both the configs are set. Log it and return 0
       if (reserveList.size() > 0) {
         for (String reserve : reserveList) {
           String[] words = reserve.split(":");
           if (words.length < 2) {
             LOG.error("Reserved space should config in pair, but current is 
{}",
                 reserve);
             continue;
           }
   
           if (words[0].trim().equals(rootDir)) {
             try {
               StorageSize size = StorageSize.parse(words[1].trim());
               return (long) size.getUnit().toBytes(size.getValue());
             } catch (Exception e) {
               LOG.error("Failed to parse StorageSize:{}", words[1].trim(), e);
               return 0;
             }
           }
         }
       }
       return 0;
     }
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

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