diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java index 996ba7d..65b33ee 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java @@ -65,7 +65,6 @@ import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.ZooKeeperConnectionException; @@ -219,7 +218,7 @@ public class HBaseFsck extends Configured implements Tool { /********* * State *********/ - final private ErrorReporter errors; + private ErrorReporter errors; int fixes = 0; /** @@ -258,33 +257,22 @@ public class HBaseFsck extends Configured implements Tool { * Constructor * * @param conf Configuration object - * @throws MasterNotRunningException if the master is not running - * @throws ZooKeeperConnectionException if unable to connect to ZooKeeper */ - public HBaseFsck(Configuration conf) throws MasterNotRunningException, - ZooKeeperConnectionException, IOException, ClassNotFoundException { + public HBaseFsck(Configuration conf) { super(conf); - errors = getErrorReporter(conf); - - int numThreads = conf.getInt("hbasefsck.numthreads", MAX_NUM_THREADS); - executor = new ScheduledThreadPoolExecutor(numThreads, Threads.newDaemonThreadFactory("hbasefsck")); } - + /** - * Constructor - * - * @param conf - * Configuration object - * @throws MasterNotRunningException - * if the master is not running - * @throws ZooKeeperConnectionException - * if unable to connect to ZooKeeper + * Initialize the internal stuffs, such as {@link #errors}, {@link #executor}, etc. + * @throws ClassNotFoundException */ - public HBaseFsck(Configuration conf, ExecutorService exec) throws MasterNotRunningException, - ZooKeeperConnectionException, IOException, ClassNotFoundException { - super(conf); - errors = getErrorReporter(getConf()); - this.executor = exec; + public void doInitial() throws ClassNotFoundException { + Configuration conf = getConf(); + errors = getErrorReporter(conf); + + int numThreads = conf.getInt("hbasefsck.numthreads", MAX_NUM_THREADS); + executor = + new ScheduledThreadPoolExecutor(numThreads, Threads.newDaemonThreadFactory("hbasefsck")); } /** @@ -3594,11 +3582,12 @@ public class HBaseFsck extends Configured implements Tool { @Override public int run(String[] args) throws Exception { - exec(executor, args); + doInitial(); + exec(args); return getRetCode(); } - public HBaseFsck exec(ExecutorService exec, String[] args) throws KeeperException, IOException, + public HBaseFsck exec(String[] args) throws KeeperException, IOException, ServiceException, InterruptedException { long sleepBeforeRerun = DEFAULT_SLEEP_BEFORE_RERUN; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java index 531d68d..f5fb6f1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsck.java @@ -37,7 +37,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -129,6 +128,7 @@ public class TestHBaseFsck { public static void setUpBeforeClass() throws Exception { TEST_UTIL.getConfiguration().setInt("hbase.regionserver.handler.count", 2); TEST_UTIL.getConfiguration().setInt("hbase.regionserver.metahandler.count", 2); + TEST_UTIL.getConfiguration().setInt("hbasefsck.numthreads", 10); TEST_UTIL.startMiniCluster(3); executorService = new ThreadPoolExecutor(1, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, @@ -765,6 +765,7 @@ public class TestHBaseFsck { // fix the problem. HBaseFsck fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1284,6 +1285,7 @@ public class TestHBaseFsck { // fix lingering split parent hbck = new HBaseFsck(conf); + hbck.doInitial(); hbck.connect(); hbck.setDisplayFullReport(); // i.e. -details hbck.setTimeLag(0); @@ -1505,6 +1507,7 @@ public class TestHBaseFsck { // verify that noHdfsChecking report the same errors HBaseFsck fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1515,6 +1518,7 @@ public class TestHBaseFsck { // verify that fixAssignments works fine with noHdfsChecking fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1555,6 +1559,7 @@ public class TestHBaseFsck { // verify that noHdfsChecking report the same errors HBaseFsck fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1565,6 +1570,7 @@ public class TestHBaseFsck { // verify that fixMeta doesn't work with noHdfsChecking fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1613,6 +1619,7 @@ public class TestHBaseFsck { // verify that noHdfsChecking can't detect ORPHAN_HDFS_REGION HBaseFsck fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1623,6 +1630,7 @@ public class TestHBaseFsck { // verify that fixHdfsHoles doesn't work with noHdfsChecking fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -1724,8 +1732,8 @@ public class TestHBaseFsck { String[] args = {"-sidelineCorruptHFiles", "-repairHoles", "-ignorePreCheckPermission", table.getNameAsString()}; - ExecutorService exec = new ScheduledThreadPoolExecutor(10); - HBaseFsck res = hbck.exec(exec, args); + hbck.doInitial(); + HBaseFsck res = hbck.exec(args); HFileCorruptionChecker hfcc = res.getHFilecorruptionChecker(); assertEquals(hfcc.getHFilesChecked(), check); @@ -1757,10 +1765,9 @@ public class TestHBaseFsck { @Test(timeout=120000) public void testQuarantineMissingHFile() throws Exception { TableName table = TableName.valueOf(name.getMethodName()); - ExecutorService exec = new ScheduledThreadPoolExecutor(10); // inject a fault in the hfcc created. final FileSystem fs = FileSystem.get(conf); - HBaseFsck hbck = new HBaseFsck(conf, exec) { + HBaseFsck hbck = new HBaseFsck(conf) { @Override public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles) throws IOException { return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) { @@ -1788,10 +1795,9 @@ public class TestHBaseFsck { @Ignore @Test(timeout=120000) public void testQuarantineMissingFamdir() throws Exception { TableName table = TableName.valueOf(name.getMethodName()); - ExecutorService exec = new ScheduledThreadPoolExecutor(10); // inject a fault in the hfcc created. final FileSystem fs = FileSystem.get(conf); - HBaseFsck hbck = new HBaseFsck(conf, exec) { + HBaseFsck hbck = new HBaseFsck(conf) { @Override public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles) throws IOException { return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) { @@ -1817,10 +1823,9 @@ public class TestHBaseFsck { @Test(timeout=120000) public void testQuarantineMissingRegionDir() throws Exception { TableName table = TableName.valueOf(name.getMethodName()); - ExecutorService exec = new ScheduledThreadPoolExecutor(10); // inject a fault in the hfcc created. final FileSystem fs = FileSystem.get(conf); - HBaseFsck hbck = new HBaseFsck(conf, exec) { + HBaseFsck hbck = new HBaseFsck(conf) { @Override public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles) throws IOException { return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java index 1f6ec70..a879bc6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/hbck/HbckTestingUtil.java @@ -22,17 +22,15 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import com.google.common.collect.Lists; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.util.HBaseFsck; import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE; +import com.google.common.collect.Lists; + public class HbckTestingUtil { - private static ExecutorService exec = new ScheduledThreadPoolExecutor(10); public static HBaseFsck doFsck( Configuration conf, boolean fix) throws Exception { return doFsck(conf, fix, null); @@ -48,7 +46,8 @@ public class HbckTestingUtil { boolean fixHdfsOrphans, boolean fixTableOrphans, boolean fixVersionFile, boolean fixReferenceFiles, boolean fixEmptyMetaRegionInfo, boolean fixTableLocks, TableName table) throws Exception { - HBaseFsck fsck = new HBaseFsck(conf, exec); + HBaseFsck fsck = new HBaseFsck(conf); + fsck.doInitial(); fsck.connect(); fsck.setDisplayFullReport(); // i.e. -details fsck.setTimeLag(0); @@ -78,8 +77,9 @@ public class HbckTestingUtil { */ public static HBaseFsck doHFileQuarantine(Configuration conf, TableName table) throws Exception { String[] args = {"-sidelineCorruptHFiles", "-ignorePreCheckPermission", table.getNameAsString()}; - HBaseFsck hbck = new HBaseFsck(conf, exec); - hbck.exec(exec, args); + HBaseFsck hbck = new HBaseFsck(conf); + hbck.doInitial(); + hbck.exec(args); return hbck; }