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 61a1c66..8df50d8 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 @@ -566,13 +566,6 @@ public class HMaster extends HRegionServer implements MasterServices, Server { this.mpmHost.loadProcedures(conf); this.mpmHost.initialize(this, this.metricsMaster); - // migrating existent table state from zk - for (Map.Entry entry : ZKDataMigrator - .queryForTableStates(getZooKeeper()).entrySet()) { - LOG.info("Converting state from zk to new states:" + entry); - tableStateManager.setTableState(entry.getKey(), entry.getValue()); - } - ZKUtil.deleteChildrenRecursively(getZooKeeper(), getZooKeeper().tableZNode); } /** @@ -711,6 +704,15 @@ public class HMaster extends HRegionServer implements MasterServices, Server { // assigned when master is shutting down if(isStopped()) return; + // migrating existent table state from zk, so splitters + // and recovery process treat states properly. + for (Map.Entry entry : ZKDataMigrator + .queryForTableStates(getZooKeeper()).entrySet()) { + LOG.info("Converting state from zk to new states:" + entry); + tableStateManager.setTableState(entry.getKey(), entry.getValue()); + } + ZKUtil.deleteChildrenRecursively(getZooKeeper(), getZooKeeper().tableZNode); + status.setStatus("Submitting log splitting work for previously failed region servers"); // Master has recovered hbase:meta region server and we put // other failed region servers in a queue to be handled later by SSH diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableStateManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableStateManager.java new file mode 100644 index 0000000..e0e969e --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestTableStateManager.java @@ -0,0 +1,82 @@ +/* + * Copyright The Apache Software Foundation + * + * 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.io.IOException; + +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.TableState; +import org.apache.hadoop.hbase.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; +import org.apache.hadoop.hbase.testclassification.LargeTests; +import org.apache.hadoop.hbase.testclassification.MasterTests; +import org.apache.hadoop.hbase.zookeeper.ZKUtil; +import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; +import org.apache.zookeeper.KeeperException; +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Tests the default table lock manager + */ +@Category({ MasterTests.class, LargeTests.class }) +public class TestTableStateManager { + + private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + + @After + public void tearDown() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + @Test(timeout = 60000) + public void testUpgradeFromZk() throws Exception { + TableName tableName = + TableName.valueOf("testUpgradeFromZk"); + TEST_UTIL.startMiniCluster(2, 1); + TEST_UTIL.shutdownMiniHBaseCluster(); + ZooKeeperWatcher watcher = TEST_UTIL.getZooKeeperWatcher(); + setTableStateInZK(watcher, tableName, ZooKeeperProtos.DeprecatedTableState.State.DISABLED); + TEST_UTIL.restartHBaseCluster(1); + + HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); + Assert.assertEquals( + master.getTableStateManager().getTableState(tableName), + TableState.State.DISABLED); + } + + private void setTableStateInZK(ZooKeeperWatcher watcher, final TableName tableName, + final ZooKeeperProtos.DeprecatedTableState.State state) + throws KeeperException, IOException { + String znode = ZKUtil.joinZNode(watcher.tableZNode, tableName.getNameAsString()); + if (ZKUtil.checkExists(watcher, znode) == -1) { + ZKUtil.createAndFailSilent(watcher, znode); + } + ZooKeeperProtos.DeprecatedTableState.Builder builder = + ZooKeeperProtos.DeprecatedTableState.newBuilder(); + builder.setState(state); + byte[] data = ProtobufUtil.prependPBMagic(builder.build().toByteArray()); + ZKUtil.setData(watcher, znode, data); + } + +}