ndimiduk commented on a change in pull request #3276: URL: https://github.com/apache/hbase/pull/3276#discussion_r649487211
########## File path: hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/DoubleArrayCost.java ########## @@ -0,0 +1,100 @@ +/** + * 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.hbase.master.balancer; + +import java.util.function.Consumer; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * A helper class to compute a scaled cost using + * {@link org.apache.commons.math3.stat.descriptive.DescriptiveStatistics#DescriptiveStatistics()}. + * It assumes that this is a zero sum set of costs. It assumes that the worst case possible is all + * of the elements in one region server and the rest having 0. + */ [email protected] +final class DoubleArrayCost { + + private double[] costs; + + // computeCost call is expensive so we use this flag to indicate whether we need to recalculate + // the cost by calling computeCost + private boolean costsChanged; + + private double cost; + + void prepare(int length) { + if (costs == null || costs.length != length) { + costs = new double[length]; + } + } + + void setCosts(Consumer<double[]> consumer) { Review comment: Not off the top of my head, no. This interface for mutability by an external actor is a little strange. Maybe `applyCostsConsumer` ? -- 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]
