Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D524918DD6 for ; Sun, 21 Jun 2015 06:12:21 +0000 (UTC) Received: (qmail 30083 invoked by uid 500); 21 Jun 2015 06:12:21 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 30035 invoked by uid 500); 21 Jun 2015 06:12:21 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 30025 invoked by uid 99); 21 Jun 2015 06:12:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Jun 2015 06:12:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7321DE3619; Sun, 21 Jun 2015 06:12:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: enis@apache.org To: commits@hbase.apache.org Message-Id: <277d6933ae954b27800869dc05559cdc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-13935 Orphaned namespace table ZK node should not prevent master to start (Stephen Yuan Jiang) Date: Sun, 21 Jun 2015 06:12:21 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/0.98 68bdf873e -> bdaf1e326 HBASE-13935 Orphaned namespace table ZK node should not prevent master to start (Stephen Yuan Jiang) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/bdaf1e32 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/bdaf1e32 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/bdaf1e32 Branch: refs/heads/0.98 Commit: bdaf1e3269bfc434177a4d526c0b9bf4d9f6588a Parents: 68bdf87 Author: Enis Soztutar Authored: Sat Jun 20 23:12:07 2015 -0700 Committer: Enis Soztutar Committed: Sat Jun 20 23:12:07 2015 -0700 ---------------------------------------------------------------------- .../master/handler/CreateTableHandler.java | 7 +- .../master/handler/TestCreateTableHandler2.java | 68 ++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/bdaf1e32/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java index 8dc7cb5..24d8c71 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/handler/CreateTableHandler.java @@ -128,7 +128,12 @@ public class CreateTableHandler extends EventHandler { // createTable isn't a frequent operation, that should be ok. //TODO: now that we have table locks, re-evaluate above try { - if (!this.assignmentManager.getZKTable().checkAndSetEnablingTable(tableName)) { + // During master initialization, the ZK state could be inconsistent from failed DDL + // in the past. If we fail here, it would prevent master to start. We should force + // setting the system table state regardless the table state. + if (!((HMaster) this.server).isInitialized() && tableName.isSystemTable()) { + this.assignmentManager.getZKTable().setEnablingTable(tableName); + } else if (!this.assignmentManager.getZKTable().checkAndSetEnablingTable(tableName)) { throw new TableExistsException(tableName); } } catch (KeeperException e) { http://git-wip-us.apache.org/repos/asf/hbase/blob/bdaf1e32/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestCreateTableHandler2.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestCreateTableHandler2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestCreateTableHandler2.java new file mode 100644 index 0000000..2d360d9 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/handler/TestCreateTableHandler2.java @@ -0,0 +1,68 @@ +/** + * + * 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 static org.junit.Assert.assertTrue; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.protobuf.ProtobufUtil; +import org.apache.hadoop.hbase.protobuf.generated.ZooKeeperProtos; +import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster; +import org.apache.hadoop.hbase.zookeeper.ZKUtil; +import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; +import org.junit.After; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(MediumTests.class) +public class TestCreateTableHandler2 { + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + private static final Log LOG = LogFactory.getLog(TestCreateTableHandler2.class); + + @After + public void tearDown() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + TEST_UTIL.shutdownMiniZKCluster(); + } + + @Test + public void testMasterRestartAfterNameSpaceEnablingNodeIsCreated() throws Exception { + // Step 1: start mini zk cluster. + MiniZooKeeperCluster zkCluster; + zkCluster = TEST_UTIL.startMiniZKCluster(); + // Step 2: add an orphaned system table ZNODE + TableName tableName = TableName.valueOf("hbase:namespace"); + ZooKeeperWatcher zkw = TEST_UTIL.getZooKeeperWatcher(); + String znode = ZKUtil.joinZNode(zkw.tableZNode, tableName.getNameAsString()); + ZooKeeperProtos.Table.Builder builder = ZooKeeperProtos.Table.newBuilder(); + builder.setState(ZooKeeperProtos.Table.State.ENABLED); + byte [] data = ProtobufUtil.prependPBMagic(builder.build().toByteArray()); + ZKUtil.createSetData(zkw, znode, data); + LOG.info("Create an orphaned Znode " + znode + " with data " + data); + // Step 3: link the zk cluster to hbase cluster + TEST_UTIL.setZkCluster(zkCluster); + // Step 4: start hbase cluster and expect master to start successfully. + TEST_UTIL.startMiniCluster(); + assertTrue(TEST_UTIL.getHBaseCluster().getLiveMasterThreads().size() == 1); + } +}