-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-25802 Miscellaneous style improvements for load balancer relate…
…d classes (#3192) Signed-off-by: Yulin Niu <[email protected]>
- Loading branch information
Showing
10 changed files
with
228 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...erver/src/main/java/org/apache/hadoop/hbase/master/balancer/RandomCandidateGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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 org.apache.yetus.audience.InterfaceAudience; | ||
|
||
@InterfaceAudience.Private | ||
class RandomCandidateGenerator extends CandidateGenerator { | ||
|
||
@Override | ||
BalanceAction generate(BalancerClusterState cluster) { | ||
int thisServer = pickRandomServer(cluster); | ||
|
||
// Pick the other server | ||
int otherServer = pickOtherRandomServer(cluster, thisServer); | ||
|
||
return pickRandomRegions(cluster, thisServer, otherServer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ain/java/org/apache/hadoop/hbase/master/balancer/RegionReplicaRackCandidateGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.concurrent.ThreadLocalRandom; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
|
||
/** | ||
* Generates candidates which moves the replicas out of the rack for co-hosted region replicas in | ||
* the same rack | ||
*/ | ||
@InterfaceAudience.Private | ||
class RegionReplicaRackCandidateGenerator extends RegionReplicaCandidateGenerator { | ||
|
||
@Override | ||
BalanceAction generate(BalancerClusterState cluster) { | ||
int rackIndex = pickRandomRack(cluster); | ||
if (cluster.numRacks <= 1 || rackIndex == -1) { | ||
return super.generate(cluster); | ||
} | ||
|
||
int regionIndex = selectCoHostedRegionPerGroup(cluster.primariesOfRegionsPerRack[rackIndex], | ||
cluster.regionsPerRack[rackIndex], cluster.regionIndexToPrimaryIndex); | ||
|
||
// if there are no pairs of region replicas co-hosted, default to random generator | ||
if (regionIndex == -1) { | ||
// default to randompicker | ||
return randomGenerator.generate(cluster); | ||
} | ||
|
||
int serverIndex = cluster.regionIndexToServerIndex[regionIndex]; | ||
int toRackIndex = pickOtherRandomRack(cluster, rackIndex); | ||
|
||
int rand = ThreadLocalRandom.current().nextInt(cluster.serversPerRack[toRackIndex].length); | ||
int toServerIndex = cluster.serversPerRack[toRackIndex][rand]; | ||
int toRegionIndex = pickRandomRegion(cluster, toServerIndex, 0.9f); | ||
return getAction(serverIndex, regionIndex, toServerIndex, toRegionIndex); | ||
} | ||
} |
Oops, something went wrong.