From fd5a5fb90755949a90c502c76de8313130403fa3 Mon Sep 17 00:00:00 2001 From: haosen chen <99318736+haosenchen@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:32:51 +0800 Subject: [PATCH] HBASE-28935 [HBCK2] filesystem command always report region hole and doesn't exit automatically (#147) Co-authored-by: haosenchen --- .../src/main/java/org/apache/hbase/FileSystemFsck.java | 6 ++++++ .../src/main/java/org/apache/hbase/hbck1/HBaseFsck.java | 6 +++++- .../java/org/apache/hbase/TestHBCKCommandLineParsing.java | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/FileSystemFsck.java b/hbase-hbck2/src/main/java/org/apache/hbase/FileSystemFsck.java index d2f63f94e7..d49cea5e80 100644 --- a/hbase-hbck2/src/main/java/org/apache/hbase/FileSystemFsck.java +++ b/hbase-hbck2/src/main/java/org/apache/hbase/FileSystemFsck.java @@ -77,6 +77,12 @@ int fsck(List tables, boolean fix) throws IOException { * hbaseFsck.setFixHdfsOrphans(fix); hbaseFsck.setFixHdfsHoles(fix); * hbaseFsck.setFixHdfsOverlaps(fix); hbaseFsck.setFixTableOrphans(fix); */ + if (!tables.isEmpty()) { + tables.stream().map(TableName::valueOf).forEach(hbaseFsck::includeTable); + } + if (!tableDirs.isEmpty()) { + tableDirs.forEach(hbaseFsck::includeTableDir); + } hbaseFsck.offlineHbck(); } catch (ClassNotFoundException | InterruptedException e) { throw new IOException(e); diff --git a/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java b/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java index 2fb31f293f..860b736b6d 100644 --- a/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java +++ b/hbase-hbck2/src/main/java/org/apache/hbase/hbck1/HBaseFsck.java @@ -374,7 +374,7 @@ public HBaseFsck(Configuration conf) throws IOException, ClassNotFoundException private static ExecutorService createThreadPool(Configuration conf) { int numThreads = conf.getInt("hbasefsck.numthreads", MAX_NUM_THREADS); return new ScheduledThreadPoolExecutor(numThreads, - new ThreadFactoryBuilder().setNameFormat("hbasefsck-%d") + new ThreadFactoryBuilder().setNameFormat("hbasefsck-%d").setDaemon(true) .setUncaughtExceptionHandler(Threads.LOGGING_EXCEPTION_HANDLER).build()); } @@ -4990,6 +4990,10 @@ Set getIncludedTables() { return new HashSet<>(tablesIncluded); } + public void includeTableDir(Path tableDir) { + tableDirs.add(tableDir); + } + /** * We are interested in only those tables that have not changed their state in hbase:meta during * the last few seconds specified by hbase.admin.fsck.timelag diff --git a/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCKCommandLineParsing.java b/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCKCommandLineParsing.java index ec56b94322..3dd8f05214 100644 --- a/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCKCommandLineParsing.java +++ b/hbase-hbck2/src/test/java/org/apache/hbase/TestHBCKCommandLineParsing.java @@ -32,6 +32,9 @@ import java.io.PrintStream; import java.util.Properties; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -61,6 +64,10 @@ public static void afterClass() throws Exception { @Before public void before() throws Exception { this.hbck2 = new HBCK2(TEST_UTIL.getConfiguration()); + if (!TEST_UTIL.getAdmin().tableExists(TableName.valueOf("table"))) { + TEST_UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(TableName.valueOf("table")) + .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build()); + } } @Test