Skip to content

Commit d851642

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

File tree

3 files changed

+102
-12
lines changed

3 files changed

+102
-12
lines changed

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,38 @@ protected void configureForRegion(HRegion region) {
7070

7171
@Override
7272
protected boolean shouldSplit() {
73-
boolean force = region.shouldForceSplit();
74-
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+
}
80+
if (region.shouldForceSplit()) {
81+
return true;
82+
}
7583
// Get count of regions that have the same common table as this.region
7684
int tableRegionsCount = getCountOfCommonTableRegions();
7785
// Get size to check
7886
long sizeToCheck = getSizeToCheck(tableRegionsCount);
87+
return isExceedSize(tableRegionsCount, sizeToCheck);
88+
}
7989

90+
/**
91+
* @return true if any store's size exceed the sizeToCheck
92+
*/
93+
protected boolean isExceedSize(int tableRegionsCount, long sizeToCheck) {
8094
for (HStore store : region.getStores()) {
81-
// If any of the stores is unable to split (eg they contain reference files)
82-
// then don't split
83-
if (!store.canSplit()) {
84-
return false;
85-
}
86-
87-
// Mark if any store is big enough
8895
long size = store.getSize();
8996
if (size > sizeToCheck) {
9097
LOG.debug("ShouldSplit because " + store.getColumnFamilyName() +
9198
" size=" + StringUtils.humanSize(size) +
9299
", sizeToCheck=" + StringUtils.humanSize(sizeToCheck) +
93100
", regionsWithCommonTable=" + tableRegionsCount);
94-
foundABigStore = true;
101+
return true;
95102
}
96103
}
97-
98-
return foundABigStore || force;
104+
return false;
99105
}
100106

101107
/**
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=" + StringUtils.humanSize(sumSize) +
42+
", sizeToCheck=" + StringUtils.humanSize(sizeToCheck) +
43+
", regionsWithCommonTable=" + 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
@@ -161,6 +161,41 @@ public void testIncreasingToUpperBoundRegionSplitPolicy() throws IOException {
161161
assertWithinJitter(maxSplitSize, policy.getSizeToCheck(0));
162162
}
163163

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

0 commit comments

Comments
 (0)