Skip to content

Commit

Permalink
HBASE-28727 SteppingSplitPolicy may not work when table enables regio…
Browse files Browse the repository at this point in the history
…n replication (apache#6077)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
(cherry picked from commit 386ecea)
  • Loading branch information
guluo2016 authored and Apache9 committed Jul 15, 2024
1 parent 9dee538 commit 3101425
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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

0 comments on commit 3101425

Please sign in to comment.