Skip to content

Commit 37b863b

Browse files
authored
HBASE-24648 Remove the legacy 'forceSplit' related code at region server side (#1990)
Signed-off-by: Viraj Jasani <vjasani@apache.org>
1 parent b39cd1e commit 37b863b

File tree

13 files changed

+187
-249
lines changed

13 files changed

+187
-249
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/SplitTableRegionProcedure.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,15 @@ public RegionInfo getDaughterTwoRI() {
167167
return daughterTwoRI;
168168
}
169169

170+
private boolean hasBestSplitRow() {
171+
return bestSplitRow != null && bestSplitRow.length > 0;
172+
}
173+
170174
/**
171175
* Check whether the region is splittable
172176
* @param env MasterProcedureEnv
173177
* @param regionToSplit parent Region to be split
174178
* @param splitRow if splitRow is not specified, will first try to get bestSplitRow from RS
175-
* @throws IOException
176179
*/
177180
private void checkSplittable(final MasterProcedureEnv env,
178181
final RegionInfo regionToSplit, final byte[] splitRow) throws IOException {
@@ -187,19 +190,20 @@ private void checkSplittable(final MasterProcedureEnv env,
187190
boolean splittable = false;
188191
if (node != null) {
189192
try {
190-
if (bestSplitRow == null || bestSplitRow.length == 0) {
191-
LOG
192-
.info("splitKey isn't explicitly specified, will try to find a best split key from RS");
193-
}
194-
// Always set bestSplitRow request as true here,
195-
// need to call Region#checkSplit to check it splittable or not
196-
GetRegionInfoResponse response = AssignmentManagerUtil.getRegionInfoResponse(env,
197-
node.getRegionLocation(), node.getRegionInfo(), true);
198-
if(bestSplitRow == null || bestSplitRow.length == 0) {
199-
bestSplitRow = response.hasBestSplitRow() ? response.getBestSplitRow().toByteArray() : null;
193+
GetRegionInfoResponse response;
194+
if (!hasBestSplitRow()) {
195+
LOG.info(
196+
"{} splitKey isn't explicitly specified, will try to find a best split key from RS {}",
197+
node.getRegionInfo().getRegionNameAsString(), node.getRegionLocation());
198+
response = AssignmentManagerUtil.getRegionInfoResponse(env, node.getRegionLocation(),
199+
node.getRegionInfo(), true);
200+
bestSplitRow =
201+
response.hasBestSplitRow() ? response.getBestSplitRow().toByteArray() : null;
202+
} else {
203+
response = AssignmentManagerUtil.getRegionInfoResponse(env, node.getRegionLocation(),
204+
node.getRegionInfo(), false);
200205
}
201206
splittable = response.hasSplittable() && response.getSplittable();
202-
203207
if (LOG.isDebugEnabled()) {
204208
LOG.debug("Splittable=" + splittable + " " + node.toShortString());
205209
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public synchronized boolean requestSplit(final Region r) {
191191
HRegion hr = (HRegion)r;
192192
try {
193193
if (shouldSplitRegion() && hr.getCompactPriority() >= PRIORITY_USER) {
194-
byte[] midKey = hr.checkSplit();
194+
byte[] midKey = hr.checkSplit().orElse(null);
195195
if (midKey != null) {
196196
requestSplit(r, midKey);
197197
return true;
@@ -216,9 +216,6 @@ public synchronized void requestSplit(final Region r, byte[] midKey, User user)
216216
if (midKey == null) {
217217
LOG.debug("Region " + r.getRegionInfo().getRegionNameAsString() +
218218
" not splittable because midkey=null");
219-
if (((HRegion)r).shouldForceSplit()) {
220-
((HRegion)r).clearSplit();
221-
}
222219
return;
223220
}
224221
try {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ protected void configureForRegion(HRegion region) {
6868

6969
@Override
7070
protected boolean shouldSplit() {
71-
boolean force = region.shouldForceSplit();
7271
boolean foundABigStore = false;
7372

7473
for (HStore store : region.getStores()) {
@@ -84,7 +83,7 @@ protected boolean shouldSplit() {
8483
}
8584
}
8685

87-
return foundABigStore || force;
86+
return foundABigStore;
8887
}
8988

9089
long getDesiredMaxFileSize() {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@
2222
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
2323

2424
/**
25-
* A {@link RegionSplitPolicy} that disables region splits.
26-
* This should be used with care, since it will disable automatic sharding.
27-
* Most of the time, using {@link ConstantSizeRegionSplitPolicy} with a
28-
* large region size (10GB, etc) is safer.
25+
* A {@link RegionSplitPolicy} that disables region splits. This should be used with care, since it
26+
* will disable automatic sharding. Most of the time, using {@link ConstantSizeRegionSplitPolicy}
27+
* with a large region size (10GB, etc) is safer.
2928
*/
3029
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
3130
public class DisabledRegionSplitPolicy extends RegionSplitPolicy {
31+
3232
@Override
3333
protected boolean shouldSplit() {
3434
return false;
3535
}
36+
37+
@Override
38+
protected boolean canSplit() {
39+
return false;
40+
}
3641
}

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

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,6 @@ void sawNoSuchFamily() {
696696

697697
// Stop updates lock
698698
private final ReentrantReadWriteLock updatesLock = new ReentrantReadWriteLock();
699-
private boolean splitRequest;
700-
private byte[] explicitSplitPoint = null;
701699

702700
private final MultiVersionConcurrencyControl mvcc;
703701

@@ -1478,7 +1476,7 @@ public boolean isAvailable() {
14781476

14791477
@Override
14801478
public boolean isSplittable() {
1481-
return isAvailable() && !hasReferences();
1479+
return splitPolicy.canSplit();
14821480
}
14831481

14841482
@Override
@@ -1977,7 +1975,8 @@ public void setMobFileCache(MobFileCache mobFileCache) {
19771975
/**
19781976
* @return split policy for this region.
19791977
*/
1980-
public RegionSplitPolicy getSplitPolicy() {
1978+
@VisibleForTesting
1979+
RegionSplitPolicy getSplitPolicy() {
19811980
return this.splitPolicy;
19821981
}
19831982

@@ -8408,9 +8407,9 @@ private static List<Cell> sort(List<Cell> cells, final CellComparator comparator
84088407

84098408
public static final long FIXED_OVERHEAD = ClassSize.align(
84108409
ClassSize.OBJECT +
8411-
ClassSize.ARRAY +
8412-
55 * ClassSize.REFERENCE + 3 * Bytes.SIZEOF_INT +
8413-
(15 * Bytes.SIZEOF_LONG) +
8410+
56 * ClassSize.REFERENCE +
8411+
3 * Bytes.SIZEOF_INT +
8412+
14 * Bytes.SIZEOF_LONG +
84148413
3 * Bytes.SIZEOF_BOOLEAN);
84158414

84168415
// woefully out of date - currently missing:
@@ -8537,50 +8536,26 @@ public void run(Message message) {
85378536
return responseBuilder.build();
85388537
}
85398538

8540-
boolean shouldForceSplit() {
8541-
return this.splitRequest;
8542-
}
8543-
8544-
byte[] getExplicitSplitPoint() {
8545-
return this.explicitSplitPoint;
8546-
}
8547-
8548-
void forceSplit(byte[] sp) {
8549-
// This HRegion will go away after the forced split is successful
8550-
// But if a forced split fails, we need to clear forced split.
8551-
this.splitRequest = true;
8552-
if (sp != null) {
8553-
this.explicitSplitPoint = sp;
8554-
}
8555-
}
8556-
8557-
void clearSplit() {
8558-
this.splitRequest = false;
8559-
this.explicitSplitPoint = null;
8539+
public Optional<byte[]> checkSplit() {
8540+
return checkSplit(false);
85608541
}
85618542

85628543
/**
8563-
* Return the splitpoint. null indicates the region isn't splittable
8564-
* If the splitpoint isn't explicitly specified, it will go over the stores
8565-
* to find the best splitpoint. Currently the criteria of best splitpoint
8566-
* is based on the size of the store.
8544+
* Return the split point. An empty result indicates the region isn't splittable.
85678545
*/
8568-
public byte[] checkSplit() {
8546+
public Optional<byte[]> checkSplit(boolean force) {
85698547
// Can't split META
85708548
if (this.getRegionInfo().isMetaRegion()) {
8571-
if (shouldForceSplit()) {
8572-
LOG.warn("Cannot split meta region in HBase 0.20 and above");
8573-
}
8574-
return null;
8549+
return Optional.empty();
85758550
}
85768551

85778552
// Can't split a region that is closing.
85788553
if (this.isClosing()) {
8579-
return null;
8554+
return Optional.empty();
85808555
}
85818556

8582-
if (!splitPolicy.shouldSplit()) {
8583-
return null;
8557+
if (!force && !splitPolicy.shouldSplit()) {
8558+
return Optional.empty();
85848559
}
85858560

85868561
byte[] ret = splitPolicy.getSplitPoint();
@@ -8590,10 +8565,12 @@ public byte[] checkSplit() {
85908565
checkRow(ret, "calculated split");
85918566
} catch (IOException e) {
85928567
LOG.error("Ignoring invalid split for region {}", this, e);
8593-
return null;
8568+
return Optional.empty();
85948569
}
8570+
return Optional.of(ret);
8571+
} else {
8572+
return Optional.empty();
85958573
}
8596-
return ret;
85978574
}
85988575

85998576
/**

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ protected void configureForRegion(HRegion region) {
7070

7171
@Override
7272
protected boolean shouldSplit() {
73-
boolean force = region.shouldForceSplit();
7473
boolean foundABigStore = false;
7574
// Get count of regions that have the same common table as this.region
7675
int tableRegionsCount = getCountOfCommonTableRegions();
@@ -95,7 +94,7 @@ protected boolean shouldSplit() {
9594
}
9695
}
9796

98-
return foundABigStore || force;
97+
return foundABigStore;
9998
}
10099

101100
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ private boolean flushRegion(HRegion region, boolean emergencyFlush,
620620
FlushResult flushResult = region.flushcache(families, false, tracker);
621621
boolean shouldCompact = flushResult.isCompactionNeeded();
622622
// We just want to check the size
623-
boolean shouldSplit = region.checkSplit() != null;
623+
boolean shouldSplit = region.checkSplit().isPresent();
624624
if (shouldSplit) {
625625
this.server.compactSplitThread.requestSplit(region);
626626
} else if (shouldCompact) {

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,35 +1837,30 @@ public GetOnlineRegionResponse getOnlineRegion(final RpcController controller,
18371837
@Override
18381838
@QosPriority(priority=HConstants.ADMIN_QOS)
18391839
public GetRegionInfoResponse getRegionInfo(final RpcController controller,
1840-
final GetRegionInfoRequest request) throws ServiceException {
1840+
final GetRegionInfoRequest request) throws ServiceException {
18411841
try {
18421842
checkOpen();
18431843
requestCount.increment();
18441844
HRegion region = getRegion(request.getRegion());
18451845
RegionInfo info = region.getRegionInfo();
1846-
byte[] bestSplitRow = null;
1847-
boolean shouldSplit = true;
1846+
byte[] bestSplitRow;
18481847
if (request.hasBestSplitRow() && request.getBestSplitRow()) {
1849-
HRegion r = region;
1850-
region.startRegionOperation(Operation.SPLIT_REGION);
1851-
r.forceSplit(null);
1852-
// Even after setting force split if split policy says no to split then we should not split.
1853-
shouldSplit = region.getSplitPolicy().shouldSplit() && !info.isMetaRegion();
1854-
bestSplitRow = r.checkSplit();
1848+
bestSplitRow = region.checkSplit(true).orElse(null);
18551849
// when all table data are in memstore, bestSplitRow = null
18561850
// try to flush region first
1857-
if(bestSplitRow == null) {
1858-
r.flush(true);
1859-
bestSplitRow = r.checkSplit();
1851+
if (bestSplitRow == null) {
1852+
region.flush(true);
1853+
bestSplitRow = region.checkSplit(true).orElse(null);
18601854
}
1861-
r.clearSplit();
1855+
} else {
1856+
bestSplitRow = null;
18621857
}
18631858
GetRegionInfoResponse.Builder builder = GetRegionInfoResponse.newBuilder();
18641859
builder.setRegionInfo(ProtobufUtil.toRegionInfo(info));
18651860
if (request.hasCompactionState() && request.getCompactionState()) {
18661861
builder.setCompactionState(ProtobufUtil.createCompactionState(region.getCompactionState()));
18671862
}
1868-
builder.setSplittable(region.isSplittable() && shouldSplit);
1863+
builder.setSplittable(region.isSplittable());
18691864
builder.setMergeable(region.isMergeable());
18701865
if (request.hasBestSplitRow() && request.getBestSplitRow() && bestSplitRow != null) {
18711866
builder.setBestSplitRow(UnsafeByteOperations.unsafeWrap(bestSplitRow));

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,20 @@ protected void configureForRegion(HRegion region) {
7070
*/
7171
protected abstract boolean shouldSplit();
7272

73+
/**
74+
* @return {@code true} if the specified region can be split.
75+
*/
76+
protected boolean canSplit() {
77+
return !region.getRegionInfo().isMetaRegion() && region.isAvailable() &&
78+
!region.hasReferences();
79+
}
80+
7381
/**
7482
* @return the key at which the region should be split, or null
7583
* if it cannot be split. This will only be called if shouldSplit
7684
* previously returned true.
7785
*/
7886
protected byte[] getSplitPoint() {
79-
byte[] explicitSplitPoint = this.region.getExplicitSplitPoint();
80-
if (explicitSplitPoint != null) {
81-
return explicitSplitPoint;
82-
}
8387
List<HStore> stores = region.getStores();
8488

8589
byte[] splitPointFromLargestStore = null;

hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,9 +3139,8 @@ public void unassignRegionByRow(byte[] row, RegionLocator table) throws IOExcept
31393139
unassignRegion(hrl.getRegion().getRegionName());
31403140
}
31413141

3142-
/*
3142+
/**
31433143
* Retrieves a splittable region randomly from tableName
3144-
*
31453144
* @param tableName name of table
31463145
* @param maxAttempts maximum number of attempts, unlimited for value of -1
31473146
* @return the HRegion chosen, null if none was found within limit of maxAttempts
@@ -3164,15 +3163,14 @@ public HRegion getSplittableRegion(TableName tableName, int maxAttempts) {
31643163
if (regCount > 0) {
31653164
idx = random.nextInt(regCount);
31663165
// if we have just tried this region, there is no need to try again
3167-
if (attempted.contains(idx))
3166+
if (attempted.contains(idx)) {
31683167
continue;
3169-
try {
3170-
regions.get(idx).checkSplit();
3171-
return regions.get(idx);
3172-
} catch (Exception ex) {
3173-
LOG.warn("Caught exception", ex);
3174-
attempted.add(idx);
31753168
}
3169+
HRegion region = regions.get(idx);
3170+
if (region.checkSplit().isPresent()) {
3171+
return region;
3172+
}
3173+
attempted.add(idx);
31763174
}
31773175
attempts++;
31783176
} while (maxAttempts == -1 || attempts < maxAttempts);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertFalse;
2323
import static org.junit.Assert.assertTrue;
24+
2425
import java.io.IOException;
2526
import java.util.ArrayList;
2627
import java.util.List;
@@ -70,6 +71,7 @@
7071
import org.junit.rules.TestName;
7172
import org.slf4j.Logger;
7273
import org.slf4j.LoggerFactory;
74+
7375
import org.apache.hbase.thirdparty.com.google.common.collect.Iterators;
7476
import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
7577
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
@@ -121,7 +123,6 @@ public void testCanSplitJustAfterASplit() throws Exception {
121123
admin.createTable(htd);
122124
TEST_UTIL.loadTable(source, fam);
123125
compactSplit.setCompactionsEnabled(false);
124-
TEST_UTIL.getHBaseCluster().getRegions(tableName).get(0).forceSplit(null);
125126
admin.split(tableName);
126127
TEST_UTIL.waitFor(60000, () -> TEST_UTIL.getHBaseCluster().getRegions(tableName).size() == 2);
127128

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,6 @@ public void testMultipleTimestamps() throws IOException {
873873
public void testSplitWithEmptyColFam() throws IOException {
874874
init(this.name.getMethodName());
875875
assertFalse(store.getSplitPoint().isPresent());
876-
store.getHRegion().forceSplit(null);
877-
assertFalse(store.getSplitPoint().isPresent());
878-
store.getHRegion().clearSplit();
879876
}
880877

881878
@Test

0 commit comments

Comments
 (0)