Skip to content

Commit ae5400e

Browse files
HBASE-29363 CompactSplit should not attempt to split secondary region replicas (#7048)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 97cf65d commit ae5400e

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplit.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.concurrent.atomic.AtomicInteger;
3737
import java.util.function.IntSupplier;
3838
import org.apache.hadoop.conf.Configuration;
39+
import org.apache.hadoop.hbase.client.RegionInfo;
3940
import org.apache.hadoop.hbase.conf.ConfigurationManager;
4041
import org.apache.hadoop.hbase.conf.PropagatingConfigurationObserver;
4142
import org.apache.hadoop.hbase.quotas.RegionServerSpaceQuotaManager;
@@ -205,7 +206,7 @@ public synchronized boolean requestSplit(final Region r) {
205206
// continuously growing, as well as the number of store files, see HBASE-26242.
206207
HRegion hr = (HRegion) r;
207208
try {
208-
if (shouldSplitRegion() && hr.getCompactPriority() >= PRIORITY_USER) {
209+
if (shouldSplitRegion(r.getRegionInfo()) && hr.getCompactPriority() >= PRIORITY_USER) {
209210
byte[] midKey = hr.checkSplit().orElse(null);
210211
if (midKey != null) {
211212
requestSplit(r, midKey);
@@ -503,12 +504,15 @@ public int getSplitQueueSize() {
503504
return splits.getQueue().size();
504505
}
505506

506-
private boolean shouldSplitRegion() {
507+
private boolean shouldSplitRegion(RegionInfo ri) {
507508
if (server.getNumberOfOnlineRegions() > 0.9 * regionSplitLimit) {
508509
LOG.warn("Total number of regions is approaching the upper limit " + regionSplitLimit + ". "
509510
+ "Please consider taking a look at http://hbase.apache.org/book.html#ops.regionmgt");
510511
}
511-
return (regionSplitLimit > server.getNumberOfOnlineRegions());
512+
return (regionSplitLimit > server.getNumberOfOnlineRegions()
513+
// Do not attempt to split secondary region replicas, as this is not allowed and our request
514+
// to do so will be rejected
515+
&& ri.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID);
512516
}
513517

514518
/** Returns the regionSplitLimit */
@@ -807,6 +811,11 @@ protected int getSplitThreadNum() {
807811
return this.splits.getCorePoolSize();
808812
}
809813

814+
/** Exposed for unit testing */
815+
long getSubmittedSplitsCount() {
816+
return this.splits.getTaskCount();
817+
}
818+
810819
/**
811820
* {@inheritDoc}
812821
*/

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactSplitThread.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
import org.apache.hadoop.hbase.util.Bytes;
3737
import org.apache.hadoop.hbase.util.CommonFSUtils;
3838
import org.junit.After;
39-
import org.junit.AfterClass;
4039
import org.junit.Assert;
41-
import org.junit.BeforeClass;
40+
import org.junit.Before;
4241
import org.junit.ClassRule;
4342
import org.junit.Test;
4443
import org.junit.experimental.categories.Category;
@@ -64,8 +63,8 @@ public class TestCompactSplitThread {
6463
/**
6564
* Setup the config for the cluster
6665
*/
67-
@BeforeClass
68-
public static void setupCluster() throws Exception {
66+
@Before
67+
public void setupCluster() throws Exception {
6968
setupConf(TEST_UTIL.getConfiguration());
7069
TEST_UTIL.startMiniCluster(NUM_RS);
7170
fs = TEST_UTIL.getDFSCluster().getFileSystem();
@@ -92,12 +91,7 @@ private static void setupConf(Configuration conf) {
9291
}
9392

9493
@After
95-
public void tearDown() throws Exception {
96-
TEST_UTIL.deleteTable(tableName);
97-
}
98-
99-
@AfterClass
100-
public static void cleanupTest() throws Exception {
94+
public void cleanupTest() throws Exception {
10195
try {
10296
TEST_UTIL.shutdownMiniCluster();
10397
} catch (Exception e) {
@@ -173,4 +167,22 @@ public void testFlushWithTableCompactionDisabled() throws Exception {
173167
Collection<String> hfiles = SnapshotTestingUtils.listHFileNames(fs, tableDir);
174168
assert (hfiles.size() > blockingStoreFiles + 1);
175169
}
170+
171+
@Test
172+
public void testFlushWithRegionReplicas() throws Exception {
173+
TableDescriptor htd =
174+
TableDescriptorBuilder.newBuilder(tableName).setRegionReplication(2).build();
175+
TEST_UTIL.createTable(htd, new byte[][] { family }, null);
176+
177+
// load the table
178+
for (int i = 0; i < blockingStoreFiles + 1; i++) {
179+
TEST_UTIL.loadTable(TEST_UTIL.getConnection().getTable(tableName), family);
180+
TEST_UTIL.flush(tableName);
181+
}
182+
183+
// One region split should have taken place, because the primary replica gets split, and not the
184+
// secondary replica.
185+
assertEquals(1, TEST_UTIL.getRSForFirstRegionInTable(tableName).getCompactSplitThread()
186+
.getSubmittedSplitsCount());
187+
}
176188
}

0 commit comments

Comments
 (0)