Skip to content

Commit

Permalink
HBASE-24581 Skip compaction request/check for replica regions at the …
Browse files Browse the repository at this point in the history
…early stage. (#1986)

Signed-off-by: Nick Dimiduk <[email protected]>
  • Loading branch information
huaxiangsun authored Jul 14, 2020
1 parent 1360bee commit 2505c77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,11 @@ private static class CompactionChecker extends ScheduledChore {
@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 {
Expand Down Expand Up @@ -2289,9 +2291,12 @@ public void postOpenDeployTasks(final PostOpenDeployContext context) throws IOEx
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
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;
Expand Down Expand Up @@ -78,13 +80,14 @@ private static Table createTableAndLoadData(final TableName tableName) throws IO
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);
}

Expand All @@ -109,11 +112,16 @@ public void testRegionReplicaSplitRegionAssignment() throws Exception {
}
}
// 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++;
}
}
Expand Down

0 comments on commit 2505c77

Please sign in to comment.