Repository: hbase
Updated Branches:
  refs/heads/branch-1 0cbb19201 -> 1911461a5
  refs/heads/branch-1.4 26aeb80b3 -> 649ee45c7


HBASE-19937 Ensure createRSGroupTable be called after ProcedureExecutor and 
LoadBalancer are initialized

Signed-off-by: tedyu <yuzhih...@gmail.com>
Amending-Author: Andrew Purtell <apurt...@apache.org>

Conflicts:
        
hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java
        
hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1911461a
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1911461a
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1911461a

Branch: refs/heads/branch-1
Commit: 1911461a56ba482dce38c4f18d783a749454ae36
Parents: 0cbb192
Author: haxiaolin <haxiao...@xiaomi.com>
Authored: Fri Feb 9 10:58:39 2018 +0800
Committer: Andrew Purtell <apurt...@apache.org>
Committed: Fri Feb 9 15:14:56 2018 -0800

----------------------------------------------------------------------
 .../hbase/rsgroup/RSGroupBasedLoadBalancer.java |  6 ++
 .../hbase/rsgroup/RSGroupInfoManager.java       |  2 +
 .../hbase/rsgroup/RSGroupInfoManagerImpl.java   |  6 +-
 .../hadoop/hbase/rsgroup/TestEnableRSGroup.java | 98 ++++++++++++++++++++
 4 files changed, 111 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1911461a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java
----------------------------------------------------------------------
diff --git 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java
 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java
index 0994ba0..529a7e6 100644
--- 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java
+++ 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupBasedLoadBalancer.java
@@ -387,6 +387,12 @@ public class RSGroupBasedLoadBalancer implements 
RSGroupableBalancer, LoadBalanc
           throw new HBaseIOException(msg);
         }
         infoManager = cps.get(0).getGroupInfoManager();
+        if(infoManager == null){
+          String msg = "RSGroupInfoManager hasn't been initialized";
+          LOG.error(msg);
+          throw new HBaseIOException(msg);
+        }
+        infoManager.start();
       }
     } catch (IOException e) {
       throw new HBaseIOException("Failed to initialize GroupInfoManagerImpl", 
e);

http://git-wip-us.apache.org/repos/asf/hbase/blob/1911461a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java
----------------------------------------------------------------------
diff --git 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java
 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java
index d849699..e50412c 100644
--- 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java
+++ 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java
@@ -48,6 +48,8 @@ public interface RSGroupInfoManager {
   byte[] META_QUALIFIER_BYTES = Bytes.toBytes("i");
   byte[] ROW_KEY = {0};
 
+  void start();
+
   /**
    * Add given RSGroupInfo to existing list of group infos.
    */

http://git-wip-us.apache.org/repos/asf/hbase/blob/1911461a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
index e4401c0..caa7fc6 100644
--- 
a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
+++ 
b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java
@@ -137,7 +137,6 @@ public class RSGroupInfoManagerImpl implements 
RSGroupInfoManager, ServerListene
   public void init() throws IOException{
     rsGroupStartupWorker = new RSGroupStartupWorker(this, master, conn);
     refresh();
-    rsGroupStartupWorker.start();
     defaultServerUpdater = new DefaultServerUpdater(this);
     Threads.setDaemonThreadRunning(defaultServerUpdater);
     failedOpenUpdater = new FailedOpenUpdater(this);
@@ -150,6 +149,11 @@ public class RSGroupInfoManagerImpl implements 
RSGroupInfoManager, ServerListene
     return isInit;
   }
 
+  public void start(){
+    // create system table of rsgroup
+    rsGroupStartupWorker.start();
+  }
+
   /**
    * Adds the group.
    *

http://git-wip-us.apache.org/repos/asf/hbase/blob/1911461a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestEnableRSGroup.java
----------------------------------------------------------------------
diff --git 
a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestEnableRSGroup.java
 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestEnableRSGroup.java
new file mode 100644
index 0000000..45dc5d3
--- /dev/null
+++ 
b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestEnableRSGroup.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.rsgroup;
+
+import java.io.IOException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.Waiter;
+import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
+import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test enable RSGroup
+ */
+@Category({ MediumTests.class })
+public class TestEnableRSGroup {
+
+  protected static final Logger LOG = 
LoggerFactory.getLogger(TestEnableRSGroup.class);
+
+  private static final HBaseTestingUtility TEST_UTIL = new 
HBaseTestingUtility();
+  private static Configuration conf = TEST_UTIL.getConfiguration();
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    TEST_UTIL.startMiniCluster();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  @Test
+  public void testEnableRSGroup() throws IOException, InterruptedException {
+    TEST_UTIL.getMiniHBaseCluster().stopMaster(0);
+    LOG.info("stopped master...");
+    conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, 
RSGroupAdminEndpoint.class.getName());
+    conf.set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, 
RSGroupBasedLoadBalancer.class.getName());
+    TEST_UTIL.getMiniHBaseCluster().setConf(conf);
+
+    TEST_UTIL.getMiniHBaseCluster().startMaster();
+    TEST_UTIL.getMiniHBaseCluster().waitForActiveAndReadyMaster(60000);
+    LOG.info("started master...");
+
+    // check if master started successfully
+    Waiter.waitFor(TEST_UTIL.getConfiguration(), 60000, new 
ExplainingPredicate<IOException>() {
+      @Override
+      public boolean evaluate() throws IOException {
+        return TEST_UTIL.getMiniHBaseCluster().getMaster() != null;
+      }
+
+      @Override
+      public String explainFailure() throws IOException {
+        return "Master failed to start up";
+      }
+    });
+
+    // wait RSGroupBasedLoadBalancer online
+    Waiter.waitFor(TEST_UTIL.getConfiguration(), 60000, new 
ExplainingPredicate<IOException>() {
+      @Override
+      public boolean evaluate() throws IOException {
+        RSGroupBasedLoadBalancer loadBalancer =
+            (RSGroupBasedLoadBalancer) 
TEST_UTIL.getMiniHBaseCluster().getMaster().getLoadBalancer();
+        return loadBalancer != null && loadBalancer.isOnline();
+      }
+
+      @Override
+      public String explainFailure() throws IOException {
+        return "RSGroupBasedLoadBalancer failed to come online";
+      }
+    });
+  }
+
+}

Reply via email to