HBASE-25662 Fix spotbugs warning in RoundRobinTableInputFormat (#3050)
This commit is contained in:
parent
aeec8ca64b
commit
8337fb2a72
|
@ -19,11 +19,11 @@ package org.apache.hadoop.hbase.mapreduce;
|
|||
|
||||
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;
|
||||
|
@ -88,11 +88,11 @@ public class RoundRobinTableInputFormat extends TableInputFormat {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
@ -101,15 +101,14 @@ public class RoundRobinTableInputFormat extends TableInputFormat {
|
|||
}
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,32 +103,32 @@ public class TestTableSplit {
|
|||
new TableSplit(TableName.valueOf(name.getMethodName()), Bytes.toBytes("row-start"),
|
||||
Bytes.toBytes("row-end"), "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, Bytes.toBytes("row-start"),
|
||||
Bytes.toBytes("row-end"), "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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue