This is an automated email from the ASF dual-hosted git repository.

junegunn pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new b3feffa1312 HBASE-29474 RegionSplitter.rollingSplit is broken (#7174)
b3feffa1312 is described below

commit b3feffa1312dbf701e33a2452dfd7449346aaccb
Author: Junegunn Choi <[email protected]>
AuthorDate: Mon Jul 28 22:34:45 2025 +0900

    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 5e91b45b166cd5a68457234f0a62ca1c2b5d9211.
    
    Signed-off-by: Duo Zhang <[email protected]>
---
 .../java/org/apache/hadoop/hbase/util/RegionSplitter.java    | 12 +++++++-----
 .../org/apache/hadoop/hbase/util/TestRegionSplitter.java     |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
index ef63985a2d2..5feee61bee0 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java
@@ -21,9 +21,9 @@ import java.io.IOException;
 import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import org.apache.commons.lang3.ArrayUtils;
@@ -459,13 +459,15 @@ public class RegionSplitter {
                 }
               }
 
+              // Sort the ServerNames by the number of regions they have
+              final List<ServerName> serversLeft = 
Lists.newArrayList(daughterRegions.keySet());
+              serversLeft.sort(Comparator.comparing(rsSizes::get));
+
               // Round-robin through the ServerName list. Choose the 
lightest-loaded servers
               // first to keep the master from load-balancing regions as we 
split.
-              for (Map.Entry<ServerName,
-                LinkedList<Pair<byte[], byte[]>>> daughterRegion : 
daughterRegions.entrySet()) {
+              for (final ServerName rsLoc : serversLeft) {
                 Pair<byte[], byte[]> dr = null;
-                ServerName rsLoc = daughterRegion.getKey();
-                LinkedList<Pair<byte[], byte[]>> regionList = 
daughterRegion.getValue();
+                final LinkedList<Pair<byte[], byte[]>> regionList = 
daughterRegions.get(rsLoc);
 
                 // Find a region in the ServerName list that hasn't been moved
                 LOG.debug("Finding a region on " + rsLoc);
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
index c97cbd02fba..d45d95732b8 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java
@@ -72,7 +72,7 @@ public class TestRegionSplitter {
 
   @BeforeClass
   public static void setup() throws Exception {
-    UTIL.startMiniCluster();
+    UTIL.startMiniCluster(2);
   }
 
   @AfterClass

Reply via email to