Class RegionReplicaGroupingCostFunction

java.lang.Object
org.apache.hadoop.hbase.master.balancer.CostFunction
org.apache.hadoop.hbase.master.balancer.RegionReplicaGroupingCostFunction
Direct Known Subclasses:
RegionReplicaHostCostFunction, RegionReplicaRackCostFunction

@Private abstract class RegionReplicaGroupingCostFunction extends CostFunction
A cost function for region replicas. We give a high cost for hosting replicas of the same region in the same server, host or rack. We do not prevent the case though, since if numReplicas > numRegionServers, we still want to keep the replica open.
  • Field Details

  • Constructor Details

  • Method Details

    • prepare

      final void prepare(BalancerClusterState cluster)
      Description copied from class: CostFunction
      Called once per LB invocation to give the cost function to initialize it's state, and perform any costly calculation.
      Overrides:
      prepare in class CostFunction
    • loadCosts

      protected abstract void loadCosts()
    • getMaxCost

      protected final long getMaxCost(BalancerClusterState cluster)
    • isNeeded

      boolean isNeeded()
      Overrides:
      isNeeded in class CostFunction
    • cost

      protected double cost()
      Specified by:
      cost in class CostFunction
    • costPerGroup

      protected final long costPerGroup(org.agrona.collections.Int2IntCounterMap colocatedReplicaCounts)
      For each primary region, it computes the total number of replicas in the array (numReplicas) and returns a sum of numReplicas-1 squared. For example, if the server hosts regions a, b, c, d, e, f where a and b are same replicas, and c,d,e are same replicas, it returns (2-1) * (2-1) + (3-1) * (3-1) + (1-1) * (1-1).
      Parameters:
      colocatedReplicaCounts - a sorted array of primary regions ids for the regions hosted
      Returns:
      a sum of numReplicas-1 squared for each primary region in the group.
    • updateWeight

      public final void updateWeight(double[] weights)
      Description copied from class: CostFunction
      Add the cost of this cost function to the weight of the candidate generator that is optimized for this cost function. By default it is the RandomCandiateGenerator for a cost function. Called once per init or after postAction.
      Overrides:
      updateWeight in class CostFunction
      Parameters:
      weights - the weights for every generator.