ndimiduk commented on code in PR #7035:
URL: https://github.com/apache/hbase/pull/7035#discussion_r2121153914


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java:
##########
@@ -322,14 +322,27 @@ private double getAverageRegionSizeMb(final 
List<RegionInfo> tableRegions,
       avgRegionSize = targetRegionSize;
     } else {
       final int regionCount = tableRegions.size();
-      final long totalSizeMb = 
tableRegions.stream().mapToLong(this::getRegionSizeMB).sum();
+      // Count of regions whose size is known
+      int regionCountKnownSize = 0;
+      long totalSizeMb = 0;
+      for (RegionInfo regionInfo : tableRegions) {
+        long regionSize = getRegionSizeMB(regionInfo);
+        if (regionSize != -1) {
+          totalSizeMb += regionSize;
+          regionCountKnownSize++;
+        }
+      }
       if (targetRegionCount > 0) {
-        avgRegionSize = totalSizeMb / (double) targetRegionCount;
+        avgRegionSize =
+          totalSizeMb / (double) targetRegionCount - (regionCount - 
regionCountKnownSize);
       } else {
-        avgRegionSize = totalSizeMb / (double) regionCount;
+        avgRegionSize = totalSizeMb / (double) regionCountKnownSize;

Review Comment:
   I think that you also need to protect against a 0 value here, in the same 
way.



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java:
##########
@@ -322,14 +322,27 @@ private double getAverageRegionSizeMb(final 
List<RegionInfo> tableRegions,
       avgRegionSize = targetRegionSize;
     } else {
       final int regionCount = tableRegions.size();
-      final long totalSizeMb = 
tableRegions.stream().mapToLong(this::getRegionSizeMB).sum();
+      // Count of regions whose size is known
+      int regionCountKnownSize = 0;
+      long totalSizeMb = 0;
+      for (RegionInfo regionInfo : tableRegions) {
+        long regionSize = getRegionSizeMB(regionInfo);
+        if (regionSize != -1) {
+          totalSizeMb += regionSize;
+          regionCountKnownSize++;
+        }
+      }
       if (targetRegionCount > 0) {
-        avgRegionSize = totalSizeMb / (double) targetRegionCount;
+        avgRegionSize =
+          totalSizeMb / (double) targetRegionCount - (regionCount - 
regionCountKnownSize);

Review Comment:
   If you're going to adjust the denominator here, I think that you also need 
to protect against a value <= 0. In that case, you can throw, like we do on 
entry into the method.



-- 
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: issues-unsubscr...@hbase.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to