Skip to content

Commit 1c095a7

Browse files
charlesconnellApache9
authored andcommitted
HBASE-29363 CompactSplit should not attempt to split secondary region replicas (#7048)
Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit ae5400e)
1 parent 4ceb1d1 commit 1c095a7

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-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: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
import org.apache.hadoop.hbase.TableName;
3131
import org.apache.hadoop.hbase.client.Connection;
3232
import org.apache.hadoop.hbase.client.ConnectionFactory;
33+
import org.apache.hadoop.hbase.client.TableDescriptor;
34+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
3335
import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
3436
import org.apache.hadoop.hbase.testclassification.MediumTests;
3537
import org.apache.hadoop.hbase.util.Bytes;
3638
import org.apache.hadoop.hbase.util.CommonFSUtils;
3739
import org.junit.After;
38-
import org.junit.AfterClass;
3940
import org.junit.Assert;
40-
import org.junit.BeforeClass;
41+
import org.junit.Before;
4142
import org.junit.ClassRule;
4243
import org.junit.Test;
4344
import org.junit.experimental.categories.Category;
@@ -63,8 +64,8 @@ public class TestCompactSplitThread {
6364
/**
6465
* Setup the config for the cluster
6566
*/
66-
@BeforeClass
67-
public static void setupCluster() throws Exception {
67+
@Before
68+
public void setupCluster() throws Exception {
6869
setupConf(TEST_UTIL.getConfiguration());
6970
TEST_UTIL.startMiniCluster(NUM_RS);
7071
fs = TEST_UTIL.getDFSCluster().getFileSystem();
@@ -91,12 +92,7 @@ private static void setupConf(Configuration conf) {
9192
}
9293

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

0 commit comments

Comments
 (0)