From b7902c3459450bcd80bf1ab8259c7e4c5818d135 Mon Sep 17 00:00:00 2001 From: Lars Francke Date: Mon, 19 Jan 2026 13:19:38 +0100 Subject: [PATCH 1/2] HBASE-29835: Fix typos and inconsistencies in CacheAwareLoadBalancer --- .../master/balancer/CacheAwareLoadBalancer.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java index 30e4b5212bfb..d84302373e44 100644 --- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java +++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java @@ -23,7 +23,7 @@ * periodically and restores the cache when it is restarted. This balancer implements a mechanism * where it maintains the amount by which a region is cached on a region server. During balancer * run, a region plan is generated that takes into account this cache information and tries to - * move the regions so that the cache minimally impacted. + * move the regions so that the cache is minimally impacted. */ import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_PERSISTENT_PATH_KEY; @@ -130,7 +130,7 @@ private void updateRegionLoad() { int regionSizeMB = (int) rm.getRegionSizeMB().get(Size.Unit.MEGABYTE); rload.add(new BalancerRegionLoad(rm)); - // Maintain a map of region and it's total size. This is needed to calculate the cache + // Maintain a map of region and its total size. This is needed to calculate the cache // ratios for the regions cached on old region servers regionCacheRatioOnCurrentServerMap.put(regionEncodedName, new Pair<>(sn, regionSizeMB)); loads.put(regionEncodedName, rload); @@ -285,9 +285,6 @@ private boolean moveRegionToOldServer(BalancerClusterState cluster, int regionIn return false; } - DecimalFormat df = new DecimalFormat("#"); - df.setMaximumFractionDigits(4); - float cacheRatioDiffThreshold = 0.6f; // Conditions for moving the region @@ -307,7 +304,7 @@ private boolean moveRegionToOldServer(BalancerClusterState cluster, int regionIn LOG.debug( "Region {} moved from {} to {} as the region is cached {} equally on both servers", cluster.regions[regionIndex].getEncodedName(), cluster.servers[currentServerIndex], - cluster.servers[oldServerIndex], df.format(cacheRatioOnCurrentServer)); + cluster.servers[oldServerIndex], cacheRatioOnCurrentServer); } return true; } @@ -324,8 +321,7 @@ private boolean moveRegionToOldServer(BalancerClusterState cluster, int regionIn "Region {} moved from {} to {} as region cache ratio {} is better than the current " + "cache ratio {}", cluster.regions[regionIndex].getEncodedName(), cluster.servers[currentServerIndex], - cluster.servers[oldServerIndex], cacheRatioOnCurrentServer, - df.format(cacheRatioOnCurrentServer)); + cluster.servers[oldServerIndex], cacheRatioOnOldServer, cacheRatioOnCurrentServer); } return true; } @@ -334,8 +330,7 @@ private boolean moveRegionToOldServer(BalancerClusterState cluster, int regionIn LOG.debug( "Region {} not moved from {} to {} with current cache ratio {} and old cache ratio {}", cluster.regions[regionIndex], cluster.servers[currentServerIndex], - cluster.servers[oldServerIndex], cacheRatioOnCurrentServer, - df.format(cacheRatioOnCurrentServer)); + cluster.servers[oldServerIndex], cacheRatioOnCurrentServer, cacheRatioOnOldServer); } return false; } @@ -391,7 +386,7 @@ BalanceAction pickRandomRegions(BalancerClusterState cluster, int thisServer, in if (LOG.isDebugEnabled()) { LOG.debug( "CacheAwareSkewnessCandidateGenerator: Region {} moved from {} to {} as it " - + "was hosted their earlier", + + "was hosted there earlier", regionEncodedName, cluster.servers[thisServer].getHostname(), cluster.servers[otherServer].getHostname()); } From 34bf2912d3aa30f89816c1f1b3ff9a9965cb2c0e Mon Sep 17 00:00:00 2001 From: Lars Francke Date: Mon, 19 Jan 2026 14:02:35 +0100 Subject: [PATCH 2/2] Remove unused import --- .../hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java index d84302373e44..867c6f8aadb2 100644 --- a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java +++ b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/CacheAwareLoadBalancer.java @@ -28,7 +28,6 @@ import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_PERSISTENT_PATH_KEY; -import java.text.DecimalFormat; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays;