Skip to content

Commit dbdef59

Browse files
authored
HBASE-26609 Round the size to MB or KB at the end of calculation in HRegionServer.createRegionLoad (#3967)
Signed-off-by: Peter Somogyi <psomogyi@apache.org>
1 parent bf258cd commit dbdef59

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,20 @@ public RegionServerAccounting getRegionServerAccounting() {
14181418
return regionServerAccounting;
14191419
}
14201420

1421+
// Round the size with KB or MB.
1422+
// A trick here is that if the sizeInBytes is less than sizeUnit, we will round the size to 1
1423+
// instead of 0 if it is not 0, to avoid some schedulers think the region has no data. See
1424+
// HBASE-26340 for more details on why this is important.
1425+
private static int roundSize(long sizeInByte, int sizeUnit) {
1426+
if (sizeInByte == 0) {
1427+
return 0;
1428+
} else if (sizeInByte < sizeUnit) {
1429+
return 1;
1430+
} else {
1431+
return (int) Math.min(sizeInByte / sizeUnit, Integer.MAX_VALUE);
1432+
}
1433+
}
1434+
14211435
/**
14221436
* @param r Region to get RegionLoad for.
14231437
* @param regionLoadBldr the RegionLoad.Builder, can be null
@@ -1431,16 +1445,14 @@ RegionLoad createRegionLoad(final HRegion r, RegionLoad.Builder regionLoadBldr,
14311445
int storefiles = 0;
14321446
int storeRefCount = 0;
14331447
int maxCompactedStoreFileRefCount = 0;
1434-
int storeUncompressedSizeMB = 0;
1435-
int storefileSizeMB = 0;
1436-
long storefileSizeByte = 0L;
1437-
int memstoreSizeMB = (int) (r.getMemStoreDataSize() / 1024 / 1024);
1438-
long storefileIndexSizeKB = 0;
1439-
int rootLevelIndexSizeKB = 0;
1440-
int totalStaticIndexSizeKB = 0;
1441-
int totalStaticBloomSizeKB = 0;
1442-
long totalCompactingKVs = 0;
1443-
long currentCompactedKVs = 0;
1448+
long storeUncompressedSize = 0L;
1449+
long storefileSize = 0L;
1450+
long storefileIndexSize = 0L;
1451+
long rootLevelIndexSize = 0L;
1452+
long totalStaticIndexSize = 0L;
1453+
long totalStaticBloomSize = 0L;
1454+
long totalCompactingKVs = 0L;
1455+
long currentCompactedKVs = 0L;
14441456
List<HStore> storeList = r.getStores();
14451457
stores += storeList.size();
14461458
for (HStore store : storeList) {
@@ -1450,22 +1462,30 @@ RegionLoad createRegionLoad(final HRegion r, RegionLoad.Builder regionLoadBldr,
14501462
int currentMaxCompactedStoreFileRefCount = store.getMaxCompactedStoreFileRefCount();
14511463
maxCompactedStoreFileRefCount = Math.max(maxCompactedStoreFileRefCount,
14521464
currentMaxCompactedStoreFileRefCount);
1453-
storeUncompressedSizeMB += (int) (store.getStoreSizeUncompressed() / 1024 / 1024);
1454-
storefileSizeByte += store.getStorefilesSize();
1465+
storeUncompressedSize += store.getStoreSizeUncompressed();
1466+
storefileSize += store.getStorefilesSize();
14551467
//TODO: storefileIndexSizeKB is same with rootLevelIndexSizeKB?
1456-
storefileIndexSizeKB += store.getStorefilesRootLevelIndexSize() / 1024;
1468+
storefileIndexSize += store.getStorefilesRootLevelIndexSize();
14571469
CompactionProgress progress = store.getCompactionProgress();
14581470
if (progress != null) {
14591471
totalCompactingKVs += progress.getTotalCompactingKVs();
14601472
currentCompactedKVs += progress.currentCompactedKVs;
14611473
}
1462-
rootLevelIndexSizeKB += (int) (store.getStorefilesRootLevelIndexSize() / 1024);
1463-
totalStaticIndexSizeKB += (int) (store.getTotalStaticIndexSize() / 1024);
1464-
totalStaticBloomSizeKB += (int) (store.getTotalStaticBloomSize() / 1024);
1474+
rootLevelIndexSize += store.getStorefilesRootLevelIndexSize();
1475+
totalStaticIndexSize += store.getTotalStaticIndexSize();
1476+
totalStaticBloomSize += store.getTotalStaticBloomSize();
14651477
}
1466-
//HBASE-26340 Fix false "0" size under 1MB
1467-
storefileSizeMB = storefileSizeByte > 0 && storefileSizeByte <= 1024 * 1024
1468-
? 1 : (int) storefileSizeByte / 1024 / 1024;
1478+
1479+
int unitMB = 1024 * 1024;
1480+
int unitKB = 1024;
1481+
1482+
int memstoreSizeMB = roundSize(r.getMemStoreDataSize(), unitMB);
1483+
int storeUncompressedSizeMB = roundSize(storeUncompressedSize, unitMB);
1484+
int storefileSizeMB = roundSize(storefileSize, unitMB);
1485+
int storefileIndexSizeKB = roundSize(storefileIndexSize, unitKB);
1486+
int rootLevelIndexSizeKB = roundSize(rootLevelIndexSize, unitKB);
1487+
int totalStaticIndexSizeKB = roundSize(totalStaticIndexSize, unitKB);
1488+
int totalStaticBloomSizeKB = roundSize(totalStaticBloomSize, unitKB);
14691489

14701490
HDFSBlocksDistribution hdfsBd = r.getHDFSBlocksDistribution();
14711491
float dataLocality = hdfsBd.getBlockLocalityIndex(serverName.getHostname());
@@ -1479,6 +1499,7 @@ RegionLoad createRegionLoad(final HRegion r, RegionLoad.Builder regionLoadBldr,
14791499
if (regionSpecifier == null) {
14801500
regionSpecifier = RegionSpecifier.newBuilder();
14811501
}
1502+
14821503
regionSpecifier.setType(RegionSpecifierType.REGION_NAME);
14831504
regionSpecifier.setValue(UnsafeByteOperations.unsafeWrap(name));
14841505
regionLoadBldr.setRegionSpecifier(regionSpecifier.build())

0 commit comments

Comments
 (0)