From a741c7348abc45a1943322ec4b08f8f189598c9d Mon Sep 17 00:00:00 2001 From: guluo Date: Sat, 24 Feb 2024 21:45:29 +0800 Subject: [PATCH 1/2] Checking if the hbase replication table exists before calling the method checkAndFixReplication() --- .../apache/hadoop/hbase/util/HBaseFsck.java | 7 +- ...HBaseFsckWithoutTableHbaseReplication.java | 67 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java 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 31020cf4bce5..4cc8539884ef 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 @@ -800,7 +800,12 @@ public int onlineHbck() checkRegionBoundaries(); } - checkAndFixReplication(); + TableName hbaseReplicationTable = + TableName.valueOf(getConf().get(ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME, + ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME_DEFAULT.getNameAsString())); + if (admin.tableExists(hbaseReplicationTable)) { + checkAndFixReplication(); + } cleanReplicationBarrier(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java new file mode 100644 index 000000000000..86d98f962643 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtil; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.Admin; +import org.apache.hadoop.hbase.replication.ReplicationStorageFactory; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.MiscTests; +import org.apache.hadoop.hbase.util.hbck.HbckTestingUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category({ MiscTests.class, MediumTests.class }) +public class TestHBaseFsckWithoutTableHbaseReplication { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestHBaseFsckWithoutTableHbaseReplication.class); + + private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); + + @Before + public void setUp() throws Exception { + UTIL.getConfiguration().setBoolean("hbase.write.hbck1.lock.file", false); + UTIL.startMiniCluster(1); + } + + @After + public void tearDown() throws Exception { + UTIL.shutdownMiniCluster(); + } + + @Test + public void test() throws Exception { + Admin admin = UTIL.getAdmin(); + TableName tableName = TableName + .valueOf(UTIL.getConfiguration().get(ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME, + ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME_DEFAULT.getNameAsString())); + assertFalse(admin.tableExists(tableName)); + HBaseFsck hBaseFsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), true); + assertEquals(0, hBaseFsck.getRetCode()); + } +} From 0da9ed38f537a270577554fb83c6596d268a869f Mon Sep 17 00:00:00 2001 From: guluo Date: Mon, 26 Feb 2024 20:23:20 +0800 Subject: [PATCH 2/2] update check --- .../org/apache/hadoop/hbase/util/HBaseFsck.java | 12 ++++++------ .../hbase/util/hbck/ReplicationChecker.java | 4 ++++ ...TestHBaseFsckWithoutTableHbaseReplication.java | 15 +++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) 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 4cc8539884ef..0d24ef783762 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 @@ -800,12 +800,7 @@ public int onlineHbck() checkRegionBoundaries(); } - TableName hbaseReplicationTable = - TableName.valueOf(getConf().get(ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME, - ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME_DEFAULT.getNameAsString())); - if (admin.tableExists(hbaseReplicationTable)) { - checkAndFixReplication(); - } + checkAndFixReplication(); cleanReplicationBarrier(); @@ -2577,6 +2572,11 @@ private synchronized HbckRegionInfo getOrCreateInfo(String name) { private void checkAndFixReplication() throws ReplicationException, IOException { ReplicationChecker checker = new ReplicationChecker(getConf(), zkw, connection, errors); + + if (!checker.checkHasDataInQueues()) { + return; + } + checker.checkUnDeletedQueues(); if (checker.hasUnDeletedQueues() && this.fixReplication) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/ReplicationChecker.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/ReplicationChecker.java index 497304a31113..f92631eb7924 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/ReplicationChecker.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/ReplicationChecker.java @@ -130,4 +130,8 @@ public void fixUnDeletedQueues() throws ReplicationException { queueStorage.removePeerFromHFileRefs(peerId); } } + + public boolean checkHasDataInQueues() throws ReplicationException { + return queueStorage.hasData(); + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java index 86d98f962643..279962c934fd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckWithoutTableHbaseReplication.java @@ -23,7 +23,6 @@ import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.replication.ReplicationStorageFactory; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MiscTests; @@ -33,6 +32,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; @Category({ MiscTests.class, MediumTests.class }) public class TestHBaseFsckWithoutTableHbaseReplication { @@ -41,11 +41,18 @@ public class TestHBaseFsckWithoutTableHbaseReplication { public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestHBaseFsckWithoutTableHbaseReplication.class); + @ClassRule + public static final TestName name = new TestName(); + private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); + private static final TableName tableName = + TableName.valueOf("replication_" + name.getMethodName()); @Before public void setUp() throws Exception { UTIL.getConfiguration().setBoolean("hbase.write.hbck1.lock.file", false); + UTIL.getConfiguration().set(ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME, + tableName.getNameAsString()); UTIL.startMiniCluster(1); } @@ -56,11 +63,7 @@ public void tearDown() throws Exception { @Test public void test() throws Exception { - Admin admin = UTIL.getAdmin(); - TableName tableName = TableName - .valueOf(UTIL.getConfiguration().get(ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME, - ReplicationStorageFactory.REPLICATION_QUEUE_TABLE_NAME_DEFAULT.getNameAsString())); - assertFalse(admin.tableExists(tableName)); + assertFalse(UTIL.getAdmin().tableExists(tableName)); HBaseFsck hBaseFsck = HbckTestingUtil.doFsck(UTIL.getConfiguration(), true); assertEquals(0, hBaseFsck.getRetCode()); }