From 3fd348b4ee8015e8205768b278bafe3c2e0fbd52 Mon Sep 17 00:00:00 2001 From: LiangJun He <2005hithlj@163.com> Date: Wed, 12 Oct 2022 14:40:05 +0800 Subject: [PATCH] HBASE-27405 Fix the replication hfile/log cleaner report that the replication table does not exist (#4811) Signed-off-by: Duo Zhang --- .../hbase/replication/ReplicationQueueStorage.java | 6 ++++++ .../hbase/replication/TableReplicationQueueStorage.java | 9 +++++++++ .../hbase/replication/master/ReplicationLogCleaner.java | 8 ++++++++ .../replication/master/TestReplicationLogCleaner.java | 1 + 4 files changed, 24 insertions(+) diff --git a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationQueueStorage.java b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationQueueStorage.java index c4204f0e8c45..6f6aee38cc8f 100644 --- a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationQueueStorage.java +++ b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ReplicationQueueStorage.java @@ -178,4 +178,10 @@ void removeLastSequenceIds(String peerId, List encodedRegionNames) * created hfile references during the call may not be included. */ Set getAllHFileRefs() throws ReplicationException; + + /** + * Whether the replication queue table exists. + * @return Whether the replication queue table exists + */ + boolean hasData() throws ReplicationException; } diff --git a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/TableReplicationQueueStorage.java b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/TableReplicationQueueStorage.java index 0c9553f4fd89..392a3692d66f 100644 --- a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/TableReplicationQueueStorage.java +++ b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/TableReplicationQueueStorage.java @@ -532,4 +532,13 @@ public Set getAllHFileRefs() throws ReplicationException { throw new ReplicationException("failed to getAllHFileRefs", e); } } + + @Override + public boolean hasData() throws ReplicationException { + try { + return conn.getAdmin().getDescriptor(tableName) != null; + } catch (IOException e) { + throw new ReplicationException("failed to get replication queue table", e); + } + } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java index f1fd8f8d6b3a..3ab52da6158e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/master/ReplicationLogCleaner.java @@ -76,6 +76,14 @@ public void preClean() { if (this.getConf() == null) { return; } + try { + if (!rpm.getQueueStorage().hasData()) { + return; + } + } catch (ReplicationException e) { + LOG.error("Error occurred while executing queueStorage.hasData()", e); + return; + } canFilter = rpm.getReplicationLogCleanerBarrier().start(); if (canFilter) { notFullyDeadServers = getNotFullyDeadServers.get(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestReplicationLogCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestReplicationLogCleaner.java index 7a227fb0603d..7edadae03b14 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestReplicationLogCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestReplicationLogCleaner.java @@ -86,6 +86,7 @@ public void setUp() throws ReplicationException { when(rpm.listPeers(null)).thenReturn(new ArrayList<>()); ReplicationQueueStorage rqs = mock(ReplicationQueueStorage.class); when(rpm.getQueueStorage()).thenReturn(rqs); + when(rpm.getQueueStorage().hasData()).thenReturn(true); when(rqs.listAllQueues()).thenReturn(new ArrayList<>()); ServerManager sm = mock(ServerManager.class); when(services.getServerManager()).thenReturn(sm);