diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java index 08e529cd01a..1675e049d77 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java @@ -257,16 +257,13 @@ class SimpleRegionNormalizer implements RegionNormalizer, ConfigurationObserver throw new IllegalStateException( "Cannot calculate average size of a table without any regions."); } - final int regionCount = tableRegions.size(); - final long totalSizeMb = tableRegions.stream() - .mapToLong(this::getRegionSizeMB) - .sum(); TableName table = tableRegions.get(0).getTable(); int targetRegionCount = -1; long targetRegionSize = -1; + double avgRegionSize; try { TableDescriptor tableDescriptor = masterServices.getTableDescriptors().get(table); - if (tableDescriptor != null && LOG.isDebugEnabled()) { + if (tableDescriptor != null) { targetRegionCount = tableDescriptor.getNormalizerTargetRegionCount(); targetRegionSize = tableDescriptor.getNormalizerTargetRegionSize(); LOG.debug("Table {} configured with target region count {}, target region size {}", table, @@ -276,18 +273,22 @@ class SimpleRegionNormalizer implements RegionNormalizer, ConfigurationObserver LOG.warn("TableDescriptor for {} unavailable, table-level target region count and size" + " configurations cannot be considered.", table, e); } - - double avgRegionSize; if (targetRegionSize > 0) { avgRegionSize = targetRegionSize; - } else if (targetRegionCount > 0) { - avgRegionSize = totalSizeMb / (double) targetRegionCount; } else { - avgRegionSize = totalSizeMb / (double) regionCount; + final int regionCount = tableRegions.size(); + final long totalSizeMb = tableRegions.stream() + .mapToLong(this::getRegionSizeMB) + .sum(); + if (targetRegionCount > 0) { + avgRegionSize = totalSizeMb / (double) targetRegionCount; + } else { + avgRegionSize = totalSizeMb / (double) regionCount; + } + LOG.debug("Table {}, total aggregated regions size: {} and average region size {}", table, + totalSizeMb, avgRegionSize); } - LOG.debug("Table {}, total aggregated regions size: {} and average region size {}", table, - totalSizeMb, avgRegionSize); return avgRegionSize; }