Skip to content

Commit

Permalink
HBASE-25662 Fix spotbugs warning in RoundRobinTableInputFormat (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
Apache9 authored and saintstack committed Mar 15, 2021
1 parent 7f236bc commit bd804c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
Expand Down Expand Up @@ -88,11 +88,11 @@ List<InputSplit> roundRobin(List<InputSplit> inputs) throws IOException {
List<InputSplit> result = new ArrayList<>(inputs.size());
// Prepare a hashmap with each region server as key and list of Input Splits as value
Map<String, List<InputSplit>> regionServerSplits = new HashMap<>();
for (InputSplit is: inputs) {
for (InputSplit is : inputs) {
if (is instanceof TableSplit) {
String regionServer = ((TableSplit)is).getRegionLocation();
if (regionServer != null && !regionServer.isEmpty()) {
regionServerSplits.computeIfAbsent(regionServer, k -> new LinkedList<>()).add(is);
String regionServer = ((TableSplit) is).getRegionLocation();
if (regionServer != null && !StringUtils.isBlank(regionServer)) {
regionServerSplits.computeIfAbsent(regionServer, k -> new ArrayList<>()).add(is);
continue;
}
}
Expand All @@ -101,15 +101,14 @@ List<InputSplit> roundRobin(List<InputSplit> inputs) throws IOException {
}
// Write out splits in a manner that spreads splits for a RegionServer to avoid 'clumping'.
while (!regionServerSplits.isEmpty()) {
Iterator<String> iterator = regionServerSplits.keySet().iterator();
while (iterator.hasNext()) {
String regionServer = iterator.next();
List<InputSplit> inputSplitListForRegion = regionServerSplits.get(regionServer);
Iterator<List<InputSplit>> iter = regionServerSplits.values().iterator();
while (iter.hasNext()) {
List<InputSplit> inputSplitListForRegion = iter.next();
if (!inputSplitListForRegion.isEmpty()) {
result.add(inputSplitListForRegion.remove(0));
}
if (inputSplitListForRegion.isEmpty()) {
iterator.remove();
iter.remove();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,32 @@ public void testToString() {
new TableSplit(TableName.valueOf(name.getMethodName()), "row-start".getBytes(), "row-end".getBytes(),
"location");
String str =
"HBase table split(table name: " + name.getMethodName() + ", scan: , start row: row-start, "
+ "end row: row-end, region location: location, "
+ "encoded region name: )";
"Split(tablename=" + name.getMethodName() + ", startrow=row-start, "
+ "endrow=row-end, regionLocation=location, "
+ "regionname=)";
Assert.assertEquals(str, split.toString());

split =
new TableSplit(TableName.valueOf(name.getMethodName()), null, "row-start".getBytes(),
"row-end".getBytes(), "location", "encoded-region-name", 1000L);
str =
"HBase table split(table name: " + name.getMethodName() + ", scan: , start row: row-start, "
+ "end row: row-end, region location: location, "
+ "encoded region name: encoded-region-name)";
"Split(tablename=" + name.getMethodName() + ", startrow=row-start, "
+ "endrow=row-end, regionLocation=location, "
+ "regionname=encoded-region-name)";
Assert.assertEquals(str, split.toString());

split = new TableSplit(null, null, null, null);
str =
"HBase table split(table name: null, scan: , start row: null, "
+ "end row: null, region location: null, "
+ "encoded region name: )";
"Split(tablename=null, startrow=null, "
+ "endrow=null, regionLocation=null, "
+ "regionname=)";
Assert.assertEquals(str, split.toString());

split = new TableSplit(null, null, null, null, null, null, 1000L);
str =
"HBase table split(table name: null, scan: , start row: null, "
+ "end row: null, region location: null, "
+ "encoded region name: null)";
"Split(tablename=null, startrow=null, "
+ "endrow=null, regionLocation=null, "
+ "regionname=null)";
Assert.assertEquals(str, split.toString());
}
}

0 comments on commit bd804c4

Please sign in to comment.