HBASE-25482 Improve SimpleRegionNormalizer#getAverageRegionSizeMb (#2858)

Signed-off-by: Nick Dimiduk <ndimiduk@apache.org>
This commit is contained in:
Baiqiang Zhao 2021-01-20 03:09:50 +08:00 committed by Nick Dimiduk
parent cc5b884a8d
commit 47fbff98e3
1 changed files with 13 additions and 12 deletions

View File

@ -257,16 +257,13 @@ class SimpleRegionNormalizer implements RegionNormalizer, ConfigurationObserver
throw new IllegalStateException( throw new IllegalStateException(
"Cannot calculate average size of a table without any regions."); "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(); TableName table = tableRegions.get(0).getTable();
int targetRegionCount = -1; int targetRegionCount = -1;
long targetRegionSize = -1; long targetRegionSize = -1;
double avgRegionSize;
try { try {
TableDescriptor tableDescriptor = masterServices.getTableDescriptors().get(table); TableDescriptor tableDescriptor = masterServices.getTableDescriptors().get(table);
if (tableDescriptor != null && LOG.isDebugEnabled()) { if (tableDescriptor != null) {
targetRegionCount = tableDescriptor.getNormalizerTargetRegionCount(); targetRegionCount = tableDescriptor.getNormalizerTargetRegionCount();
targetRegionSize = tableDescriptor.getNormalizerTargetRegionSize(); targetRegionSize = tableDescriptor.getNormalizerTargetRegionSize();
LOG.debug("Table {} configured with target region count {}, target region size {}", table, 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" LOG.warn("TableDescriptor for {} unavailable, table-level target region count and size"
+ " configurations cannot be considered.", table, e); + " configurations cannot be considered.", table, e);
} }
double avgRegionSize;
if (targetRegionSize > 0) { if (targetRegionSize > 0) {
avgRegionSize = targetRegionSize; avgRegionSize = targetRegionSize;
} else if (targetRegionCount > 0) {
avgRegionSize = totalSizeMb / (double) targetRegionCount;
} else { } 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; return avgRegionSize;
} }