You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by vj...@apache.org on 2020/06/11 12:59:41 UTC

[hbase] branch branch-2.2 updated: HBASE-24532 : Execute region plans with throttle should return succeeded plans (#1884)

This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.2 by this push:
     new b397282  HBASE-24532 : Execute region plans with throttle should return succeeded plans (#1884)
b397282 is described below

commit b3972826616d7e29cf381092a8850fb2e5f7a9c2
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Thu Jun 11 18:17:59 2020 +0530

    HBASE-24532 : Execute region plans with throttle should return succeeded plans (#1884)
    
    Signed-off-by: Wellington Chevreuil <wc...@apache.org>
---
 .../org/apache/hadoop/hbase/master/HMaster.java    | 10 ++-
 .../hbase/master/TestRegionPlansWithThrottle.java  | 98 ++++++++++++++++++++++
 2 files changed, 106 insertions(+), 2 deletions(-)

diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index b9b7076..e87560c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -1723,8 +1723,13 @@ public class HMaster extends HRegionServer implements MasterServices {
     return true;
   }
 
+  /**
+   * Execute region plans with throttling
+   * @param plans to execute
+   * @return succeeded plans
+   */
   public List<RegionPlan> executeRegionPlansWithThrottling(List<RegionPlan> plans) {
-    List<RegionPlan> sucRPs = new ArrayList<>();
+    List<RegionPlan> successRegionPlans = new ArrayList<>();
     int maxRegionsInTransition = getMaxRegionsInTransition();
     long balanceStartTime = System.currentTimeMillis();
     long cutoffTime = balanceStartTime + this.maxBlancingTime;
@@ -1747,6 +1752,7 @@ public class HMaster extends HRegionServer implements MasterServices {
         }
         //rpCount records balance plans processed, does not care if a plan succeeds
         rpCount++;
+        successRegionPlans.add(plan);
 
         if (this.maxBlancingTime > 0) {
           balanceThrottling(balanceStartTime + rpCount * balanceInterval, maxRegionsInTransition,
@@ -1764,7 +1770,7 @@ public class HMaster extends HRegionServer implements MasterServices {
         }
       }
     }
-    return sucRPs;
+    return successRegionPlans;
   }
 
   @Override
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlansWithThrottle.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlansWithThrottle.java
new file mode 100644
index 0000000..7108340
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlansWithThrottle.java
@@ -0,0 +1,98 @@
+/*
+ * 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.master;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.StartMiniClusterOption;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({ MiscTests.class, MediumTests.class})
+public class TestRegionPlansWithThrottle {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestRegionPlansWithThrottle.class);
+
+  private static HMaster hMaster;
+
+  private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    UTIL.startMiniCluster(StartMiniClusterOption.builder().numRegionServers(2).build());
+    hMaster = UTIL.getMiniHBaseCluster().getMaster();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    UTIL.shutdownMiniCluster();
+  }
+
+  @Test
+  public void testExecuteRegionPlansWithThrottling() throws Exception {
+    final TableName tableName = TableName.valueOf("testExecuteRegionPlansWithThrottling");
+
+    TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
+      new TableDescriptorBuilder.ModifyableTableDescriptor(tableName).setColumnFamily(
+        new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(Bytes.toBytes("cf")));
+
+    UTIL.getAdmin().createTable(tableDescriptor);
+    Table table = UTIL.getConnection().getTable(tableName);
+
+    List<Put> puts = new ArrayList<>();
+    for (int i = 0; i < 100; i++) {
+      Put put = new Put(Bytes.toBytes("row" + i));
+      byte[] q = Bytes.toBytes("q1");
+      byte[] v = Bytes.toBytes("v" + i);
+      put.addColumn(Bytes.toBytes("cf"), q, v);
+      puts.add(put);
+    }
+    table.put(puts);
+    UTIL.getAdmin().flush(tableName);
+    UTIL.getAdmin().split(tableName, Bytes.toBytes("v5"));
+
+    List<RegionPlan> plans = new ArrayList<>();
+    List<RegionInfo> regionInfos = UTIL.getAdmin().getRegions(tableName);
+    for (RegionInfo regionInfo : regionInfos) {
+      plans.add(
+        new RegionPlan(regionInfo, UTIL.getHBaseCluster().getRegionServer(0).getServerName(),
+          UTIL.getHBaseCluster().getRegionServer(1).getServerName()));
+    }
+    List<RegionPlan> successPlans = hMaster.executeRegionPlansWithThrottling(plans);
+    Assert.assertEquals(regionInfos.size(), successPlans.size());
+  }
+
+}