Skip to content

Commit 8337fb2

Browse files
authored
HBASE-25662 Fix spotbugs warning in RoundRobinTableInputFormat (#3050)
1 parent aeec8ca commit 8337fb2

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/RoundRobinTableInputFormat.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22-
import java.util.Iterator;
23-
import java.util.LinkedList;
24-
import java.util.Map;
2522
import java.util.HashMap;
23+
import java.util.Iterator;
2624
import java.util.List;
25+
import java.util.Map;
26+
import org.apache.commons.lang3.StringUtils;
2727
import org.apache.hadoop.conf.Configuration;
2828
import org.apache.hadoop.hbase.HBaseConfiguration;
2929
import org.apache.hadoop.hbase.HConstants;
@@ -88,11 +88,11 @@ List<InputSplit> roundRobin(List<InputSplit> inputs) throws IOException {
8888
List<InputSplit> result = new ArrayList<>(inputs.size());
8989
// Prepare a hashmap with each region server as key and list of Input Splits as value
9090
Map<String, List<InputSplit>> regionServerSplits = new HashMap<>();
91-
for (InputSplit is: inputs) {
91+
for (InputSplit is : inputs) {
9292
if (is instanceof TableSplit) {
93-
String regionServer = ((TableSplit)is).getRegionLocation();
94-
if (regionServer != null && !regionServer.isEmpty()) {
95-
regionServerSplits.computeIfAbsent(regionServer, k -> new LinkedList<>()).add(is);
93+
String regionServer = ((TableSplit) is).getRegionLocation();
94+
if (regionServer != null && !StringUtils.isBlank(regionServer)) {
95+
regionServerSplits.computeIfAbsent(regionServer, k -> new ArrayList<>()).add(is);
9696
continue;
9797
}
9898
}
@@ -101,15 +101,14 @@ List<InputSplit> roundRobin(List<InputSplit> inputs) throws IOException {
101101
}
102102
// Write out splits in a manner that spreads splits for a RegionServer to avoid 'clumping'.
103103
while (!regionServerSplits.isEmpty()) {
104-
Iterator<String> iterator = regionServerSplits.keySet().iterator();
105-
while (iterator.hasNext()) {
106-
String regionServer = iterator.next();
107-
List<InputSplit> inputSplitListForRegion = regionServerSplits.get(regionServer);
104+
Iterator<List<InputSplit>> iter = regionServerSplits.values().iterator();
105+
while (iter.hasNext()) {
106+
List<InputSplit> inputSplitListForRegion = iter.next();
108107
if (!inputSplitListForRegion.isEmpty()) {
109108
result.add(inputSplitListForRegion.remove(0));
110109
}
111110
if (inputSplitListForRegion.isEmpty()) {
112-
iterator.remove();
111+
iter.remove();
113112
}
114113
}
115114
}

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableSplit.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,32 +103,32 @@ public void testToString() {
103103
new TableSplit(TableName.valueOf(name.getMethodName()), Bytes.toBytes("row-start"),
104104
Bytes.toBytes("row-end"), "location");
105105
String str =
106-
"HBase table split(table name: " + name.getMethodName() + ", scan: , start row: row-start, "
107-
+ "end row: row-end, region location: location, "
108-
+ "encoded region name: )";
106+
"Split(tablename=" + name.getMethodName() + ", startrow=row-start, "
107+
+ "endrow=row-end, regionLocation=location, "
108+
+ "regionname=)";
109109
Assert.assertEquals(str, split.toString());
110110

111111
split =
112112
new TableSplit(TableName.valueOf(name.getMethodName()), null, Bytes.toBytes("row-start"),
113113
Bytes.toBytes("row-end"), "location", "encoded-region-name", 1000L);
114114
str =
115-
"HBase table split(table name: " + name.getMethodName() + ", scan: , start row: row-start, "
116-
+ "end row: row-end, region location: location, "
117-
+ "encoded region name: encoded-region-name)";
115+
"Split(tablename=" + name.getMethodName() + ", startrow=row-start, "
116+
+ "endrow=row-end, regionLocation=location, "
117+
+ "regionname=encoded-region-name)";
118118
Assert.assertEquals(str, split.toString());
119119

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

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

0 commit comments

Comments
 (0)