Skip to content

Commit 8f5803d

Browse files
authored
HBASE-29474 RegionSplitter.rollingSplit is broken (#7174)
Avoid concurrent modification by iterating over a snapshot of the keys. Also, revive the sorting logic for the ServerName list, which was mistakenly removed in 5e91b45. Signed-off-by: Duo Zhang <[email protected]>
1 parent bdefd1e commit 8f5803d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import java.math.BigInteger;
2222
import java.util.Arrays;
2323
import java.util.Collection;
24+
import java.util.Comparator;
2425
import java.util.LinkedList;
2526
import java.util.List;
26-
import java.util.Map;
2727
import java.util.Set;
2828
import java.util.TreeMap;
2929
import org.apache.commons.lang3.ArrayUtils;
@@ -460,13 +460,15 @@ static void rollingSplit(TableName tableName, SplitAlgorithm splitAlgo, Configur
460460
}
461461
}
462462

463+
// Sort the ServerNames by the number of regions they have
464+
final List<ServerName> serversLeft = Lists.newArrayList(daughterRegions.keySet());
465+
serversLeft.sort(Comparator.comparing(rsSizes::get));
466+
463467
// Round-robin through the ServerName list. Choose the lightest-loaded servers
464468
// first to keep the master from load-balancing regions as we split.
465-
for (Map.Entry<ServerName,
466-
LinkedList<Pair<byte[], byte[]>>> daughterRegion : daughterRegions.entrySet()) {
469+
for (final ServerName rsLoc : serversLeft) {
467470
Pair<byte[], byte[]> dr = null;
468-
ServerName rsLoc = daughterRegion.getKey();
469-
LinkedList<Pair<byte[], byte[]>> regionList = daughterRegion.getValue();
471+
final LinkedList<Pair<byte[], byte[]>> regionList = daughterRegions.get(rsLoc);
470472

471473
// Find a region in the ServerName list that hasn't been moved
472474
LOG.debug("Finding a region on " + rsLoc);

hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class TestRegionSplitter {
7272

7373
@BeforeClass
7474
public static void setup() throws Exception {
75-
UTIL.startMiniCluster();
75+
UTIL.startMiniCluster(2);
7676
}
7777

7878
@AfterClass

0 commit comments

Comments
 (0)