HBASE-27202 Clean up error-prone findings in hbase-balancer (#4623)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Andrew Purtell 2022-07-18 15:35:43 -07:00 committed by GitHub
parent b7117a443d
commit 5af4b3d5c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 17 deletions

View File

@ -111,7 +111,7 @@ public class FavoredNodeAssignmentHelper {
break; break;
} }
} }
serverList.add((sn)); serverList.add(sn);
this.regionServerToRackMap.put(sn.getHostname(), rackName); this.regionServerToRackMap.put(sn.getHostname(), rackName);
} }
} }
@ -235,7 +235,7 @@ public class FavoredNodeAssignmentHelper {
if (numIterations % rackList.size() == 0) { if (numIterations % rackList.size() == 0) {
if (++serverIndex >= maxRackSize) serverIndex = 0; if (++serverIndex >= maxRackSize) serverIndex = 0;
} }
if ((++rackIndex) >= rackList.size()) { if (++rackIndex >= rackList.size()) {
rackIndex = 0; // reset the rack index to 0 rackIndex = 0; // reset the rack index to 0
} }
} else break; } else break;
@ -259,7 +259,7 @@ public class FavoredNodeAssignmentHelper {
if (numIterations % rackList.size() == 0) { if (numIterations % rackList.size() == 0) {
++serverIndex; ++serverIndex;
} }
if ((++rackIndex) >= rackList.size()) { if (++rackIndex >= rackList.size()) {
rackIndex = 0; // reset the rack index to 0 rackIndex = 0; // reset the rack index to 0
} }
} }
@ -298,7 +298,7 @@ public class FavoredNodeAssignmentHelper {
if (getTotalNumberOfRacks() == 1) { if (getTotalNumberOfRacks() == 1) {
favoredNodes = singleRackCase(regionInfo, primaryRS, primaryRack); favoredNodes = singleRackCase(regionInfo, primaryRS, primaryRack);
} else { } else {
favoredNodes = multiRackCase(regionInfo, primaryRS, primaryRack); favoredNodes = multiRackCase(primaryRS, primaryRack);
} }
return favoredNodes; return favoredNodes;
} }
@ -483,14 +483,12 @@ public class FavoredNodeAssignmentHelper {
* has only one region server, then we place primary and tertiary on one rack and secondary on * has only one region server, then we place primary and tertiary on one rack and secondary on
* another. The aim is two distribute the three favored nodes on >= 2 racks. TODO: see how we can * another. The aim is two distribute the three favored nodes on >= 2 racks. TODO: see how we can
* use generateMissingFavoredNodeMultiRack API here * use generateMissingFavoredNodeMultiRack API here
* @param regionInfo Region for which we are trying to generate FN
* @param primaryRS The primary favored node. * @param primaryRS The primary favored node.
* @param primaryRack The rack of the primary favored node. * @param primaryRack The rack of the primary favored node.
* @return Array containing secondary and tertiary favored nodes. * @return Array containing secondary and tertiary favored nodes.
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private ServerName[] multiRackCase(RegionInfo regionInfo, ServerName primaryRS, private ServerName[] multiRackCase(ServerName primaryRS, String primaryRack) throws IOException {
String primaryRack) throws IOException {
List<ServerName> favoredNodes = Lists.newArrayList(primaryRS); List<ServerName> favoredNodes = Lists.newArrayList(primaryRS);
// Create the secondary and tertiary pair // Create the secondary and tertiary pair

View File

@ -99,7 +99,7 @@ public class FavoredNodesPlan {
} }
/** /**
* @return the mapping between each region to its favored region server list * Return the mapping between each region to its favored region server list.
*/ */
public Map<String, List<ServerName>> getAssignmentMap() { public Map<String, List<ServerName>> getAssignmentMap() {
// Make a deep copy so changes don't harm our copy of favoredNodesMap. // Make a deep copy so changes don't harm our copy of favoredNodesMap.
@ -119,7 +119,7 @@ public class FavoredNodesPlan {
if (o == null) { if (o == null) {
return false; return false;
} }
if (getClass() != o.getClass()) { if (!(o instanceof FavoredNodesPlan)) {
return false; return false;
} }
// To compare the map from object o is identical to current assignment map. // To compare the map from object o is identical to current assignment map.

View File

@ -409,8 +409,8 @@ public class AssignmentVerificationReport {
} }
/** /**
* @return list which contains just 3 elements: average dispersion score, max dispersion score and * Return a list which contains 3 elements: average dispersion score, max dispersion score and min
* min dispersion score as first, second and third element respectively. * dispersion score as first, second and third elements, respectively.
*/ */
public List<Float> getDispersionInformation() { public List<Float> getDispersionInformation() {
List<Float> dispersion = new ArrayList<>(); List<Float> dispersion = new ArrayList<>();
@ -578,7 +578,7 @@ public class AssignmentVerificationReport {
} }
int i = 0; int i = 0;
for (ServerName addr : serverSet) { for (ServerName addr : serverSet) {
if ((i++) % 3 == 0) { if (i++ % 3 == 0) {
System.out.print("\n\t\t\t"); System.out.print("\n\t\t\t");
} }
System.out.print(addr.getAddress() + " ; "); System.out.print(addr.getAddress() + " ; ");

View File

@ -148,10 +148,7 @@ public class RegionPlan implements Comparable<RegionPlan> {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null) { if (!(obj instanceof RegionPlan)) {
return false;
}
if (getClass() != obj.getClass()) {
return false; return false;
} }
RegionPlan other = (RegionPlan) obj; RegionPlan other = (RegionPlan) obj;

View File

@ -218,7 +218,7 @@ class BalancerClusterState {
colocatedReplicaCountsPerHost = new Int2IntCounterMap[numHosts]; colocatedReplicaCountsPerHost = new Int2IntCounterMap[numHosts];
colocatedReplicaCountsPerRack = new Int2IntCounterMap[numRacks]; colocatedReplicaCountsPerRack = new Int2IntCounterMap[numRacks];
int tableIndex = 0, regionIndex = 0, regionPerServerIndex = 0; int regionIndex = 0, regionPerServerIndex = 0;
for (Map.Entry<ServerName, List<RegionInfo>> entry : clusterState.entrySet()) { for (Map.Entry<ServerName, List<RegionInfo>> entry : clusterState.entrySet()) {
if (entry.getKey() == null) { if (entry.getKey() == null) {

View File

@ -246,6 +246,7 @@ class RegionHDFSBlockLocationFinder extends Configured {
*/ */
@RestrictedApi(explanation = "Should only be called in tests", link = "", @RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*|.*/RegionHDFSBlockLocationFinder.java") allowedOnPath = ".*/src/test/.*|.*/RegionHDFSBlockLocationFinder.java")
@SuppressWarnings("MixedMutabilityReturnType")
List<ServerName> mapHostNameToServerName(List<String> hosts) { List<ServerName> mapHostNameToServerName(List<String> hosts) {
if (hosts == null || status == null) { if (hosts == null || status == null) {
if (hosts == null) { if (hosts == null) {