From 65979de1fb81b2b1da979a5a716f1784648289b3 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Wed, 10 Nov 2010 21:46:14 +0000 Subject: [PATCH] HBASE-3216 Move HBaseFsck from client to util git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1033736 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + bin/hbase | 2 +- .../hbase/{client => util}/HBaseFsck.java | 5 +- .../{client => util}/HBaseFsckRepair.java | 5 +- .../apache/hadoop/hbase/client/TestAdmin.java | 9 -- .../hadoop/hbase/util/TestHBaseFsck.java | 106 ++++++++++++++++++ 6 files changed, 116 insertions(+), 12 deletions(-) rename src/main/java/org/apache/hadoop/hbase/{client => util}/HBaseFsck.java (99%) rename src/main/java/org/apache/hadoop/hbase/{client => util}/HBaseFsckRepair.java (95%) create mode 100644 src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java diff --git a/CHANGES.txt b/CHANGES.txt index 1705d7eccb0..0f318046354 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -673,6 +673,7 @@ Release 0.90.0 - Unreleased abort HBASE-3214 TestMasterFailover.testMasterFailoverWithMockedRITOnDeadRS is failing (Gary via jgray) + HBASE-3216 Move HBaseFsck from client to util IMPROVEMENTS diff --git a/bin/hbase b/bin/hbase index ab95ea09a07..21292680809 100755 --- a/bin/hbase +++ b/bin/hbase @@ -255,7 +255,7 @@ elif [ "$COMMAND" = "avro" ] ; then elif [ "$COMMAND" = "migrate" ] ; then CLASS='org.apache.hadoop.hbase.util.Migrate' elif [ "$COMMAND" = "hbck" ] ; then - CLASS='org.apache.hadoop.hbase.client.HBaseFsck' + CLASS='org.apache.hadoop.hbase.util.HBaseFsck' elif [ "$COMMAND" = "zookeeper" ] ; then CLASS='org.apache.hadoop.hbase.zookeeper.HQuorumPeer' if [ "$1" != "stop" ] ; then diff --git a/src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java similarity index 99% rename from src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java rename to src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java index cf2787987f2..275e400319e 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/HBaseFsck.java +++ b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.client; +package org.apache.hadoop.hbase.util; import java.io.IOException; import java.util.Collection; @@ -45,6 +45,9 @@ import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.ZooKeeperConnectionException; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HConnection; +import org.apache.hadoop.hbase.client.MetaScanner; import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.ipc.HRegionInterface; diff --git a/src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java similarity index 95% rename from src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java rename to src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java index 67bc36e48c4..f7a6db563dc 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/HBaseFsckRepair.java +++ b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsckRepair.java @@ -17,7 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.hadoop.hbase.client; +package org.apache.hadoop.hbase.util; import java.io.IOException; import java.util.List; @@ -26,6 +26,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HServerAddress; +import org.apache.hadoop.hbase.client.Delete; +import org.apache.hadoop.hbase.client.HConnectionManager; +import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.ipc.HRegionInterface; import org.apache.hadoop.hbase.zookeeper.ZKAssign; diff --git a/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java b/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java index a898b93e42d..8560d220fdf 100644 --- a/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java +++ b/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java @@ -120,15 +120,6 @@ public class TestAdmin { assertTrue(ok); } - @Test - public void testHBaseFsck() throws IOException { - HBaseFsck fsck = - new HBaseFsck(TEST_UTIL.getMiniHBaseCluster().getConfiguration()); - fsck.displayFullReport(); - int result = fsck.doWork(); - assertEquals(0, result); - } - @Test public void testCreateTable() throws IOException { HTableDescriptor [] tables = admin.listTables(); diff --git a/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java b/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java new file mode 100644 index 00000000000..203347e3abc --- /dev/null +++ b/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java @@ -0,0 +1,106 @@ +/** + * Copyright 2010 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.util; + +import java.io.IOException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HServerInfo; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class TestHBaseFsck { + + final Log LOG = LogFactory.getLog(getClass()); + private final static HBaseTestingUtility TEST_UTIL = + new HBaseTestingUtility(); + private final static Configuration conf = TEST_UTIL.getConfiguration(); + private final static byte[] TABLE = Bytes.toBytes("table"); + private final static byte[] FAM = Bytes.toBytes("fam"); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + TEST_UTIL.startMiniCluster(3); + } + + @Test + public void testHBaseFsck() throws IOException { + HBaseFsck fsck = new HBaseFsck(conf); + fsck.displayFullReport(); + fsck.setTimeLag(0); + // Most basic check ever, 0 tables + int result = fsck.doWork(); + assertEquals(0, result); + + TEST_UTIL.createTable(TABLE, FAM); + + // We created 1 table, should be fine + result = fsck.doWork(); + assertEquals(0, result); + + // Now let's mess it up and change the assignment in .META. to + // point to a different region server + HTable meta = new HTable(conf, HTableDescriptor.META_TABLEDESC.getName()); + ResultScanner scanner = meta.getScanner(new Scan()); + + resforloop : for (Result res : scanner) { + long startCode = Bytes.toLong(res.getValue(HConstants.CATALOG_FAMILY, + HConstants.STARTCODE_QUALIFIER)); + + for (JVMClusterUtil.RegionServerThread rs : + TEST_UTIL.getHBaseCluster().getRegionServerThreads()) { + + HServerInfo hsi = rs.getRegionServer().getServerInfo(); + + // When we find a diff RS, change the assignment and break + if (startCode != hsi.getStartCode()) { + Put put = new Put(res.getRow()); + put.add(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER, + Bytes.toBytes(hsi.getHostnamePort())); + put.add(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER, + Bytes.toBytes(hsi.getStartCode())); + meta.put(put); + break resforloop; + } + } + } + + // We set this here, but it's really not fixing anything... + fsck.setFixErrors(); + result = fsck.doWork(); + // Fixed or not, it still reports inconsistencies + assertEquals(-1, result); + + // Disabled, won't work because the region stays unassigned, see HBASE-3217 + // new HTable(conf, TABLE).getScanner(new Scan()); + } +}