lokeshj1703 commented on a change in pull request #1982: URL: https://github.com/apache/ozone/pull/1982#discussion_r597505555
########## File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeUsageInfo.java ########## @@ -0,0 +1,172 @@ +/** + * 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.hadoop.hdds.scm.node; + +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat; + +import java.util.Comparator; + +public class DatanodeUsageInfo { + + private DatanodeDetails datanodeDetails; + private SCMNodeStat scmNodeStat; + + /** + * Constructs a DatanodeUsageInfo with DatanodeDetails and SCMNodeStat. + * + * @param datanodeDetails DatanodeDetails + * @param scmNodeStat SCMNodeStat + */ + public DatanodeUsageInfo( + DatanodeDetails datanodeDetails, + SCMNodeStat scmNodeStat) { + this.datanodeDetails = datanodeDetails; + this.scmNodeStat = scmNodeStat; + } + + /** + * Compares two DatanodeUsageInfo on the basis of used space. + * + * @param first DatanodeUsageInfo + * @param second DatanodeUsageInfo + * @return a value greater than 0 if first is more used, a value + * lesser than 0 if second is more used, and 0 if both are equally used or + * first.equals(second) is true + */ + private static int compare(DatanodeUsageInfo first, + DatanodeUsageInfo second) { + if (first.equals(second)) { + return 0; + } + double remaining = first.scmNodeStat.getRemaining().get().doubleValue(); + double capacity = first.scmNodeStat.getCapacity().get().doubleValue(); + double ratioRemaining = remaining / capacity; Review comment: Lets move the SCMNodeStat comparison to its own class and use the corresponding fn here. ########## File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeUsageInfo.java ########## @@ -0,0 +1,172 @@ +/** + * 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.hadoop.hdds.scm.node; + +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat; + +import java.util.Comparator; + +public class DatanodeUsageInfo { + + private DatanodeDetails datanodeDetails; + private SCMNodeStat scmNodeStat; + + /** + * Constructs a DatanodeUsageInfo with DatanodeDetails and SCMNodeStat. + * + * @param datanodeDetails DatanodeDetails + * @param scmNodeStat SCMNodeStat + */ + public DatanodeUsageInfo( + DatanodeDetails datanodeDetails, + SCMNodeStat scmNodeStat) { + this.datanodeDetails = datanodeDetails; + this.scmNodeStat = scmNodeStat; + } + + /** + * Compares two DatanodeUsageInfo on the basis of used space. + * + * @param first DatanodeUsageInfo + * @param second DatanodeUsageInfo + * @return a value greater than 0 if first is more used, a value + * lesser than 0 if second is more used, and 0 if both are equally used or + * first.equals(second) is true + */ + private static int compare(DatanodeUsageInfo first, + DatanodeUsageInfo second) { + if (first.equals(second)) { + return 0; + } + double remaining = first.scmNodeStat.getRemaining().get().doubleValue(); + double capacity = first.scmNodeStat.getCapacity().get().doubleValue(); + double ratioRemaining = remaining / capacity; + + double secondRemaining = second.scmNodeStat + .getRemaining().get().doubleValue(); + double secondCapacity = second.scmNodeStat + .getCapacity().get().doubleValue(); + double secondRatioRemaining = secondRemaining / secondCapacity; + + return Double.compare(secondRatioRemaining, ratioRemaining); + } + + /** + * Sets DatanodeDetails of this DatanodeUsageInfo. + * + * @param datanodeDetails the DatanodeDetails to use + */ + public void setDatanodeDetails( + DatanodeDetails datanodeDetails) { + this.datanodeDetails = datanodeDetails; + } + + /** + * Sets SCMNodeStat of this DatanodeUsageInfo. + * + * @param scmNodeStat the SCMNodeStat to use. + */ + public void setScmNodeStat( + SCMNodeStat scmNodeStat) { + this.scmNodeStat = scmNodeStat; + } + + /** + * Gets DatanodeDetails of this DatanodeUsageInfo. + * + * @return DatanodeDetails + */ + public DatanodeDetails getDatanodeDetails() { + return datanodeDetails; + } + + /** + * Gets SCMNodeStat of this DatanodeUsageInfo. + * + * @return SCMNodeStat + */ + public SCMNodeStat getScmNodeStat() { + return scmNodeStat; + } + + /** + * Gets Comparator that compares two DatanodeUsageInfo on the basis of + * used space. The comparison function returns a value greater than 0 if + * first DatanodeUsageInfo is more used, a value lesser than 0 if second + * DatanodeUsageInfo is more used, and 0 if both are equally used or first + * .equals(second) is true + * + * @return Comparator to compare two DatanodeUsageInfo. + */ + public static Comparator<DatanodeUsageInfo> getUsageComparator() { Review comment: Let's rename this to getMostUsedByRemainingPercentage or sth similar. ########## File path: hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeUsageInfo.java ########## @@ -0,0 +1,172 @@ +/** + * 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.hadoop.hdds.scm.node; + +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat; + +import java.util.Comparator; + +public class DatanodeUsageInfo { + + private DatanodeDetails datanodeDetails; + private SCMNodeStat scmNodeStat; + + /** + * Constructs a DatanodeUsageInfo with DatanodeDetails and SCMNodeStat. + * + * @param datanodeDetails DatanodeDetails + * @param scmNodeStat SCMNodeStat + */ + public DatanodeUsageInfo( + DatanodeDetails datanodeDetails, + SCMNodeStat scmNodeStat) { + this.datanodeDetails = datanodeDetails; + this.scmNodeStat = scmNodeStat; + } + + /** + * Compares two DatanodeUsageInfo on the basis of used space. + * + * @param first DatanodeUsageInfo + * @param second DatanodeUsageInfo + * @return a value greater than 0 if first is more used, a value + * lesser than 0 if second is more used, and 0 if both are equally used or + * first.equals(second) is true + */ + private static int compare(DatanodeUsageInfo first, Review comment: Let's rename to compareByRemainingPercentage or sth similar? Also update the doc to reflect same. -- 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]
