From 2505c7760de66535b89de493326e9f2b800d8c3f Mon Sep 17 00:00:00 2001 From: huaxiangsun Date: Tue, 14 Jul 2020 15:49:20 -0700 Subject: [PATCH] HBASE-24581 Skip compaction request/check for replica regions at the early stage. (#1986) Signed-off-by: Nick Dimiduk --- .../hadoop/hbase/regionserver/HRegionServer.java | 13 +++++++++---- .../master/assignment/TestRegionReplicaSplit.java | 14 +++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 1e38e8ab002..99fddf67ecd 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1781,9 +1781,11 @@ public class HRegionServer extends Thread implements @Override protected void chore() { for (Region r : this.instance.onlineRegions.values()) { - if (r == null) { + // Skip compaction if region is read only + if (r == null || r.isReadOnly()) { continue; } + HRegion hr = (HRegion) r; for (HStore s : hr.stores.values()) { try { @@ -2289,9 +2291,12 @@ public class HRegionServer extends Thread implements LOG.info("Post open deploy tasks for {}, pid={}, masterSystemTime={}", r.getRegionInfo().getRegionNameAsString(), openProcId, masterSystemTime); // Do checks to see if we need to compact (references or too many files) - for (HStore s : r.stores.values()) { - if (s.hasReferences() || s.needsCompaction()) { - this.compactSplitThread.requestSystemCompaction(r, s, "Opening Region"); + // Skip compaction check if region is read only + if (!r.isReadOnly()) { + for (HStore s : r.stores.values()) { + if (s.hasReferences() || s.needsCompaction()) { + this.compactSplitThread.requestSystemCompaction(r, s, "Opening Region"); + } } } long openSeqNum = r.getOpenSeqNum(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionReplicaSplit.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionReplicaSplit.java index 0d3790f7f77..202d99e56ee 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionReplicaSplit.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionReplicaSplit.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.master.assignment; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -31,6 +32,7 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.hadoop.hbase.client.RegionReplicaTestHelper; +import org.apache.hadoop.hbase.client.RegionReplicaUtil; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.regionserver.HRegionServer; @@ -78,13 +80,14 @@ public class TestRegionReplicaSplit { Table table = HTU.createTable(builder.build(), new byte[][] { f }, getSplits(2), new Configuration(HTU.getConfiguration())); HTU.loadTable(HTU.getConnection().getTable(tableName), f); + HTU.flush(tableName); return table; } private static byte[][] getSplits(int numRegions) { RegionSplitter.UniformSplit split = new RegionSplitter.UniformSplit(); - split.setFirstRow(Bytes.toBytes(0L)); - split.setLastRow(Bytes.toBytes(Long.MAX_VALUE)); + split.setFirstRow(Bytes.toBytes("a")); + split.setLastRow(Bytes.toBytes("z")); return split.split(numRegions); } @@ -109,11 +112,16 @@ public class TestRegionReplicaSplit { } } // There are 6 regions before split, 9 regions after split. - HTU.getAdmin().split(table.getName(), Bytes.toBytes(1)); + HTU.getAdmin().split(table.getName(), Bytes.toBytes("d")); int count = 0; while (true) { for (RegionServerThread rs : HTU.getMiniHBaseCluster().getRegionServerThreads()) { for (Region r : rs.getRegionServer().getRegions(table.getName())) { + // Make sure that every region has some data (even for split daughter regions). + if (RegionReplicaUtil.isDefaultReplica(r.getRegionInfo())) { + assertTrue(r.getStore(f).hasReferences() || + r.getStore(f).getStorefiles().size() > 0); + } count++; } }