Skip to content

Commit 3fb24a0

Browse files
Apache9saintstack
authored andcommitted
HBASE-25662 Fix spotbugs warning in RoundRobinTableInputFormat (#3050)
1 parent 2ecf923 commit 3fb24a0

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
@@ -102,32 +102,32 @@ public void testToString() {
102102
new TableSplit(TableName.valueOf(name.getMethodName()), "row-start".getBytes(), "row-end".getBytes(),
103103
"location");
104104
String str =
105-
"HBase table split(table name: " + name.getMethodName() + ", scan: , start row: row-start, "
106-
+ "end row: row-end, region location: location, "
107-
+ "encoded region name: )";
105+
"Split(tablename=" + name.getMethodName() + ", startrow=row-start, "
106+
+ "endrow=row-end, regionLocation=location, "
107+
+ "regionname=)";
108108
Assert.assertEquals(str, split.toString());
109109

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

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

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

0 commit comments

Comments
 (0)