Skip to content

Commit 6e245b4

Browse files
committed
HBASE-24530 Introduce a split policy similar with SteppingSplitPolicy but count all store size
1 parent bfec964 commit 6e245b4

File tree

3 files changed

+99
-11
lines changed

3 files changed

+99
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,35 @@ protected void configureForRegion(HRegion region) {
7070

7171
@Override
7272
protected boolean shouldSplit() {
73-
boolean foundABigStore = false;
73+
// If any of the stores is unable to split (eg they contain reference files)
74+
// then don't split
75+
for (HStore store : region.getStores()) {
76+
if (!store.canSplit()) {
77+
return false;
78+
}
79+
}
7480
// Get count of regions that have the same common table as this.region
7581
int tableRegionsCount = getCountOfCommonTableRegions();
7682
// Get size to check
7783
long sizeToCheck = getSizeToCheck(tableRegionsCount);
84+
return isExceedSize(tableRegionsCount, sizeToCheck);
85+
}
7886

87+
/**
88+
* @return true if any store's size exceed the sizeToCheck
89+
*/
90+
protected boolean isExceedSize(int tableRegionsCount, long sizeToCheck) {
7991
for (HStore store : region.getStores()) {
80-
// If any of the stores is unable to split (eg they contain reference files)
81-
// then don't split
82-
if (!store.canSplit()) {
83-
return false;
84-
}
85-
86-
// Mark if any store is big enough
8792
long size = store.getSize();
8893
if (size > sizeToCheck) {
8994
LOG.debug("ShouldSplit because " + store.getColumnFamilyName() +
9095
" size=" + StringUtils.humanSize(size) +
9196
", sizeToCheck=" + StringUtils.humanSize(sizeToCheck) +
9297
", regionsWithCommonTable=" + tableRegionsCount);
93-
foundABigStore = true;
98+
return true;
9499
}
95100
}
96-
97-
return foundABigStore;
101+
return false;
98102
}
99103

100104
/**
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 org.apache.hadoop.hbase.procedure2.util.StringUtils;
21+
import org.apache.yetus.audience.InterfaceAudience;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
@InterfaceAudience.Private
26+
public class SteppingAllStoresSizeSplitPolicy extends SteppingSplitPolicy {
27+
private static final Logger LOG =
28+
LoggerFactory.getLogger(SteppingAllStoresSizeSplitPolicy.class);
29+
30+
/**
31+
* @return true if sum of store's size exceed the sizeToCheck
32+
*/
33+
@Override
34+
protected boolean isExceedSize(int tableRegionsCount, long sizeToCheck) {
35+
long sumSize = 0;
36+
for (HStore store : region.getStores()) {
37+
sumSize += store.getSize();
38+
}
39+
if (sumSize > sizeToCheck) {
40+
LOG.debug("ShouldSplit because region size is big enough " +
41+
"size={}, sizeToCheck={}, regionsWithCommonTable={}",
42+
StringUtils.humanSize(sumSize), StringUtils.humanSize(sizeToCheck),
43+
tableRegionsCount);
44+
return true;
45+
}
46+
return false;
47+
}
48+
49+
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,41 @@ public void testIncreasingToUpperBoundRegionSplitPolicy() throws IOException {
153153
assertWithinJitter(maxSplitSize, policy.getSizeToCheck(0));
154154
}
155155

156+
@Test
157+
public void testIsExceedSize() throws IOException {
158+
// Configure SteppingAllStoresSizeSplitPolicy as our split policy
159+
conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
160+
SteppingAllStoresSizeSplitPolicy.class.getName());
161+
// Now make it so the mock region has a RegionServerService that will
162+
// return 'online regions'.
163+
RegionServerServices rss = Mockito.mock(RegionServerServices.class);
164+
final List<HRegion> regions = new ArrayList<>();
165+
Mockito.doReturn(regions).when(rss).getRegions(TABLENAME);
166+
Mockito.when(mockRegion.getRegionServerServices()).thenReturn(rss);
167+
168+
SteppingAllStoresSizeSplitPolicy policy =
169+
(SteppingAllStoresSizeSplitPolicy) RegionSplitPolicy.create(mockRegion, conf);
170+
regions.add(mockRegion);
171+
172+
HStore mockStore1 = Mockito.mock(HStore.class);
173+
Mockito.doReturn(100L).when(mockStore1).getSize();
174+
HStore mockStore2 = Mockito.mock(HStore.class);
175+
Mockito.doReturn(924L).when(mockStore2).getSize();
176+
HStore mockStore3 = Mockito.mock(HStore.class);
177+
Mockito.doReturn(925L).when(mockStore3).getSize();
178+
179+
// test sum of store's size not greater than sizeToCheck
180+
stores.add(mockStore1);
181+
stores.add(mockStore2);
182+
assertFalse(policy.isExceedSize(1, 1024));
183+
stores.clear();
184+
185+
// test sum of store's size greater than sizeToCheck
186+
stores.add(mockStore1);
187+
stores.add(mockStore3);
188+
assertTrue(policy.isExceedSize(1, 1024));
189+
}
190+
156191
@Test
157192
public void testBusyRegionSplitPolicy() throws Exception {
158193
doReturn(TableDescriptorBuilder.newBuilder(TABLENAME).build()).when(mockRegion)

0 commit comments

Comments
 (0)