saintstack commented on a change in pull request #3575: URL: https://github.com/apache/hbase/pull/3575#discussion_r686475878
########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -207,15 +212,20 @@ public String getRack(ServerName server) { serverIndexToHostIndex = new int[numServers]; serverIndexToRackIndex = new int[numServers]; - regionsPerServer = new int[numServers][]; - serverIndexToRegionsOffset = new int[numServers]; - regionsPerHost = new int[numHosts][]; - regionsPerRack = new int[numRacks][]; - primariesOfRegionsPerServer = new int[numServers][]; - primariesOfRegionsPerHost = new int[numHosts][]; - primariesOfRegionsPerRack = new int[numRacks][]; + regionsPerServer = new ArrayList<ArrayList<Integer>>(numServers); + regionsPerHost = new ArrayList<HashSet<Integer>>(numHosts); + regionsPerRack = new ArrayList<HashSet<Integer>>(numRacks); + primariesOfRegionsPerServer = new ArrayList<HashMap<Integer, ArrayList<Integer>>>(numServers); + primariesOfRegionsPerHost = new ArrayList<HashMap<Integer, ArrayList<Integer>>>(numHosts); + primariesOfRegionsPerRack = new ArrayList<HashMap<Integer, ArrayList<Integer>>>(numRacks); Review comment: Here too? ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -207,15 +212,20 @@ public String getRack(ServerName server) { serverIndexToHostIndex = new int[numServers]; serverIndexToRackIndex = new int[numServers]; - regionsPerServer = new int[numServers][]; - serverIndexToRegionsOffset = new int[numServers]; - regionsPerHost = new int[numHosts][]; - regionsPerRack = new int[numRacks][]; - primariesOfRegionsPerServer = new int[numServers][]; - primariesOfRegionsPerHost = new int[numHosts][]; - primariesOfRegionsPerRack = new int[numRacks][]; + regionsPerServer = new ArrayList<ArrayList<Integer>>(numServers); + regionsPerHost = new ArrayList<HashSet<Integer>>(numHosts); + regionsPerRack = new ArrayList<HashSet<Integer>>(numRacks); + primariesOfRegionsPerServer = new ArrayList<HashMap<Integer, ArrayList<Integer>>>(numServers); Review comment: Can s/?/HashSet<Integer>/ ... in all of these. ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -207,15 +212,20 @@ public String getRack(ServerName server) { serverIndexToHostIndex = new int[numServers]; serverIndexToRackIndex = new int[numServers]; - regionsPerServer = new int[numServers][]; - serverIndexToRegionsOffset = new int[numServers]; - regionsPerHost = new int[numHosts][]; - regionsPerRack = new int[numRacks][]; - primariesOfRegionsPerServer = new int[numServers][]; - primariesOfRegionsPerHost = new int[numHosts][]; - primariesOfRegionsPerRack = new int[numRacks][]; + regionsPerServer = new ArrayList<ArrayList<Integer>>(numServers); + regionsPerHost = new ArrayList<HashSet<Integer>>(numHosts); + regionsPerRack = new ArrayList<HashSet<Integer>>(numRacks); + primariesOfRegionsPerServer = new ArrayList<HashMap<Integer, ArrayList<Integer>>>(numServers); + primariesOfRegionsPerHost = new ArrayList<HashMap<Integer, ArrayList<Integer>>>(numHosts); + primariesOfRegionsPerRack = new ArrayList<HashMap<Integer, ArrayList<Integer>>>(numRacks); + + for (Map.Entry<ServerName, List<RegionInfo>> entry : clusterState.entrySet()) { + regionsPerServer.add(new ArrayList<Integer>(entry.getValue().size())); + primariesOfRegionsPerServer.add( + new HashMap<Integer, ArrayList<Integer>>(entry.getValue().size())); Review comment: s/Map/HashMap/... etc. ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -699,102 +684,57 @@ void regionMoved(int region, int oldServer, int newServer) { // update for servers int primary = regionIndexToPrimaryIndex[region]; if (oldServer >= 0) { - primariesOfRegionsPerServer[oldServer] = - removeRegion(primariesOfRegionsPerServer[oldServer], primary); + removeElement(primariesOfRegionsPerServer.get(oldServer), primary, region); } - primariesOfRegionsPerServer[newServer] = - addRegionSorted(primariesOfRegionsPerServer[newServer], primary); + addElement(primariesOfRegionsPerServer.get(newServer), primary, region); // update for hosts if (multiServersPerHost) { - int oldHost = oldServer >= 0 ? serverIndexToHostIndex[oldServer] : -1; - int newHost = serverIndexToHostIndex[newServer]; - if (newHost != oldHost) { - regionsPerHost[newHost] = addRegion(regionsPerHost[newHost], region); - primariesOfRegionsPerHost[newHost] = - addRegionSorted(primariesOfRegionsPerHost[newHost], primary); - if (oldHost >= 0) { - regionsPerHost[oldHost] = removeRegion(regionsPerHost[oldHost], region); - primariesOfRegionsPerHost[oldHost] = - removeRegion(primariesOfRegionsPerHost[oldHost], primary); // will still be sorted - } - } + updateForLocation(serverIndexToHostIndex, regionsPerHost, primariesOfRegionsPerHost, + oldServer, newServer, primary, region); } // update for racks if (numRacks > 1) { - int oldRack = oldServer >= 0 ? serverIndexToRackIndex[oldServer] : -1; - int newRack = serverIndexToRackIndex[newServer]; - if (newRack != oldRack) { - regionsPerRack[newRack] = addRegion(regionsPerRack[newRack], region); - primariesOfRegionsPerRack[newRack] = - addRegionSorted(primariesOfRegionsPerRack[newRack], primary); - if (oldRack >= 0) { - regionsPerRack[oldRack] = removeRegion(regionsPerRack[oldRack], region); - primariesOfRegionsPerRack[oldRack] = - removeRegion(primariesOfRegionsPerRack[oldRack], primary); // will still be sorted - } - } - } - } - - int[] removeRegion(int[] regions, int regionIndex) { - // TODO: this maybe costly. Consider using linked lists - int[] newRegions = new int[regions.length - 1]; - int i = 0; - for (i = 0; i < regions.length; i++) { - if (regions[i] == regionIndex) { - break; - } - newRegions[i] = regions[i]; + updateForLocation(serverIndexToRackIndex, regionsPerRack, primariesOfRegionsPerRack, + oldServer, newServer, primary, region); } - System.arraycopy(regions, i + 1, newRegions, i, newRegions.length - i); - return newRegions; - } - - int[] addRegion(int[] regions, int regionIndex) { - int[] newRegions = new int[regions.length + 1]; - System.arraycopy(regions, 0, newRegions, 0, regions.length); - newRegions[newRegions.length - 1] = regionIndex; - return newRegions; } - int[] addRegionSorted(int[] regions, int regionIndex) { - int[] newRegions = new int[regions.length + 1]; - int i = 0; - for (i = 0; i < regions.length; i++) { // find the index to insert - if (regions[i] > regionIndex) { - break; + /** + * Common method for per host and per rack region index updates when a region is moved. + * @param serverIndexToLocation serverIndexToHostIndex or serverIndexToRackIndex + * @param regionsPerLocation regionsPerHost or regionsPerRack + * @param primariesOfRegionsPerLocation primariesOfRegionsPerHost or primariesOfRegionsPerRack + */ + private void updateForLocation(int[] serverIndexToLocation, + ArrayList<HashSet<Integer>> regionsPerLocation, Review comment: s/List/ArrayList/ ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -65,15 +66,19 @@ int[] serverIndexToHostIndex; // serverIndex -> host index int[] serverIndexToRackIndex; // serverIndex -> rack index + ArrayList<ArrayList<Integer>> regionsPerServer; // serverIndex -> region list - int[][] regionsPerServer; // serverIndex -> region list - int[] serverIndexToRegionsOffset; // serverIndex -> offset of region list - int[][] regionsPerHost; // hostIndex -> list of regions - int[][] regionsPerRack; // rackIndex -> region list - int[][] primariesOfRegionsPerServer; // serverIndex -> sorted list of regions by primary region - // index - int[][] primariesOfRegionsPerHost; // hostIndex -> sorted list of regions by primary region index - int[][] primariesOfRegionsPerRack; // rackIndex -> sorted list of regions by primary region index + ArrayList<HashSet<Integer>> regionsPerHost; // hostIndex -> list of regions + ArrayList<HashSet<Integer>> regionsPerRack; // rackIndex -> region list + + // serverIndex -> hash map of count by primary region index per server + ArrayList<HashMap<Integer, ArrayList<Integer>>> primariesOfRegionsPerServer; + + // hostIndex -> hash map of count by primary region index per server + ArrayList<HashMap<Integer, ArrayList<Integer>>> primariesOfRegionsPerHost; + + // rackIndex -> hash map of count by primary region index per server + ArrayList<HashMap<Integer, ArrayList<Integer>>> primariesOfRegionsPerRack; Review comment: s/List/ArrayList/ here unless you are using methods on ArrayLiist not in List? ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -878,4 +820,30 @@ private double getSkewChangeFor(int serverIndex, int tableIndex, int regionCount regionCountChange - meanRegionsPerTable[tableIndex]); return curSkew - oldSkew; } + + public static void addElement(HashMap<Integer, ArrayList<Integer>> map, Integer key, + Integer value) { + if (map == null) { + LOG.warn("add element to null"); + return; + } + ArrayList list = map.get(key); Review comment: s/List/ArrayList/ ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -341,66 +340,45 @@ public String getRack(ServerName server) { } } - for (int i = 0; i < regionsPerServer.length; i++) { - primariesOfRegionsPerServer[i] = new int[regionsPerServer[i].length]; - for (int j = 0; j < regionsPerServer[i].length; j++) { - int primaryIndex = regionIndexToPrimaryIndex[regionsPerServer[i][j]]; - primariesOfRegionsPerServer[i][j] = primaryIndex; + for (int i = 0; i < regionsPerServer.size(); i++) { + for (Integer region : regionsPerServer.get(i)) { + addElement(primariesOfRegionsPerServer.get(i), regionIndexToPrimaryIndex[region], region); } - // sort the regions by primaries. - Arrays.sort(primariesOfRegionsPerServer[i]); } // compute regionsPerHost if (multiServersPerHost) { - for (int i = 0; i < serversPerHost.length; i++) { - int numRegionsPerHost = 0; - for (int j = 0; j < serversPerHost[i].length; j++) { - numRegionsPerHost += regionsPerServer[serversPerHost[i][j]].length; - } - regionsPerHost[i] = new int[numRegionsPerHost]; - primariesOfRegionsPerHost[i] = new int[numRegionsPerHost]; - } - for (int i = 0; i < serversPerHost.length; i++) { - int numRegionPerHostIndex = 0; - for (int j = 0; j < serversPerHost[i].length; j++) { - for (int k = 0; k < regionsPerServer[serversPerHost[i][j]].length; k++) { - int region = regionsPerServer[serversPerHost[i][j]][k]; - regionsPerHost[i][numRegionPerHostIndex] = region; - int primaryIndex = regionIndexToPrimaryIndex[region]; - primariesOfRegionsPerHost[i][numRegionPerHostIndex] = primaryIndex; - numRegionPerHostIndex++; - } - } - // sort the regions by primaries. - Arrays.sort(primariesOfRegionsPerHost[i]); - } + populateRegionPerLocationFromServer(regionsPerHost, primariesOfRegionsPerHost, + serversPerHost); } // compute regionsPerRack if (numRacks > 1) { - for (int i = 0; i < serversPerRack.length; i++) { - int numRegionsPerRack = 0; - for (int j = 0; j < serversPerRack[i].length; j++) { - numRegionsPerRack += regionsPerServer[serversPerRack[i][j]].length; - } - regionsPerRack[i] = new int[numRegionsPerRack]; - primariesOfRegionsPerRack[i] = new int[numRegionsPerRack]; - } + populateRegionPerLocationFromServer(regionsPerRack, primariesOfRegionsPerRack, + serversPerRack); + } + } - for (int i = 0; i < serversPerRack.length; i++) { - int numRegionPerRackIndex = 0; - for (int j = 0; j < serversPerRack[i].length; j++) { - for (int k = 0; k < regionsPerServer[serversPerRack[i][j]].length; k++) { - int region = regionsPerServer[serversPerRack[i][j]][k]; - regionsPerRack[i][numRegionPerRackIndex] = region; - int primaryIndex = regionIndexToPrimaryIndex[region]; - primariesOfRegionsPerRack[i][numRegionPerRackIndex] = primaryIndex; - numRegionPerRackIndex++; - } + private void populateRegionPerLocationFromServer(ArrayList<HashSet<Integer>> regionsPerLocation, + ArrayList<HashMap<Integer, ArrayList<Integer>>> primariesOfRegionsPerLocation, + int[][] serversPerLocation) { + for (int i = 0; i < serversPerLocation.length; i++) { + int numRegionsPerLocation = 0; + for (int j = 0; j < serversPerLocation[i].length; j++) { + numRegionsPerLocation += regionsPerServer.get(serversPerLocation[i][j]).size(); + } + regionsPerLocation.add(new HashSet<Integer>(numRegionsPerLocation)); + primariesOfRegionsPerLocation.add( + new HashMap<Integer, ArrayList<Integer>>(numRegionsPerLocation)); Review comment: Here too... ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -878,4 +820,30 @@ private double getSkewChangeFor(int serverIndex, int tableIndex, int regionCount regionCountChange - meanRegionsPerTable[tableIndex]); return curSkew - oldSkew; } + + public static void addElement(HashMap<Integer, ArrayList<Integer>> map, Integer key, + Integer value) { + if (map == null) { + LOG.warn("add element to null"); + return; + } + ArrayList list = map.get(key); + if(list == null) { + list = new ArrayList(); + map.put(key, list); + } + list.add(value); + } + + public static void removeElement(HashMap<Integer, ArrayList<Integer>> map, Review comment: s/Map/HashMap/ etc. ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -878,4 +820,30 @@ private double getSkewChangeFor(int serverIndex, int tableIndex, int regionCount regionCountChange - meanRegionsPerTable[tableIndex]); return curSkew - oldSkew; } + + public static void addElement(HashMap<Integer, ArrayList<Integer>> map, Integer key, + Integer value) { + if (map == null) { + LOG.warn("add element to null"); + return; + } + ArrayList list = map.get(key); + if(list == null) { + list = new ArrayList(); + map.put(key, list); Review comment: Only a single-thread in here? ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -878,4 +820,30 @@ private double getSkewChangeFor(int serverIndex, int tableIndex, int regionCount regionCountChange - meanRegionsPerTable[tableIndex]); return curSkew - oldSkew; } + + public static void addElement(HashMap<Integer, ArrayList<Integer>> map, Integer key, + Integer value) { + if (map == null) { + LOG.warn("add element to null"); + return; + } + ArrayList list = map.get(key); + if(list == null) { + list = new ArrayList(); + map.put(key, list); + } + list.add(value); + } + + public static void removeElement(HashMap<Integer, ArrayList<Integer>> map, + Integer key, Integer value) { + if (map == null) { + LOG.warn("remove element from null"); + return; + } + ArrayList list = map.get(key); Review comment: s/List/ArrayList/ ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -818,20 +757,19 @@ int getLowestLocalityRegionOnServer(int serverIndex) { } if (locality < lowestLocality) { lowestLocality = locality; - lowestLocalityRegionIndex = j; + lowestLocalityRegionIndex = regionIndex; } } - if (lowestLocalityRegionIndex == -1) { + if (lowestLocality == 1.0f) { return -1; } if (LOG.isTraceEnabled()) { - LOG.trace("Lowest locality region is " + - regions[regionsPerServer[serverIndex][lowestLocalityRegionIndex]] + LOG.trace("Lowest locality region is " + regions[lowestLocalityRegionIndex] Review comment: Don't need the isTraceEnabled if parameterized logging. ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -639,36 +613,47 @@ boolean wouldLowerAvailability(RegionInfo regionInfo, ServerName serverName) { // check host if (multiServersPerHost) { - // these arrays would only be allocated if we have more than one server per host - int host = serverIndexToHostIndex[server]; - if (contains(primariesOfRegionsPerHost[host], primary)) { - // check for whether there are other hosts that we can place this region - for (int i = 0; i < primariesOfRegionsPerHost.length; i++) { - if (i != host && !contains(primariesOfRegionsPerHost[i], primary)) { - return true; // meaning there is a better host - } - } - return false; // there is not a better host to place this + int result = checkLocationForPrimary(serverIndexToHostIndex, primariesOfRegionsPerHost, + server, primary); + if (result != 0) { + return result > 0; } } // check rack if (numRacks > 1) { - int rack = serverIndexToRackIndex[server]; - if (contains(primariesOfRegionsPerRack[rack], primary)) { - // check for whether there are other racks that we can place this region - for (int i = 0; i < primariesOfRegionsPerRack.length; i++) { - if (i != rack && !contains(primariesOfRegionsPerRack[i], primary)) { - return true; // meaning there is a better rack - } - } - return false; // there is not a better rack to place this + int result = checkLocationForPrimary(serverIndexToRackIndex, primariesOfRegionsPerRack, + server, primary); + if (result != 0) { + return result > 0; } } return false; } + /** + * Common method for better solution check. + * @param serverIndexToLocation serverIndexToHostIndex or serverIndexToRackIndex + * @param primariesOfRegionsPerLocation primariesOfRegionsPerHost or primariesOfRegionsPerRack + * @return 1 for better, -1 for no better, 0 for unknown + */ + private int checkLocationForPrimary(int[] serverIndexToLocation, + ArrayList<HashMap<Integer, ArrayList<Integer>>> primariesOfRegionsPerLocation, Review comment: s/ArrayList/List/ ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -878,4 +820,30 @@ private double getSkewChangeFor(int serverIndex, int tableIndex, int regionCount regionCountChange - meanRegionsPerTable[tableIndex]); return curSkew - oldSkew; } + + public static void addElement(HashMap<Integer, ArrayList<Integer>> map, Integer key, Review comment: s/Map/HashMap/... ditto for ArrayList. ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -818,20 +757,19 @@ int getLowestLocalityRegionOnServer(int serverIndex) { } if (locality < lowestLocality) { lowestLocality = locality; - lowestLocalityRegionIndex = j; + lowestLocalityRegionIndex = regionIndex; } } - if (lowestLocalityRegionIndex == -1) { + if (lowestLocality == 1.0f) { return -1; } if (LOG.isTraceEnabled()) { - LOG.trace("Lowest locality region is " + - regions[regionsPerServer[serverIndex][lowestLocalityRegionIndex]] + LOG.trace("Lowest locality region is " + regions[lowestLocalityRegionIndex] Review comment: Do parameterized logging? ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -803,12 +743,11 @@ int getLowestLocalityRegionOnServer(int serverIndex) { if (regionFinder != null) { float lowestLocality = 1.0f; int lowestLocalityRegionIndex = -1; - if (regionsPerServer[serverIndex].length == 0) { + if (regionsPerServer.get(serverIndex).size() == 0) { Review comment: s/size() == 0/isEmpty()/ ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -878,4 +820,30 @@ private double getSkewChangeFor(int serverIndex, int tableIndex, int regionCount regionCountChange - meanRegionsPerTable[tableIndex]); return curSkew - oldSkew; } + + public static void addElement(HashMap<Integer, ArrayList<Integer>> map, Integer key, + Integer value) { + if (map == null) { + LOG.warn("add element to null"); + return; + } + ArrayList list = map.get(key); + if(list == null) { Review comment: Space after if. ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -341,66 +340,45 @@ public String getRack(ServerName server) { } } - for (int i = 0; i < regionsPerServer.length; i++) { - primariesOfRegionsPerServer[i] = new int[regionsPerServer[i].length]; - for (int j = 0; j < regionsPerServer[i].length; j++) { - int primaryIndex = regionIndexToPrimaryIndex[regionsPerServer[i][j]]; - primariesOfRegionsPerServer[i][j] = primaryIndex; + for (int i = 0; i < regionsPerServer.size(); i++) { + for (Integer region : regionsPerServer.get(i)) { + addElement(primariesOfRegionsPerServer.get(i), regionIndexToPrimaryIndex[region], region); } - // sort the regions by primaries. - Arrays.sort(primariesOfRegionsPerServer[i]); } // compute regionsPerHost if (multiServersPerHost) { - for (int i = 0; i < serversPerHost.length; i++) { - int numRegionsPerHost = 0; - for (int j = 0; j < serversPerHost[i].length; j++) { - numRegionsPerHost += regionsPerServer[serversPerHost[i][j]].length; - } - regionsPerHost[i] = new int[numRegionsPerHost]; - primariesOfRegionsPerHost[i] = new int[numRegionsPerHost]; - } - for (int i = 0; i < serversPerHost.length; i++) { - int numRegionPerHostIndex = 0; - for (int j = 0; j < serversPerHost[i].length; j++) { - for (int k = 0; k < regionsPerServer[serversPerHost[i][j]].length; k++) { - int region = regionsPerServer[serversPerHost[i][j]][k]; - regionsPerHost[i][numRegionPerHostIndex] = region; - int primaryIndex = regionIndexToPrimaryIndex[region]; - primariesOfRegionsPerHost[i][numRegionPerHostIndex] = primaryIndex; - numRegionPerHostIndex++; - } - } - // sort the regions by primaries. - Arrays.sort(primariesOfRegionsPerHost[i]); - } + populateRegionPerLocationFromServer(regionsPerHost, primariesOfRegionsPerHost, + serversPerHost); } // compute regionsPerRack if (numRacks > 1) { - for (int i = 0; i < serversPerRack.length; i++) { - int numRegionsPerRack = 0; - for (int j = 0; j < serversPerRack[i].length; j++) { - numRegionsPerRack += regionsPerServer[serversPerRack[i][j]].length; - } - regionsPerRack[i] = new int[numRegionsPerRack]; - primariesOfRegionsPerRack[i] = new int[numRegionsPerRack]; - } + populateRegionPerLocationFromServer(regionsPerRack, primariesOfRegionsPerRack, + serversPerRack); + } + } - for (int i = 0; i < serversPerRack.length; i++) { - int numRegionPerRackIndex = 0; - for (int j = 0; j < serversPerRack[i].length; j++) { - for (int k = 0; k < regionsPerServer[serversPerRack[i][j]].length; k++) { - int region = regionsPerServer[serversPerRack[i][j]][k]; - regionsPerRack[i][numRegionPerRackIndex] = region; - int primaryIndex = regionIndexToPrimaryIndex[region]; - primariesOfRegionsPerRack[i][numRegionPerRackIndex] = primaryIndex; - numRegionPerRackIndex++; - } + private void populateRegionPerLocationFromServer(ArrayList<HashSet<Integer>> regionsPerLocation, Review comment: s/List/ArrayList/ ? ########## File path: hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java ########## @@ -878,4 +820,30 @@ private double getSkewChangeFor(int serverIndex, int tableIndex, int regionCount regionCountChange - meanRegionsPerTable[tableIndex]); return curSkew - oldSkew; } + + public static void addElement(HashMap<Integer, ArrayList<Integer>> map, Integer key, + Integer value) { + if (map == null) { + LOG.warn("add element to null"); + return; + } + ArrayList list = map.get(key); + if(list == null) { + list = new ArrayList(); + map.put(key, list); + } + list.add(value); + } + + public static void removeElement(HashMap<Integer, ArrayList<Integer>> map, + Integer key, Integer value) { + if (map == null) { + LOG.warn("remove element from null"); + return; + } + ArrayList list = map.get(key); + if(list != null) { Review comment: space after if. -- 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. To unsubscribe, e-mail: issues-unsubscr...@hbase.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org