junegunn commented on code in PR #7174:
URL: https://github.com/apache/hbase/pull/7174#discussion_r2234187666


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java:
##########
@@ -460,13 +460,15 @@ static void rollingSplit(TableName tableName, 
SplitAlgorithm splitAlgo, Configur
                 }
               }
 
+              // 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);

Review Comment:
   > Is it possible to not use LinkedList here?
   
   On the surface, the original author seemed to have chosen `LinkedList` to 
use `pop()` method to remove an element from the beginning of the list.
   
   
https://github.com/apache/hbase/blob/32b1829d53d2db66c577e85428a108f3c6e3c601/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java#L476
   
   It's probably possible to rewrite the logic to not rely on it, but as it 
would require some code changes, I think it deserves a separate issue if we 
really want to do it.
   
   Speaking of which, another non-conventional choice in this class is the use 
of `TreeMap`. This can be trivially replaced with a `HashMap` without affecting 
the behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to