Skip to content

Commit df90a4b

Browse files
committed
HBASE-26242 Allow split when store file count larger than the configed blocking file count (#3652)
Signed-off-by: Andrew Purtell <apurtell@apache.org>
1 parent b5ac638 commit df90a4b

File tree

3 files changed

+169
-7
lines changed

3 files changed

+169
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ public String dumpQueue() {
200200
}
201201

202202
public synchronized boolean requestSplit(final Region r) {
203-
// don't split regions that are blocking
203+
// Don't split regions that are blocking is the default behavior.
204+
// But in some circumstances, split here is needed to prevent the region size from
205+
// continuously growing, as well as the number of store files, see HBASE-26242.
204206
HRegion hr = (HRegion)r;
205207
try {
206208
if (shouldSplitRegion() && hr.getCompactPriority() >= PRIORITY_USER) {
@@ -218,14 +220,14 @@ public synchronized boolean requestSplit(final Region r) {
218220
return false;
219221
}
220222

221-
public synchronized void requestSplit(final Region r, byte[] midKey) {
223+
private synchronized void requestSplit(final Region r, byte[] midKey) {
222224
requestSplit(r, midKey, null);
223225
}
224226

225227
/*
226228
* The User parameter allows the split thread to assume the correct user identity
227229
*/
228-
public synchronized void requestSplit(final Region r, byte[] midKey, User user) {
230+
private synchronized void requestSplit(final Region r, byte[] midKey, User user) {
229231
if (midKey == null) {
230232
LOG.debug("Region " + r.getRegionInfo().getRegionNameAsString() +
231233
" not splittable because midkey=null");
@@ -487,9 +489,9 @@ public int getSplitQueueSize() {
487489
}
488490

489491
private boolean shouldSplitRegion() {
490-
if(server.getNumberOfOnlineRegions() > 0.9*regionSplitLimit) {
492+
if (server.getNumberOfOnlineRegions() > 0.9 * regionSplitLimit) {
491493
LOG.warn("Total number of regions is approaching the upper limit " + regionSplitLimit + ". "
492-
+ "Please consider taking a look at http://hbase.apache.org/book.html#ops.regionmgt");
494+
+ "Please consider taking a look at http://hbase.apache.org/book.html#ops.regionmgt");
493495
}
494496
return (regionSplitLimit > server.getNumberOfOnlineRegions());
495497
}
@@ -657,11 +659,14 @@ private void doCompaction(User user) {
657659
this + "; duration=" + StringUtils.formatTimeDiff(now, start));
658660
if (completed) {
659661
// degenerate case: blocked regions require recursive enqueues
660-
if (store.getCompactPriority() <= 0) {
662+
if (region.getCompactPriority() < Store.PRIORITY_USER
663+
&& store.getCompactPriority() <= 0) {
661664
requestSystemCompaction(region, store, "Recursive enqueue");
662665
} else {
663666
// see if the compaction has caused us to exceed max region size
664-
requestSplit(region);
667+
if (!requestSplit(region) && store.getCompactPriority() <= 0) {
668+
requestSystemCompaction(region, store, "Recursive enqueue");
669+
}
665670
}
666671
}
667672
} catch (IOException ex) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
267267
public static final String COMPACTION_AFTER_BULKLOAD_ENABLE =
268268
"hbase.compaction.after.bulkload.enable";
269269

270+
/** Config for allow split when file count greater than the configured blocking file count*/
271+
public static final String SPLIT_IGNORE_BLOCKING_ENABLED_KEY =
272+
"hbase.hregion.split.ignore.blocking.enabled";
273+
270274
/**
271275
* This is for for using HRegion as a local storage, where we may put the recovered edits in a
272276
* special place. Once this is set, we will only replay the recovered edits under this directory
@@ -8196,6 +8200,10 @@ public Optional<byte[]> checkSplit(boolean force) {
81968200
* @return The priority that this region should have in the compaction queue
81978201
*/
81988202
public int getCompactPriority() {
8203+
if (conf.getBoolean(SPLIT_IGNORE_BLOCKING_ENABLED_KEY, false) && checkSplit().isPresent()) {
8204+
// if a region should split, split it before compact
8205+
return Store.PRIORITY_USER;
8206+
}
81998207
return stores.values().stream().mapToInt(HStore::getCompactPriority).min()
82008208
.orElse(Store.NO_PRIORITY);
82018209
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.regionserver;
19+
20+
import static org.apache.hadoop.hbase.regionserver.HRegion.SPLIT_IGNORE_BLOCKING_ENABLED_KEY;
21+
import static org.apache.hadoop.hbase.regionserver.Store.PRIORITY_USER;
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertFalse;
24+
import static org.junit.Assert.assertNotNull;
25+
import static org.junit.Assert.assertTrue;
26+
import java.util.List;
27+
import org.apache.hadoop.hbase.HBaseClassTestRule;
28+
import org.apache.hadoop.hbase.HBaseTestingUtility;
29+
import org.apache.hadoop.hbase.HConstants;
30+
import org.apache.hadoop.hbase.TableName;
31+
import org.apache.hadoop.hbase.client.Admin;
32+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
33+
import org.apache.hadoop.hbase.client.Put;
34+
import org.apache.hadoop.hbase.client.ResultScanner;
35+
import org.apache.hadoop.hbase.client.Scan;
36+
import org.apache.hadoop.hbase.client.Table;
37+
import org.apache.hadoop.hbase.client.TableDescriptor;
38+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
39+
import org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure;
40+
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
41+
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
42+
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
43+
import org.apache.hadoop.hbase.testclassification.MediumTests;
44+
import org.apache.hadoop.hbase.util.Bytes;
45+
import org.junit.AfterClass;
46+
import org.junit.Assert;
47+
import org.junit.BeforeClass;
48+
import org.junit.ClassRule;
49+
import org.junit.Test;
50+
import org.junit.experimental.categories.Category;
51+
import org.slf4j.Logger;
52+
import org.slf4j.LoggerFactory;
53+
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
54+
55+
@Category({ MediumTests.class})
56+
public class TestSplitWithBlockingFiles {
57+
58+
@ClassRule
59+
public static final HBaseClassTestRule CLASS_RULE =
60+
HBaseClassTestRule.forClass(TestSplitWithBlockingFiles.class);
61+
62+
private static final Logger LOG = LoggerFactory.getLogger(TestSplitWithBlockingFiles.class);
63+
64+
protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
65+
private static TableName TABLE_NAME = TableName.valueOf("test");
66+
private static Admin ADMIN;
67+
private static byte[] CF = Bytes.toBytes("cf");
68+
private static Table TABLE;
69+
70+
71+
@BeforeClass
72+
public static void setupCluster() throws Exception {
73+
UTIL.getConfiguration().setLong(HConstants.HREGION_MAX_FILESIZE, 8 * 2 * 10240L);
74+
UTIL.getConfiguration().setInt(HStore.BLOCKING_STOREFILES_KEY, 1);
75+
UTIL.getConfiguration().set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
76+
ConstantSizeRegionSplitPolicy.class.getName());
77+
UTIL.getConfiguration().setBoolean(SPLIT_IGNORE_BLOCKING_ENABLED_KEY, true);
78+
UTIL.startMiniCluster(1);
79+
ADMIN = UTIL.getAdmin();
80+
TableDescriptor td = TableDescriptorBuilder.newBuilder(TABLE_NAME)
81+
.setColumnFamily(
82+
ColumnFamilyDescriptorBuilder.newBuilder(CF).setBlocksize(1000).build()).build();
83+
TABLE = UTIL.createTable(td, null);
84+
UTIL.waitTableAvailable(TABLE_NAME);
85+
}
86+
87+
@AfterClass
88+
public static void cleanupTest() throws Exception {
89+
Closeables.close(TABLE, true);
90+
UTIL.shutdownMiniCluster();
91+
}
92+
93+
@Test
94+
public void testSplitIgnoreBlockingFiles() throws Exception {
95+
ADMIN.splitSwitch(false, true);
96+
byte[] value = new byte[1024];
97+
for (int m = 0; m < 10; m++) {
98+
String rowPrefix = "row" + m;
99+
for (int i = 0; i < 10; i++) {
100+
Put p = new Put(Bytes.toBytes(rowPrefix + i));
101+
p.addColumn(CF, Bytes.toBytes("qualifier"), value);
102+
p.addColumn(CF, Bytes.toBytes("qualifier2"), value);
103+
TABLE.put(p);
104+
}
105+
ADMIN.flush(TABLE_NAME);
106+
}
107+
Scan scan = new Scan();
108+
ResultScanner results = TABLE.getScanner(scan);
109+
int count = 0;
110+
while (results.next() != null) {
111+
count++;
112+
}
113+
Assert.assertEquals("There should be 100 rows!", 100, count);
114+
List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegionServer(0).getRegions();
115+
regions.removeIf(r -> !r.getRegionInfo().getTable().equals(TABLE_NAME));
116+
assertEquals(1, regions.size());
117+
assertNotNull(regions.get(0).getSplitPolicy().getSplitPoint());
118+
assertTrue(regions.get(0).getCompactPriority() >= PRIORITY_USER);
119+
assertTrue(UTIL.getMiniHBaseCluster().getRegionServer(0).getCompactSplitThread()
120+
.requestSplit(regions.get(0)));
121+
122+
// split region
123+
ADMIN.splitSwitch(true, true);
124+
MasterProcedureEnv env =
125+
UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment();
126+
final ProcedureExecutor<MasterProcedureEnv> executor =
127+
UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
128+
SplitTableRegionProcedure splitProcedure =
129+
new SplitTableRegionProcedure(env, regions.get(0).getRegionInfo(), Bytes.toBytes("row5"));
130+
executor.submitProcedure(splitProcedure);
131+
ProcedureTestingUtility.waitProcedure(executor, splitProcedure.getProcId());
132+
133+
regions = UTIL.getMiniHBaseCluster().getRegionServer(0).getRegions();
134+
regions.removeIf(r -> !r.getRegionInfo().getTable().equals(TABLE_NAME));
135+
assertEquals(2, regions.size());
136+
scan = new Scan();
137+
results = TABLE.getScanner(scan);
138+
count = 0;
139+
while (results.next() != null) {
140+
count++;
141+
}
142+
Assert.assertEquals("There should be 100 rows!", 100, count);
143+
for (HRegion region : regions) {
144+
assertTrue(region.getCompactPriority() < PRIORITY_USER);
145+
assertFalse(
146+
UTIL.getMiniHBaseCluster().getRegionServer(0).getCompactSplitThread().requestSplit(region));
147+
}
148+
}
149+
}

0 commit comments

Comments
 (0)