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
This commit is contained in:
Jean-Daniel Cryans 2010-11-10 21:46:14 +00:00
parent 6b7055eb24
commit 65979de1fb
6 changed files with 116 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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());
}
}