Skip to content

HBASE-24530 Introduce a split policy similar with SteppingSplitPolicy… #1883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,35 @@ protected void configureForRegion(HRegion region) {

@Override
protected boolean shouldSplit() {
boolean foundABigStore = false;
// If any of the stores is unable to split (eg they contain reference files)
// then don't split
for (HStore store : region.getStores()) {
if (!store.canSplit()) {
return false;
}
}
// Get count of regions that have the same common table as this.region
int tableRegionsCount = getCountOfCommonTableRegions();
// Get size to check
long sizeToCheck = getSizeToCheck(tableRegionsCount);
return isExceedSize(tableRegionsCount, sizeToCheck);
}

/**
* @return true if any store's size exceed the sizeToCheck
*/
protected boolean isExceedSize(int tableRegionsCount, long sizeToCheck) {
for (HStore store : region.getStores()) {
// If any of the stores is unable to split (eg they contain reference files)
// then don't split
if (!store.canSplit()) {
return false;
}

// Mark if any store is big enough
long size = store.getSize();
if (size > sizeToCheck) {
LOG.debug("ShouldSplit because " + store.getColumnFamilyName() +
" size=" + StringUtils.humanSize(size) +
", sizeToCheck=" + StringUtils.humanSize(sizeToCheck) +
", regionsWithCommonTable=" + tableRegionsCount);
foundABigStore = true;
return true;
}
}

return foundABigStore;
return false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.regionserver;

import org.apache.hadoop.hbase.procedure2.util.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@InterfaceAudience.Private
public class SteppingAllStoresSizeSplitPolicy extends SteppingSplitPolicy {
private static final Logger LOG =
LoggerFactory.getLogger(SteppingAllStoresSizeSplitPolicy.class);

/**
* @return true if sum of store's size exceed the sizeToCheck
*/
@Override
protected boolean isExceedSize(int tableRegionsCount, long sizeToCheck) {
long sumSize = 0;
for (HStore store : region.getStores()) {
sumSize += store.getSize();
}
if (sumSize > sizeToCheck) {
LOG.debug("ShouldSplit because region size is big enough " +
"size={}, sizeToCheck={}, regionsWithCommonTable={}",
StringUtils.humanSize(sumSize), StringUtils.humanSize(sizeToCheck),
tableRegionsCount);
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,43 @@ public void testIncreasingToUpperBoundRegionSplitPolicy() throws IOException {
assertWithinJitter(maxSplitSize, policy.getSizeToCheck(0));
}

@Test
public void testIsExceedSize() throws IOException {
// Configure SteppingAllStoresSizeSplitPolicy as our split policy
conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY,
SteppingAllStoresSizeSplitPolicy.class.getName());
// Now make it so the mock region has a RegionServerService that will
// return 'online regions'.
RegionServerServices rss = mock(RegionServerServices.class);
final List<HRegion> regions = new ArrayList<>();
doReturn(regions).when(rss).getRegions(TABLENAME);
when(mockRegion.getRegionServerServices()).thenReturn(rss);

TableDescriptor td = TableDescriptorBuilder.newBuilder(TABLENAME).build();
doReturn(td).when(mockRegion).getTableDescriptor();
SteppingAllStoresSizeSplitPolicy policy =
(SteppingAllStoresSizeSplitPolicy) RegionSplitPolicy.create(mockRegion, conf);
regions.add(mockRegion);

HStore mockStore1 = mock(HStore.class);
doReturn(100L).when(mockStore1).getSize();
HStore mockStore2 = mock(HStore.class);
doReturn(924L).when(mockStore2).getSize();
HStore mockStore3 = mock(HStore.class);
doReturn(925L).when(mockStore3).getSize();

// test sum of store's size not greater than sizeToCheck
stores.add(mockStore1);
stores.add(mockStore2);
assertFalse(policy.isExceedSize(1, 1024));
stores.clear();

// test sum of store's size greater than sizeToCheck
stores.add(mockStore1);
stores.add(mockStore3);
assertTrue(policy.isExceedSize(1, 1024));
}

@Test
public void testBusyRegionSplitPolicy() throws Exception {
doReturn(TableDescriptorBuilder.newBuilder(TABLENAME).build()).when(mockRegion)
Expand Down