From 5bbed78d7311c2996694563df750e9b549d048dc Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Sat, 1 Oct 2011 04:18:13 +0000 Subject: [PATCH] HBASE-4506 [hbck] Allow HBaseFsck to be instantiated without connecting git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1177896 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../apache/hadoop/hbase/util/HBaseFsck.java | 26 +++++++++++-------- .../hadoop/hbase/util/TestHBaseFsck.java | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index cc107775e14..00106090a7d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -683,6 +683,8 @@ Release 0.90.5 - Unreleased HBASE-4295 rowcounter does not return the correct number of rows in certain circumstances (David Revell) HBASE-4515 User.getCurrent() can fail to initialize the current user + HBASE-4506 [hbck] Allow HBaseFsck to be instantiated without connecting + (Jonathan Hsieh) IMPROVEMENT HBASE-4205 Enhance HTable javadoc (Eric Charles) diff --git a/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java index 84657241845..ed57b4dd69c 100644 --- a/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java +++ b/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java @@ -106,7 +106,7 @@ public class HBaseFsck { // Empty regioninfo qualifiers in .META. private Set emptyRegionInfoQualifiers = new HashSet(); private int numThreads = MAX_NUM_THREADS; - private final HBaseAdmin admin; + private HBaseAdmin admin; ThreadPoolExecutor executor; // threads to retrieve data from regionservers @@ -117,18 +117,21 @@ public class HBaseFsck { * @throws MasterNotRunningException if the master is not running * @throws ZooKeeperConnectionException if unable to connect to zookeeper */ - public HBaseFsck(Configuration conf) - throws MasterNotRunningException, ZooKeeperConnectionException, IOException { + public HBaseFsck(Configuration conf) throws MasterNotRunningException, + ZooKeeperConnectionException, IOException { this.conf = conf; - admin = new HBaseAdmin(conf); - status = admin.getMaster().getClusterStatus(); - connection = admin.getConnection(); - numThreads = conf.getInt("hbasefsck.numthreads", numThreads); executor = new ThreadPoolExecutor(0, numThreads, - THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, - new LinkedBlockingQueue()); + THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, + new LinkedBlockingQueue()); + } + + public void connect() throws MasterNotRunningException, + ZooKeeperConnectionException { + admin = new HBaseAdmin(conf); + status = admin.getMaster().getClusterStatus(); + connection = admin.getConnection(); } /** @@ -1337,11 +1340,11 @@ public class HBaseFsck { * @param args * @throws Exception */ - public static void main(String [] args) throws Exception { + public static void main(String[] args) throws Exception { // create a fsck object Configuration conf = HBaseConfiguration.create(); - conf.set("fs.defaultFS", conf.get("hbase.rootdir")); + conf.set("fs.defaultFS", conf.get(HConstants.HBASE_DIR)); HBaseFsck fsck = new HBaseFsck(conf); long sleepBeforeRerun = DEFAULT_SLEEP_BEFORE_RERUN; @@ -1389,6 +1392,7 @@ public class HBaseFsck { } } // do the real work of fsck + fsck.connect(); int code = fsck.doWork(); // If we have changed the HBase state it is better to run fsck again // to see if we haven't broken something else in the process. diff --git a/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java b/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java index fae0881cf78..29430500872 100644 --- a/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java +++ b/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java @@ -77,6 +77,7 @@ public class TestHBaseFsck { private List doFsck(boolean fix) throws Exception { HBaseFsck fsck = new HBaseFsck(conf); + fsck.connect(); fsck.displayFullReport(); // i.e. -details fsck.setTimeLag(0); fsck.setFixErrors(fix);