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
This commit is contained in:
Michael Stack 2011-10-01 04:18:13 +00:00
parent 39c0909e3e
commit 5bbed78d73
3 changed files with 18 additions and 11 deletions

View File

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

View File

@ -106,7 +106,7 @@ public class HBaseFsck {
// Empty regioninfo qualifiers in .META.
private Set<Result> emptyRegionInfoQualifiers = new HashSet<Result>();
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<Runnable>());
THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
}
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.

View File

@ -77,6 +77,7 @@ public class TestHBaseFsck {
private List<ERROR_CODE> doFsck(boolean fix) throws Exception {
HBaseFsck fsck = new HBaseFsck(conf);
fsck.connect();
fsck.displayFullReport(); // i.e. -details
fsck.setTimeLag(0);
fsck.setFixErrors(fix);