use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class HMaster method mergeRegions.
@Override
public long mergeRegions(final HRegionInfo[] regionsToMerge, final boolean forcible, final long nonceGroup, final long nonce) throws IOException {
checkInitialized();
assert (regionsToMerge.length == 2);
TableName tableName = regionsToMerge[0].getTable();
if (tableName == null || regionsToMerge[1].getTable() == null) {
throw new UnknownRegionException("Can't merge regions without table associated");
}
if (!tableName.equals(regionsToMerge[1].getTable())) {
throw new IOException("Cannot merge regions from two different tables " + regionsToMerge[0].getTable() + " and " + regionsToMerge[1].getTable());
}
if (regionsToMerge[0].compareTo(regionsToMerge[1]) == 0) {
throw new MergeRegionException("Cannot merge a region to itself " + regionsToMerge[0] + ", " + regionsToMerge[1]);
}
return MasterProcedureUtil.submitProcedure(new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
@Override
protected void run() throws IOException {
getMaster().getMasterCoprocessorHost().preMergeRegions(regionsToMerge);
LOG.info(getClientIdAuditPrefix() + " Merge regions " + regionsToMerge[0].getEncodedName() + " and " + regionsToMerge[1].getEncodedName());
submitProcedure(new MergeTableRegionsProcedure(procedureExecutor.getEnvironment(), regionsToMerge, forcible));
getMaster().getMasterCoprocessorHost().postMergeRegions(regionsToMerge);
}
@Override
protected String getDescription() {
return "DisableTableProcedure";
}
});
}
use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class SplitTableRegionProcedure method prepareSplitRegion.
/**
* Prepare to Split region.
* @param env MasterProcedureEnv
*/
public boolean prepareSplitRegion(final MasterProcedureEnv env) throws IOException {
// Fail if we are taking snapshot for the given table
if (env.getMasterServices().getSnapshotManager().isTakingSnapshot(getParentRegion().getTable())) {
setFailure(new IOException("Skip splitting region " + getParentRegion().getShortNameToLog() + ", because we are taking snapshot for the table " + getParentRegion().getTable()));
return false;
}
// Check whether the region is splittable
RegionStateNode node = env.getAssignmentManager().getRegionStates().getRegionStateNode(getParentRegion());
if (node == null) {
throw new UnknownRegionException(getParentRegion().getRegionNameAsString());
}
RegionInfo parentHRI = node.getRegionInfo();
if (parentHRI == null) {
LOG.info("Unsplittable; parent region is null; node={}", node);
return false;
}
// just before us.
if (node.isInState(State.SPLIT)) {
LOG.info("Split of " + parentHRI + " skipped; state is already SPLIT");
return false;
}
if (parentHRI.isSplit() || parentHRI.isOffline()) {
LOG.info("Split of " + parentHRI + " skipped because offline/split.");
return false;
}
// expected parent to be online or closed
if (!node.isInState(EXPECTED_SPLIT_STATES)) {
// We may have SPLIT already?
setFailure(new IOException("Split " + parentHRI.getRegionNameAsString() + " FAILED because state=" + node.getState() + "; expected " + Arrays.toString(EXPECTED_SPLIT_STATES)));
return false;
}
// the switch was set to false after submit.
if (!env.getMasterServices().isSplitOrMergeEnabled(MasterSwitchType.SPLIT)) {
LOG.warn("pid=" + getProcId() + " split switch is off! skip split of " + parentHRI);
setFailure(new IOException("Split region " + parentHRI.getRegionNameAsString() + " failed due to split switch off"));
return false;
}
if (!env.getMasterServices().getTableDescriptors().get(getTableName()).isSplitEnabled()) {
LOG.warn("pid={}, split is disabled for the table! Skipping split of {}", getProcId(), parentHRI);
setFailure(new IOException("Split region " + parentHRI.getRegionNameAsString() + " failed as region split is disabled for the table"));
return false;
}
// set node state as SPLITTING
node.setState(State.SPLITTING);
// we are always able to split the region
return true;
}
use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class AbstractStateMachineTableProcedure method checkOnline.
/**
* Check region is online.
*/
protected static void checkOnline(MasterProcedureEnv env, RegionInfo ri) throws DoNotRetryRegionException {
RegionStateNode regionNode = env.getAssignmentManager().getRegionStates().getRegionStateNode(ri);
if (regionNode == null) {
throw new UnknownRegionException("No RegionState found for " + ri.getEncodedName());
}
regionNode.checkOnline();
}
use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class MasterRpcServices method getRegionInfo.
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public GetRegionInfoResponse getRegionInfo(final RpcController controller, final GetRegionInfoRequest request) throws ServiceException {
RegionInfo ri = null;
try {
ri = getRegionInfo(request.getRegion());
} catch (UnknownRegionException ure) {
throw new ServiceException(ure);
}
GetRegionInfoResponse.Builder builder = GetRegionInfoResponse.newBuilder();
if (ri != null) {
builder.setRegionInfo(ProtobufUtil.toRegionInfo(ri));
} else {
// Is it a MOB name? These work differently.
byte[] regionName = request.getRegion().getValue().toByteArray();
TableName tableName = RegionInfo.getTable(regionName);
if (MobUtils.isMobRegionName(tableName, regionName)) {
// a dummy region info contains the compaction state.
RegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(tableName);
builder.setRegionInfo(ProtobufUtil.toRegionInfo(mobRegionInfo));
if (request.hasCompactionState() && request.getCompactionState()) {
builder.setCompactionState(server.getMobCompactionState(tableName));
}
} else {
// If unknown RegionInfo and not a MOB region, it is unknown.
throw new ServiceException(new UnknownRegionException(Bytes.toString(regionName)));
}
}
return builder.build();
}
use of org.apache.hadoop.hbase.UnknownRegionException in project hbase by apache.
the class MasterRpcServices method offlineRegion.
/**
* Offline specified region from master's in-memory state. It will not attempt to
* reassign the region as in unassign.
*
* This is a special method that should be used by experts or hbck.
*/
@Override
public OfflineRegionResponse offlineRegion(RpcController controller, OfflineRegionRequest request) throws ServiceException {
try {
server.checkInitialized();
final RegionSpecifierType type = request.getRegion().getType();
if (type != RegionSpecifierType.REGION_NAME) {
LOG.warn("moveRegion specifier type: expected: " + RegionSpecifierType.REGION_NAME + " actual: " + type);
}
final byte[] regionName = request.getRegion().getValue().toByteArray();
final RegionInfo hri = server.getAssignmentManager().getRegionInfo(regionName);
if (hri == null) {
throw new UnknownRegionException(Bytes.toStringBinary(regionName));
}
if (server.cpHost != null) {
server.cpHost.preRegionOffline(hri);
}
LOG.info(server.getClientIdAuditPrefix() + " offline " + hri.getRegionNameAsString());
server.getAssignmentManager().offlineRegion(hri);
if (server.cpHost != null) {
server.cpHost.postRegionOffline(hri);
}
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
return OfflineRegionResponse.newBuilder().build();
}
Aggregations