ndimiduk commented on a change in pull request #2490:
URL: https://github.com/apache/hbase/pull/2490#discussion_r502560699



##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java
##########
@@ -315,35 +317,61 @@ private boolean skipForMerge(final RegionStates 
regionStates, final RegionInfo r
    * towards target average or target region count.
    */
   private List<NormalizationPlan> computeMergeNormalizationPlans(final 
NormalizeContext ctx) {
-    if (ctx.getTableRegions().size() < minRegionCount) {
+    if (isEmpty(ctx.getTableRegions()) || ctx.getTableRegions().size() < 
minRegionCount) {
       LOG.debug("Table {} has {} regions, required min number of regions for 
normalizer to run"
         + " is {}, not computing merge plans.", ctx.getTableName(), 
ctx.getTableRegions().size(),
         minRegionCount);
       return Collections.emptyList();
     }
 
-    final double avgRegionSizeMb = ctx.getAverageRegionSizeMb();
+    final long avgRegionSizeMb = (long) ctx.getAverageRegionSizeMb();
+    if (avgRegionSizeMb < mergeMinRegionSizeMb) {
+      return Collections.emptyList();
+    }
     LOG.debug("Computing normalization plan for table {}. average region size: 
{}, number of"
       + " regions: {}.", ctx.getTableName(), avgRegionSizeMb, 
ctx.getTableRegions().size());
 
-    final List<NormalizationPlan> plans = new ArrayList<>();
-    for (int candidateIdx = 0; candidateIdx < ctx.getTableRegions().size() - 
1; candidateIdx++) {
-      final RegionInfo current = ctx.getTableRegions().get(candidateIdx);
-      final RegionInfo next = ctx.getTableRegions().get(candidateIdx + 1);
-      if (skipForMerge(ctx.getRegionStates(), current)
-        || skipForMerge(ctx.getRegionStates(), next)) {
-        continue;
+    // this nested loop walks the table's region chain once, looking for 
contiguous sequences of
+    // regions that meet the criteria for merge. The outer loop tracks the 
starting point of the
+    // next sequence, the inner loop looks for the end of that sequence. A 
single sequence becomes
+    // an instance of MergeNormalizationPlan.
+
+    final List<NormalizationPlan> plans = new LinkedList<>();
+    final List<NormalizationTarget> rangeMembers = new LinkedList<>();
+    long sumRangeMembersSizeMb;
+    int current = 0;
+    for (int rangeStart = 0;

Review comment:
       The meat of this patch is this new nested loop.

##########
File path: 
hbase-common/src/test/java/org/apache/hadoop/hbase/MatcherPredicate.java
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase;
+
+import java.util.function.Supplier;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.StringDescription;
+
+/**
+ * An implementation of {@link Waiter.ExplainingPredicate} that uses Hamcrest 
{@link Matcher} for both

Review comment:
       I realized all my waiting in tests (1) use conditions that are shipped 
in the hamcrest library (2) have failure messages that look like failed 
`Matcher` explanations.

##########
File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/master/normalizer/SimpleRegionNormalizer.java
##########
@@ -124,10 +126,10 @@ private static Period parseMergeMinRegionAge(final 
Configuration conf) {
     return Period.ofDays(settledValue);
   }
 
-  private static int parseMergeMinRegionSizeMb(final Configuration conf) {
-    final int parsedValue =
-      conf.getInt(MERGE_MIN_REGION_SIZE_MB_KEY, 
DEFAULT_MERGE_MIN_REGION_SIZE_MB);
-    final int settledValue = Math.max(0, parsedValue);
+  private static long parseMergeMinRegionSizeMb(final Configuration conf) {

Review comment:
       Upgraded this datatype to a `long` because this is the type returned by 
the region size info we get from AM.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to