Skip to content
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

HBASE-28727 SteppingSplitPolicy may not work when table enables region replication #6077

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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 @@ -22,6 +22,7 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.yetus.audience.InterfaceAudience;
Expand Down Expand Up @@ -97,7 +98,10 @@ private int getCountOfCommonTableRegions() {
int tableRegionsCount = 0;
try {
List<? extends Region> hri = rss.getRegions(tablename);
tableRegionsCount = hri == null || hri.isEmpty() ? 0 : hri.size();
if (hri != null && !hri.isEmpty()) {
tableRegionsCount = (int) hri.stream()
.filter(r -> r.getRegionInfo().getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID).count();
}
} catch (IOException e) {
LOG.debug("Failed getOnlineRegions " + tablename, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,46 @@ public void testIncreasingToUpperBoundRegionSplitPolicy() throws IOException {
assertWithinJitter(maxSplitSize, policy.getSizeToCheck(0));
}

@Test
public void testSteppingSplitPolicyWithRegionReplication() throws IOException {
conf.set(HConstants.HBASE_REGION_SPLIT_POLICY_KEY, SteppingSplitPolicy.class.getName());

RegionServerServices rss = mock(RegionServerServices.class);
doReturn(rss).when(mockRegion).getRegionServerServices();

long maxFileSize = HConstants.DEFAULT_MAX_FILE_SIZE;
TableDescriptor td =
TableDescriptorBuilder.newBuilder(TABLENAME).setMaxFileSize(maxFileSize).build();
doReturn(td).when(mockRegion).getTableDescriptor();
assertEquals(td.getMaxFileSize(), maxFileSize);

List<HStore> storefiles = new ArrayList<>();
HStore mockStore = mock(HStore.class);
long flushSize = conf.getLong(HConstants.HREGION_MEMSTORE_FLUSH_SIZE,
TableDescriptorBuilder.DEFAULT_MEMSTORE_FLUSH_SIZE);
long exceedSize = flushSize * 2 + 1;
doReturn(exceedSize).when(mockStore).getSize();
doReturn(true).when(mockStore).canSplit();
storefiles.add(mockStore);
doReturn(storefiles).when(mockRegion).getStores();

List<HRegion> regions = new ArrayList<>();
HRegion r1 = mock(HRegion.class);
RegionInfo regionInfo1 = mock(RegionInfo.class);
doReturn(regionInfo1).when(r1).getRegionInfo();
doReturn(RegionInfo.DEFAULT_REPLICA_ID).when(regionInfo1).getReplicaId();
HRegion r2 = mock(HRegion.class);
RegionInfo regionInfo2 = mock(RegionInfo.class);
doReturn(regionInfo2).when(r2).getRegionInfo();
doReturn(1).when(regionInfo2).getReplicaId();
regions.add(r1);
regions.add(r2);
doReturn(regions).when(rss).getRegions(td.getTableName());

SteppingSplitPolicy policy = (SteppingSplitPolicy) RegionSplitPolicy.create(mockRegion, conf);
assertTrue(policy.shouldSplit());
}

@Test
public void testIsExceedSize() throws IOException {
// Configure SteppingAllStoresSizeSplitPolicy as our split policy
Expand Down