Repository: hbase
Updated Branches:
  refs/heads/branch-1.0 19087bc07 -> 8e938de75


HBASE-12966 NPE in HMaster while recovering tables in Enabling state (Andrey 
Stepachev)


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

Branch: refs/heads/branch-1.0
Commit: 8e938de75ff9d4e1a5f11e04fd14a5c84e4bcccf
Parents: 19087bc
Author: tedyu <[email protected]>
Authored: Thu Feb 5 13:07:35 2015 -0800
Committer: tedyu <[email protected]>
Committed: Thu Feb 5 13:07:35 2015 -0800

----------------------------------------------------------------------
 .../master/handler/EnableTableHandler.java      |  35 ++++---
 .../hadoop/hbase/HBaseTestingUtility.java       |  41 ++++++++
 .../master/handler/TestEnableTableHandler.java  | 101 +++++++++++++++++++
 3 files changed, 163 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/8e938de7/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
index feb5b64..243ec2d 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/EnableTableHandler.java
@@ -26,15 +26,15 @@ import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.CoordinatedStateException;
-import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.MetaTableAccessor;
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.TableNotDisabledException;
 import org.apache.hadoop.hbase.TableNotFoundException;
-import org.apache.hadoop.hbase.MetaTableAccessor;
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.executor.EventHandler;
 import org.apache.hadoop.hbase.executor.EventType;
 import org.apache.hadoop.hbase.master.AssignmentManager;
@@ -226,19 +226,26 @@ public class EnableTableHandler extends EventHandler {
     List<ServerName> onlineServers = 
serverManager.createDestinationServersList();
     Map<ServerName, List<HRegionInfo>> bulkPlan =
         this.assignmentManager.getBalancer().retainAssignment(regionsToAssign, 
onlineServers);
-    LOG.info("Bulk assigning " + regionsCount + " region(s) across " + 
bulkPlan.size()
-      + " server(s), retainAssignment=true");
+    if (bulkPlan != null) {
+      LOG.info("Bulk assigning " + regionsCount + " region(s) across " + 
bulkPlan.size()
+          + " server(s), retainAssignment=true");
 
-    BulkAssigner ba = new GeneralBulkAssigner(this.server, bulkPlan, 
this.assignmentManager, true);
-    try {
-      if (ba.bulkAssign()) {
-        done = true;
+      BulkAssigner ba =
+          new GeneralBulkAssigner(this.server, bulkPlan, 
this.assignmentManager, true);
+      try {
+        if (ba.bulkAssign()) {
+          done = true;
+        }
+      } catch (InterruptedException e) {
+        LOG.warn("Enable operation was interrupted when enabling table '"
+            + this.tableName + "'");
+        // Preserve the interrupt.
+        Thread.currentThread().interrupt();
       }
-    } catch (InterruptedException e) {
-      LOG.warn("Enable operation was interrupted when enabling table '"
-        + this.tableName + "'");
-      // Preserve the interrupt.
-      Thread.currentThread().interrupt();
+    } else {
+      done = true;
+      LOG.info("Balancer was unable to find suitable servers for table " + 
tableName
+          + ", leaving unassigned");
     }
     if (done) {
       // Flip the table to enabled.

http://git-wip-us.apache.org/repos/asf/hbase/blob/8e938de7/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
index 27a7d4b..dffbc95 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
@@ -2860,6 +2860,47 @@ public class HBaseTestingUtility extends 
HBaseCommonTestingUtility {
   }
 
   /**
+   * Waits for a table to be 'disabled'.  Disabled means that table is set as 
'disabled'
+   * Will timeout after default period (30 seconds)
+   * @param table Table to wait on.
+   * @throws InterruptedException
+   * @throws IOException
+   */
+  public void waitTableDisabled(byte[] table)
+      throws InterruptedException, IOException {
+    waitTableDisabled(getHBaseAdmin(), table, 30000);
+  }
+
+  public void waitTableDisabled(Admin admin, byte[] table)
+      throws InterruptedException, IOException {
+    waitTableDisabled(admin, table, 30000);
+  }
+
+  /**
+   * Waits for a table to be 'disabled'.  Disabled means that table is set as 
'disabled'
+   * @param table Table to wait on.
+   * @param timeoutMillis Time to wait on it being marked disabled.
+   * @throws InterruptedException
+   * @throws IOException
+   */
+  public void waitTableDisabled(byte[] table, long timeoutMillis)
+      throws InterruptedException, IOException {
+    waitTableDisabled(getHBaseAdmin(), table, timeoutMillis);
+  }
+
+  public void waitTableDisabled(Admin admin, byte[] table, long timeoutMillis)
+      throws InterruptedException, IOException {
+    TableName tableName = TableName.valueOf(table);
+    long startWait = System.currentTimeMillis();
+    while (!admin.isTableDisabled(tableName)) {
+      assertTrue("Timed out waiting for table to become disabled " +
+              Bytes.toStringBinary(table),
+          System.currentTimeMillis() - startWait < timeoutMillis);
+      Thread.sleep(200);
+    }
+  }
+
+  /**
    * Make sure that at least the specified number of region servers
    * are running
    * @param num minimum number of region servers that should be running

http://git-wip-us.apache.org/repos/asf/hbase/blob/8e938de7/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java
 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java
new file mode 100644
index 0000000..327c11e
--- /dev/null
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestEnableTableHandler.java
@@ -0,0 +1,101 @@
+/**
+ *
+ * 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.handler;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.MetaTableAccessor;
+import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.FSTableDescriptors;
+import org.apache.hadoop.hbase.util.JVMClusterUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@Category({ MediumTests.class })
+public class TestEnableTableHandler {
+  private static final HBaseTestingUtility TEST_UTIL = new 
HBaseTestingUtility();
+  private static final Log LOG = 
LogFactory.getLog(TestEnableTableHandler.class);
+  private static final byte[] FAMILYNAME = Bytes.toBytes("fam");
+
+  @Before
+  public void setUp() throws Exception {
+    TEST_UTIL.getConfiguration().set("hbase.balancer.tablesOnMaster", 
"hbase:meta");
+    TEST_UTIL.startMiniCluster(1);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  @Test(timeout = 300000)
+  public void testEnableTableWithNoRegionServers() throws Exception {
+    final TableName tableName = 
TableName.valueOf("testEnableTableWithNoRegionServers");
+    final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
+    final HMaster m = cluster.getMaster();
+    final HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
+    final HTableDescriptor desc = new HTableDescriptor(tableName);
+    desc.addFamily(new HColumnDescriptor(FAMILYNAME));
+    admin.createTable(desc);
+    admin.disableTable(tableName);
+    TEST_UTIL.waitTableDisabled(tableName.getName());
+
+    admin.enableTable(tableName);
+    TEST_UTIL.waitTableEnabled(tableName);
+
+    // disable once more
+    admin.disableTable(tableName);
+
+    // now stop region servers
+    JVMClusterUtil.RegionServerThread rs = 
cluster.getRegionServerThreads().get(0);
+    rs.getRegionServer().stop("stop");
+    cluster.waitForRegionServerToStop(rs.getRegionServer().getServerName(), 
10000);
+
+    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.META_TABLE_NAME);
+
+    admin.enableTable(tableName);
+    assertTrue(admin.isTableEnabled(tableName));
+
+    JVMClusterUtil.RegionServerThread rs2 = cluster.startRegionServer();
+    m.getAssignmentManager().assign(admin.getTableRegions(tableName));
+    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
+    List<HRegionInfo> onlineRegions = admin.getOnlineRegions(
+        rs2.getRegionServer().getServerName());
+    assertEquals(2, onlineRegions.size());
+    assertEquals(tableName, onlineRegions.get(1).getTable());
+  }
+
+}

Reply via email to