in hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java [5427:5499]
public HBaseFsck exec(ExecutorService exec, String[] args)
throws KeeperException, IOException, InterruptedException, ReplicationException {
errors.print("HBaseFsck command line options: " + String.join(" ", args));
CommandLineData cld = new CommandLineData();
doCommandLine(args, cld);
// pre-check current user has FS write permission or not
try {
preCheckPermission();
} catch (IOException ace) {
Runtime.getRuntime().exit(-1);
}
// do the real work of hbck
connect();
// after connecting to server above, we have server version
// check if unsupported option is specified based on server version
if (!isOptionsSupported(args)) {
return printUsageAndExit();
}
try {
Collection<TableName> tables = getIncludedTables();
Path rootdir = CommonFSUtils.getRootDir(getConf());
if (tables.isEmpty()) {
tableDirs.addAll(FSUtils.getTableDirs(rootFs, rootdir));
} else {
tableDirs.add(CommonFSUtils.getTableDir(rootdir, TableName.META_TABLE_NAME));
for (TableName table : tables) {
tableDirs.add(CommonFSUtils.getTableDir(rootdir, table));
}
}
// if corrupt file mode is on, first fix them since they may be opened later
if (cld.checkCorruptHFiles || cld.sidelineCorruptHFiles) {
LOG.info("Checking all hfiles for corruption");
HFileCorruptionChecker hfcc = createHFileCorruptionChecker(cld.sidelineCorruptHFiles);
setHFileCorruptionChecker(hfcc); // so we can get result
hfcc.checkTables(tableDirs);
hfcc.report(errors);
}
// check and fix table integrity, region consistency.
int code = onlineHbck();
setRetCode(code);
// If we have changed the HBase state it is better to run hbck again
// to see if we haven't broken something else in the process.
// We run it only once more because otherwise we can easily fall into
// an infinite loop.
if (shouldRerun()) {
try {
LOG.info("Sleeping " + cld.sleepBeforeRerun + "ms before re-checking after fix...");
Thread.sleep(cld.sleepBeforeRerun);
} catch (InterruptedException ie) {
LOG.warn("Interrupted while sleeping");
return this;
}
// Just report
setFixAssignments(false);
setFixMeta(false);
setFixHdfsHoles(false);
setFixHdfsOverlaps(false);
setFixVersionFile(false);
setFixTableOrphans(false);
errors.resetErrors();
code = onlineHbck();
setRetCode(code);
}
} finally {
IOUtils.closeQuietly(this);
}
return this;
}