Class RegionReplicaGroupingCostFunction
java.lang.Object
org.apache.hadoop.hbase.master.balancer.CostFunction
org.apache.hadoop.hbase.master.balancer.RegionReplicaGroupingCostFunction
- Direct Known Subclasses:
RegionReplicaHostCostFunction
,RegionReplicaRackCostFunction
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 Summary
Fields inherited from class org.apache.hadoop.hbase.master.balancer.CostFunction
cluster, COST_EPSILON
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected double
cost()
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.protected final long
getMaxCost
(BalancerClusterState cluster) (package private) boolean
isNeeded()
protected abstract void
(package private) final void
prepare
(BalancerClusterState cluster) Called once per LB invocation to give the cost function to initialize it's state, and perform any costly calculation.final void
updateWeight
(double[] weights) Add the cost of this cost function to the weight of the candidate generator that is optimized for this cost function.Methods inherited from class org.apache.hadoop.hbase.master.balancer.CostFunction
getMultiplier, postAction, regionMoved, scale, setMultiplier
-
Field Details
-
maxCost
-
costsPerGroup
-
-
Constructor Details
-
RegionReplicaGroupingCostFunction
-
-
Method Details
-
prepare
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 classCostFunction
-
loadCosts
-
getMaxCost
-
isNeeded
boolean isNeeded()- Overrides:
isNeeded
in classCostFunction
-
cost
- Specified by:
cost
in classCostFunction
-
updateWeight
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 classCostFunction
- Parameters:
weights
- the weights for every generator.
-
costPerGroup
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.
-