HBASE-23864 No need to submit SplitTableRegionProcedure/MergeTableRegionsProcedure when split/merge is disabled (#1182)

Signed-off-by: binlijin <binlijin@gmail.com>
This commit is contained in:
Guanghao Zhang 2020-02-19 18:20:12 +08:00
parent 085d0e5fb6
commit 5e06a2ee7f
4 changed files with 37 additions and 3 deletions

View File

@ -1899,6 +1899,12 @@ public class HMaster extends HRegionServer implements MasterServices {
final long nonce) throws IOException { final long nonce) throws IOException {
checkInitialized(); checkInitialized();
if (!isSplitOrMergeEnabled(MasterSwitchType.MERGE)) {
String regionsStr = Arrays.deepToString(regionsToMerge);
LOG.warn("Merge switch is off! skip merge of " + regionsStr);
throw new IOException("Merge of " + regionsStr + " failed because merge switch is off");
}
final String mergeRegionsStr = Arrays.stream(regionsToMerge). final String mergeRegionsStr = Arrays.stream(regionsToMerge).
map(r -> RegionInfo.getShortNameToLog(r)).collect(Collectors.joining(", ")); map(r -> RegionInfo.getShortNameToLog(r)).collect(Collectors.joining(", "));
return MasterProcedureUtil.submitProcedure(new NonceProcedureRunnable(this, ng, nonce) { return MasterProcedureUtil.submitProcedure(new NonceProcedureRunnable(this, ng, nonce) {
@ -1924,6 +1930,13 @@ public class HMaster extends HRegionServer implements MasterServices {
final long nonceGroup, final long nonce) final long nonceGroup, final long nonce)
throws IOException { throws IOException {
checkInitialized(); checkInitialized();
if (!isSplitOrMergeEnabled(MasterSwitchType.SPLIT)) {
LOG.warn("Split switch is off! skip split of " + regionInfo);
throw new IOException("Split region " + regionInfo.getRegionNameAsString() +
" failed due to split switch off");
}
return MasterProcedureUtil.submitProcedure( return MasterProcedureUtil.submitProcedure(
new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) { new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
@Override @Override

View File

@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseIOException; import org.apache.hadoop.hbase.HBaseIOException;
@ -42,6 +43,7 @@ import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.UnknownRegionException; import org.apache.hadoop.hbase.UnknownRegionException;
import org.apache.hadoop.hbase.client.DoNotRetryRegionException; import org.apache.hadoop.hbase.client.DoNotRetryRegionException;
import org.apache.hadoop.hbase.client.MasterSwitchType;
import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.client.RegionStatesCount; import org.apache.hadoop.hbase.client.RegionStatesCount;
@ -1007,6 +1009,12 @@ public class AssignmentManager {
" hriA=" + hriA + " hriB=" + hriB); " hriA=" + hriA + " hriB=" + hriB);
} }
if (!master.isSplitOrMergeEnabled(MasterSwitchType.SPLIT)) {
LOG.warn("Split switch is off! skip split of " + parent);
throw new IOException("Split region " + parent.getRegionNameAsString() +
" failed due to split switch off");
}
// Submit the Split procedure // Submit the Split procedure
final byte[] splitKey = hriB.getStartKey(); final byte[] splitKey = hriB.getStartKey();
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
@ -1032,6 +1040,12 @@ public class AssignmentManager {
" maybe an old RS (< 2.0) had the operation in progress"); " maybe an old RS (< 2.0) had the operation in progress");
} }
if (!master.isSplitOrMergeEnabled(MasterSwitchType.MERGE)) {
LOG.warn("Merge switch is off! skip merge of regionA=" + hriA + " regionB=" + hriB);
throw new IOException("Merge of regionA=" + hriA + " regionB=" + hriB +
" failed because merge switch is off");
}
// Submit the Merge procedure // Submit the Merge procedure
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Handling merge request from RS=" + merged + ", merged=" + merged); LOG.debug("Handling merge request from RS=" + merged + ", merged=" + merged);

View File

@ -453,6 +453,10 @@ public class MergeTableRegionsProcedure
throw new MergeRegionException("Skip merging regions " + throw new MergeRegionException("Skip merging regions " +
RegionInfo.getShortNameToLog(regionsToMerge) + ", because we are snapshotting " + tn); RegionInfo.getShortNameToLog(regionsToMerge) + ", because we are snapshotting " + tn);
} }
// Mostly this check is not used because we already check the switch before submit a merge
// procedure. Just for safe, check the switch again. This procedure can be rollbacked if
// the switch was set to false after submit.
if (!env.getMasterServices().isSplitOrMergeEnabled(MasterSwitchType.MERGE)) { if (!env.getMasterServices().isSplitOrMergeEnabled(MasterSwitchType.MERGE)) {
String regionsStr = Arrays.deepToString(this.regionsToMerge); String regionsStr = Arrays.deepToString(this.regionsToMerge);
LOG.warn("Merge switch is off! skip merge of " + regionsStr); LOG.warn("Merge switch is off! skip merge of " + regionsStr);

View File

@ -523,8 +523,9 @@ public class SplitTableRegionProcedure
return false; return false;
} }
// Since we have the lock and the master is coordinating the operation // Mostly this check is not used because we already check the switch before submit a split
// we are always able to split the region // procedure. Just for safe, check the switch again. This procedure can be rollbacked if
// the switch was set to false after submit.
if (!env.getMasterServices().isSplitOrMergeEnabled(MasterSwitchType.SPLIT)) { if (!env.getMasterServices().isSplitOrMergeEnabled(MasterSwitchType.SPLIT)) {
LOG.warn("pid=" + getProcId() + " split switch is off! skip split of " + parentHRI); LOG.warn("pid=" + getProcId() + " split switch is off! skip split of " + parentHRI);
setFailure(new IOException("Split region " + parentHRI.getRegionNameAsString() + setFailure(new IOException("Split region " + parentHRI.getRegionNameAsString() +
@ -543,6 +544,8 @@ public class SplitTableRegionProcedure
// set node state as SPLITTING // set node state as SPLITTING
node.setState(State.SPLITTING); node.setState(State.SPLITTING);
// Since we have the lock and the master is coordinating the operation
// we are always able to split the region
return true; return true;
} }