hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/5] hbase git commit: HBASE-13017 Backport HBASE-12035 Keep table state in Meta to 1.0 branch; REVERT
Date Tue, 03 Mar 2015 21:26:26 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 9e7ad9959 -> 6b1674b31


http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOpenedRegionHandler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOpenedRegionHandler.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOpenedRegionHandler.java
index c1482a7..4ae6b24 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOpenedRegionHandler.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOpenedRegionHandler.java
@@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.MockServer;
 import org.apache.hadoop.hbase.zookeeper.ZKAssign;
+import org.apache.hadoop.hbase.zookeeper.ZKTableStateManager;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.zookeeper.KeeperException;
@@ -127,7 +128,6 @@ public class TestOpenedRegionHandler {
       region = HRegion.createHRegion(hri, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(),
htd);
       assertNotNull(region);
       AssignmentManager am = Mockito.mock(AssignmentManager.class);
-      TableStateManager tsm = Mockito.mock(TableStateManager.class);
       RegionStates rsm = Mockito.mock(RegionStates.class);
       Mockito.doReturn(rsm).when(am).getRegionStates();
       when(rsm.isRegionInTransition(hri)).thenReturn(false);
@@ -137,7 +137,7 @@ public class TestOpenedRegionHandler {
       // create a node with OPENED state
       zkw = HBaseTestingUtility.createAndForceNodeToOpenedState(TEST_UTIL,
           region, server.getServerName());
-      when(am.getTableStateManager()).thenReturn(tsm);
+      when(am.getTableStateManager()).thenReturn(new ZKTableStateManager(zkw));
       Stat stat = new Stat();
       String nodeName = ZKAssign.getNodeName(zkw, region.getRegionInfo()
           .getEncodedName());
@@ -166,7 +166,6 @@ public class TestOpenedRegionHandler {
       try {
         handler.process();
       } catch (Exception e) {
-        e.printStackTrace();
         expectedException = true;
       }
       assertFalse("The process method should not throw any exception.",

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
index a35e359..20cbd62 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
@@ -19,8 +19,10 @@ package org.apache.hadoop.hbase.master;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableStateManager;
 import org.apache.hadoop.hbase.testclassification.SmallTests;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -41,7 +43,7 @@ public class TestRegionStates {
 
   @Test
   public void testWeDontReturnDrainingServersForOurBalancePlans() throws Exception {
-    MasterServices server = mock(MasterServices.class);
+    Server server = mock(Server.class);
     when(server.getServerName()).thenReturn(ServerName.valueOf("master,1,1"));
     Configuration configuration = mock(Configuration.class);
     when(server.getConfiguration()).thenReturn(configuration);

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/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
index 93b8755..39b347d 100644
--- 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
@@ -18,32 +18,25 @@
  */
 package org.apache.hadoop.hbase.master.handler;
 
-import java.io.IOException;
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.MetaTableAccessor;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HConstants;
 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.Delete;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.client.ResultScanner;
-import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.client.Table;
 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;
@@ -53,6 +46,13 @@ import org.junit.experimental.categories.Category;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+
 @Category({ MediumTests.class })
 public class TestEnableTableHandler {
   private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -84,6 +84,7 @@ public class TestEnableTableHandler {
 
     admin.enableTable(tableName);
     TEST_UTIL.waitTableEnabled(tableName);
+
     // disable once more
     admin.disableTable(tableName);
 
@@ -93,49 +94,30 @@ public class TestEnableTableHandler {
     rs.getRegionServer().stop("stop");
     cluster.waitForRegionServerToStop(rs.getRegionServer().getServerName(), 10000);
 
-    LOG.debug("Now enabling table " + tableName);
+    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.META_TABLE_NAME);
 
     admin.enableTable(tableName);
     assertTrue(admin.isTableEnabled(tableName));
 
     JVMClusterUtil.RegionServerThread rs2 = cluster.startRegionServer();
-    cluster.waitForRegionServerToStart(rs2.getRegionServer().getServerName().getHostname(),
-        rs2.getRegionServer().getServerName().getPort(), 60000);
-
-    List<HRegionInfo> regions = TEST_UTIL.getHBaseAdmin().getTableRegions(tableName);
-    assertEquals(1, regions.size());
-    for (HRegionInfo region : regions) {
-      TEST_UTIL.getHBaseAdmin().assign(region.getEncodedNameAsBytes());
-    }
-    LOG.debug("Waiting for table assigned " + tableName);
+    m.getAssignmentManager().assign(admin.getTableRegions(tableName));
     TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
     List<HRegionInfo> onlineRegions = admin.getOnlineRegions(
         rs2.getRegionServer().getServerName());
-    ArrayList<HRegionInfo> tableRegions = filterTableRegions(tableName, onlineRegions);
-    assertEquals(1, tableRegions.size());
-  }
-
-  private ArrayList<HRegionInfo> filterTableRegions(final TableName tableName,
-      List<HRegionInfo> onlineRegions) {
-    return Lists.newArrayList(Iterables.filter(onlineRegions, new Predicate<HRegionInfo>()
{
-      @Override
-      public boolean apply(HRegionInfo input) {
-        return input.getTable().equals(tableName);
-      }
-    }));
+    assertEquals(2, onlineRegions.size());
+    assertEquals(tableName, onlineRegions.get(1).getTable());
   }
 
   /**
    * We were only clearing rows that had a hregioninfo column in hbase:meta.  Mangled rows
that
    * were missing the hregioninfo because of error were being left behind messing up any
    * subsequent table made with the same name. HBASE-12980
-   *
    * @throws IOException
    * @throws InterruptedException
    */
-  @Test(timeout = 60000)
+  @Test(timeout=60000)
   public void testDeleteForSureClearsAllTableRowsFromMeta()
-      throws IOException, InterruptedException {
+  throws IOException, InterruptedException {
     final TableName tableName = TableName.valueOf("testDeleteForSureClearsAllTableRowsFromMeta");
     final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
     final HMaster m = cluster.getMaster();

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestUpgradeTo96.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestUpgradeTo96.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestUpgradeTo96.java
index dc4bc40..2a8c9e3 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestUpgradeTo96.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/migration/TestUpgradeTo96.java
@@ -30,7 +30,6 @@ import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FsShell;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.client.TableState;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.io.FileLink;
 import org.apache.hadoop.hbase.io.HFileLink;
@@ -137,7 +136,7 @@ public class TestUpgradeTo96 {
     // add table znode, data of its children would be protobuffized
     tableAZnode = ZKUtil.joinZNode(zkw.tableZNode, "a");
     ZKUtil.createWithParents(zkw, tableAZnode,
-      Bytes.toBytes(TableState.State.ENABLED.toString()));
+      Bytes.toBytes(ZooKeeperProtos.Table.State.ENABLED.toString()));
     // add replication znodes, data of its children would be protobuffized
     String replicationZnode = ZKUtil.joinZNode(zkw.baseZNode, "replication");
     replicationPeerZnode = ZKUtil.joinZNode(replicationZnode, "peers");

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java
index 9054aa9..2f99cd5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestCoprocessorScanPolicy.java
@@ -211,7 +211,6 @@ public class TestCoprocessorScanPolicy {
     // should be gone now
     assertEquals(0, r.size());
     t.close();
-    EnvironmentEdgeManager.reset();
   }
 
   public static class ScanObserver extends BaseRegionObserver {

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
index 0bd412d..df01d71 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java
@@ -261,7 +261,7 @@ public class TestFSTableDescriptors {
       htds.createTableDescriptor(htd);
     }
     // add hbase:meta
-    HTableDescriptor htd = new HTableDescriptor(TableName.META_TABLE_NAME);
+    HTableDescriptor htd = new HTableDescriptor(HTableDescriptor.META_TABLEDESC.getTableName());
     htds.createTableDescriptor(htd);
 
     assertTrue(htds.getAll().size() == count + 1);

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
index 4083bea..c4ed3ee 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java
@@ -37,6 +37,8 @@ import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
+import java.util.Map.Entry;
 import java.util.NavigableMap;
 import java.util.Set;
 import java.util.concurrent.Callable;
@@ -67,6 +69,7 @@ import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.TableExistsException;
 import org.apache.hadoop.hbase.testclassification.LargeTests;
 import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.RegionLocations;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.MetaTableAccessor;
@@ -81,10 +84,12 @@ import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HConnection;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.MetaScanner;
+import org.apache.hadoop.hbase.client.Mutation;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.RegionReplicaUtil;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.RowMutations;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.client.Table;
 import org.apache.hadoop.hbase.io.hfile.TestHFile;
@@ -159,7 +164,6 @@ public class TestHBaseFsck {
     conf.setInt("hbase.hconnection.threads.max", 2 * POOL_SIZE);
     conf.setInt("hbase.hconnection.threads.core", POOL_SIZE);
     conf.setInt("hbase.hbck.close.timeout", 2 * REGION_ONLINE_TIMEOUT);
-    conf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 2 * REGION_ONLINE_TIMEOUT);
     TEST_UTIL.startMiniCluster(3);
 
     tableExecutorService = new ThreadPoolExecutor(1, POOL_SIZE, 60, TimeUnit.SECONDS,
@@ -1352,7 +1356,7 @@ public class TestHBaseFsck {
     HBaseFsck hbck = doFsck(conf, false);
     assertErrors(hbck, new ERROR_CODE[] {ERROR_CODE.NOT_IN_HDFS,
         ERROR_CODE.NOT_IN_HDFS, ERROR_CODE.NOT_IN_HDFS,
-        ERROR_CODE.NOT_IN_HDFS, ERROR_CODE.ORPHAN_TABLE_STATE, });
+        ERROR_CODE.NOT_IN_HDFS,});
     // holes are separate from overlap groups
     assertEquals(0, hbck.getOverlapGroups(table).size());
 
@@ -1395,34 +1399,6 @@ public class TestHBaseFsck {
   }
 
   /**
-   * when the hbase.version file missing, It is fix the fault.
-   */
-  @Test (timeout=180000)
-  public void testNoTableState() throws Exception {
-    // delete the hbase.version file
-    TableName table =
-        TableName.valueOf("testNoTableState");
-    try {
-      setupTable(table);
-      // make sure data in regions, if in wal only there is no data loss
-      admin.flush(table);
-
-      MetaTableAccessor.deleteTableState(TEST_UTIL.getConnection(), table);
-
-      // test
-      HBaseFsck hbck = doFsck(conf, false);
-      assertErrors(hbck, new ERROR_CODE[] { ERROR_CODE.NO_TABLE_STATE });
-      // fix table state missing
-      doFsck(conf, true);
-
-      assertNoErrors(doFsck(conf, false));
-      assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(table));
-    } finally {
-      cleanupTable(table);
-    }
-  }
-
-  /**
    * The region is not deployed when the table is disabled.
    */
   @Test (timeout=180000)
@@ -2429,6 +2405,55 @@ public class TestHBaseFsck {
     writeLock.release(); // release for clean state
   }
 
+  /**
+   * Test orphaned table ZNode (for table states)
+   */
+  @Test
+  public void testOrphanedTableZNode() throws Exception {
+    TableName table = TableName.valueOf("testOrphanedZKTableEntry");
+
+    try {
+      TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getTableStateManager()
+      .setTableState(table, ZooKeeperProtos.Table.State.ENABLING);
+
+      try {
+        setupTable(table);
+        Assert.fail(
+          "Create table should fail when its ZNode has already existed with ENABLING state.");
+      } catch(TableExistsException t) {
+        //Expected exception
+      }
+      // The setup table was interrupted in some state that needs to some cleanup.
+      try {
+        cleanupTable(table);
+      } catch (IOException e) {
+        // Because create table failed, it is expected that the cleanup table would
+        // throw some exception.  Ignore and continue.
+      }
+
+      HBaseFsck hbck = doFsck(conf, false);
+      assertTrue(hbck.getErrors().getErrorList().contains(ERROR_CODE.ORPHANED_ZK_TABLE_ENTRY));
+
+      // fix the orphaned ZK entry
+      hbck = doFsck(conf, true);
+
+      // check that orpahned ZK table entry is gone.
+      hbck = doFsck(conf, false);
+      assertFalse(hbck.getErrors().getErrorList().contains(ERROR_CODE.ORPHANED_ZK_TABLE_ENTRY));
+      // Now create table should succeed.
+      setupTable(table);
+    } finally {
+      // This code could be called that either a table was created successfully or set up
+      // table failed in some unknown state.  Therefore, clean up can either succeed or fail.
+      try {
+        cleanupTable(table);
+      } catch (IOException e) {
+        // The cleanup table would throw some exception if create table failed in some state.
+        // Ignore this exception
+      }
+    }
+  }
+
   @Test (timeout=180000)
   public void testMetaOffline() throws Exception {
     // check no errors

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
index 5be4b1e..744240e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRebuildTestCore.java
@@ -35,9 +35,6 @@ 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.client.HConnection;
-import org.apache.hadoop.hbase.client.HConnectionManager;
-import org.apache.hadoop.hbase.client.TableState;
 import org.apache.hadoop.hbase.testclassification.LargeTests;
 import org.apache.hadoop.hbase.NamespaceDescriptor;
 import org.apache.hadoop.hbase.ServerName;
@@ -232,6 +229,7 @@ public class OfflineMetaRebuildTestCore {
     out.write(hri.toDelimitedByteArray());
     out.close();
 
+    // add to meta.
     MetaTableAccessor.addRegionToMeta(meta, hri);
     meta.close();
     return hri;
@@ -286,9 +284,16 @@ public class OfflineMetaRebuildTestCore {
    * @return # of entries in meta.
    */
   protected int scanMeta() throws IOException {
-    LOG.info("Scanning META");
-    MetaTableAccessor.fullScanMetaAndPrint(TEST_UTIL.getConnection());
-    return MetaTableAccessor.fullScanRegions(TEST_UTIL.getConnection()).size();
+    int count = 0;
+    HTable meta = new HTable(conf, TableName.META_TABLE_NAME);
+    ResultScanner scanner = meta.getScanner(new Scan());
+    LOG.info("Table: " + Bytes.toString(meta.getTableName()));
+    for (Result res : scanner) {
+      LOG.info(Bytes.toString(res.getRow()));
+      count++;
+    }
+    meta.close();
+    return count;
   }
 
   protected HTableDescriptor[] getTables(final Configuration configuration) throws IOException
{

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildBase.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildBase.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildBase.java
index a4ddc13..f4a035f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildBase.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildBase.java
@@ -20,13 +20,11 @@ package org.apache.hadoop.hbase.util.hbck;
 import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.assertErrors;
 import static org.apache.hadoop.hbase.util.hbck.HbckTestingUtil.doFsck;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
 
 import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.client.Admin;
 import org.apache.hadoop.hbase.client.Connection;
@@ -59,29 +57,24 @@ public class TestOfflineMetaRebuildBase extends OfflineMetaRebuildTestCore
{
 
     // shutdown the minicluster
     TEST_UTIL.shutdownMiniHBaseCluster();
+    TEST_UTIL.shutdownMiniZKCluster();
 
     // rebuild meta table from scratch
     HBaseFsck fsck = new HBaseFsck(conf);
     assertTrue(fsck.rebuildMeta(false));
 
     // bring up the minicluster
+    TEST_UTIL.startMiniZKCluster();
     TEST_UTIL.restartHBaseCluster(3);
     try (Connection connection = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()))
{
       Admin admin = connection.getAdmin();
-      if (admin.isTableDisabled(table))
-        admin.enableTable(table);
+      admin.enableTable(table);
       LOG.info("Waiting for no more RIT");
       TEST_UTIL.waitUntilNoRegionsInTransition(60000);
       LOG.info("No more RIT in ZK, now doing final test verification");
 
       // everything is good again.
-      assertEquals(5, scanMeta()); // including table state rows
-      TableName[] tableNames = TEST_UTIL.getHBaseAdmin().listTableNames();
-      for (TableName tableName : tableNames) {
-        HTableDescriptor tableDescriptor = TEST_UTIL.getHBaseAdmin().getTableDescriptor(tableName);
-        assertNotNull(tableDescriptor);
-        assertTrue(TEST_UTIL.getHBaseAdmin().isTableEnabled(tableName));
-      }
+      assertEquals(5, scanMeta());
       HTableDescriptor[] htbls = admin.listTables();
       LOG.info("Tables present after restart: " + Arrays.toString(htbls));
       assertEquals(1, htbls.length);

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildHole.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildHole.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildHole.java
index 7bdc6f2..f6fd4f1 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildHole.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildHole.java
@@ -61,6 +61,7 @@ public class TestOfflineMetaRebuildHole extends OfflineMetaRebuildTestCore
{
 
     // shutdown the minicluster
     TEST_UTIL.shutdownMiniHBaseCluster();
+    TEST_UTIL.shutdownMiniZKCluster();
 
     // attempt to rebuild meta table from scratch
     HBaseFsck fsck = new HBaseFsck(conf);
@@ -68,6 +69,7 @@ public class TestOfflineMetaRebuildHole extends OfflineMetaRebuildTestCore
{
     fsck.close();
 
     // bring up the minicluster
+    TEST_UTIL.startMiniZKCluster(); // tables seem enabled by default
     TEST_UTIL.restartHBaseCluster(3);
 
     ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildOverlap.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildOverlap.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildOverlap.java
index b8ca7d7..69a962b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildOverlap.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/TestOfflineMetaRebuildOverlap.java
@@ -66,6 +66,7 @@ public class TestOfflineMetaRebuildOverlap extends OfflineMetaRebuildTestCore
{
 
     // shutdown the minicluster
     TEST_UTIL.shutdownMiniHBaseCluster();
+    TEST_UTIL.shutdownMiniZKCluster();
 
     // attempt to rebuild meta table from scratch
     HBaseFsck fsck = new HBaseFsck(conf);
@@ -76,6 +77,7 @@ public class TestOfflineMetaRebuildOverlap extends OfflineMetaRebuildTestCore
{
     assertEquals(3, problems.size());
 
     // bring up the minicluster
+    TEST_UTIL.startMiniZKCluster(); // tables seem enabled by default
     TEST_UTIL.restartHBaseCluster(3);
 
     ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TEST_UTIL);

http://git-wip-us.apache.org/repos/asf/hbase/blob/6b1674b3/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTableStateManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTableStateManager.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTableStateManager.java
new file mode 100644
index 0000000..e81c89f
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKTableStateManager.java
@@ -0,0 +1,114 @@
+/**
+ *
+ * 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.zookeeper;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.hbase.Abortable;
+import org.apache.hadoop.hbase.CoordinatedStateException;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableStateManager;
+import org.apache.zookeeper.KeeperException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos.Table;
+
+@Category(MediumTests.class)
+public class TestZKTableStateManager {
+  private static final Log LOG = LogFactory.getLog(TestZKTableStateManager.class);
+  private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    TEST_UTIL.startMiniZKCluster();
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+    TEST_UTIL.shutdownMiniZKCluster();
+  }
+
+  @Test
+  public void testTableStates()
+      throws CoordinatedStateException, IOException, KeeperException, InterruptedException
{
+    final TableName name =
+        TableName.valueOf("testDisabled");
+    Abortable abortable = new Abortable() {
+      @Override
+      public void abort(String why, Throwable e) {
+        LOG.info(why, e);
+      }
+
+      @Override
+      public boolean isAborted() {
+        return false;
+      }
+
+    };
+    ZooKeeperWatcher zkw = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
+      name.getNameAsString(), abortable, true);
+    TableStateManager zkt = new ZKTableStateManager(zkw);
+    assertFalse(zkt.isTableState(name, Table.State.ENABLED));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLED));
+    assertFalse(zkt.isTableState(name, Table.State.ENABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLED, Table.State.DISABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLED, Table.State.ENABLING));
+    assertFalse(zkt.isTablePresent(name));
+    zkt.setTableState(name, Table.State.DISABLING);
+    assertTrue(zkt.isTableState(name, Table.State.DISABLING));
+    assertTrue(zkt.isTableState(name, Table.State.DISABLED, Table.State.DISABLING));
+    assertFalse(zkt.getTablesInStates(Table.State.DISABLED).contains(name));
+    assertTrue(zkt.isTablePresent(name));
+    zkt.setTableState(name, Table.State.DISABLED);
+    assertTrue(zkt.isTableState(name, Table.State.DISABLED));
+    assertTrue(zkt.isTableState(name, Table.State.DISABLED, Table.State.DISABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLING));
+    assertTrue(zkt.getTablesInStates(Table.State.DISABLED).contains(name));
+    assertTrue(zkt.isTablePresent(name));
+    zkt.setTableState(name, Table.State.ENABLING);
+    assertTrue(zkt.isTableState(name, Table.State.ENABLING));
+    assertTrue(zkt.isTableState(name, Table.State.DISABLED, Table.State.ENABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLED));
+    assertFalse(zkt.getTablesInStates(Table.State.DISABLED).contains(name));
+    assertTrue(zkt.isTablePresent(name));
+    zkt.setTableState(name, Table.State.ENABLED);
+    assertTrue(zkt.isTableState(name, Table.State.ENABLED));
+    assertFalse(zkt.isTableState(name, Table.State.ENABLING));
+    assertTrue(zkt.isTablePresent(name));
+    zkt.setDeletedTable(name);
+    assertFalse(zkt.isTableState(name, Table.State.ENABLED));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLED));
+    assertFalse(zkt.isTableState(name, Table.State.ENABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLED, Table.State.DISABLING));
+    assertFalse(zkt.isTableState(name, Table.State.DISABLED, Table.State.ENABLING));
+    assertFalse(zkt.isTablePresent(name));
+  }
+}


Mime
View raw message