Search in sources :

Example 11 with UnknownRegionException

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";
        }
    });
}
Also used : TableName(org.apache.hadoop.hbase.TableName) MergeTableRegionsProcedure(org.apache.hadoop.hbase.master.procedure.MergeTableRegionsProcedure) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) MergeRegionException(org.apache.hadoop.hbase.exceptions.MergeRegionException) MasterProcedureUtil(org.apache.hadoop.hbase.master.procedure.MasterProcedureUtil)

Example 12 with UnknownRegionException

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;
}
Also used : UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 13 with UnknownRegionException

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();
}
Also used : UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode)

Example 14 with UnknownRegionException

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();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) GetRegionInfoResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) QosPriority(org.apache.hadoop.hbase.ipc.QosPriority)

Example 15 with UnknownRegionException

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();
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Aggregations

UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)18 IOException (java.io.IOException)14 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)10 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)9 TableName (org.apache.hadoop.hbase.TableName)8 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)5 InterruptedIOException (java.io.InterruptedIOException)4 ServerName (org.apache.hadoop.hbase.ServerName)4 MergeRegionException (org.apache.hadoop.hbase.exceptions.MergeRegionException)4 RegionSpecifierType (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType)4 Test (org.junit.Test)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 TableExistsException (org.apache.hadoop.hbase.TableExistsException)2 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 Admin (org.apache.hadoop.hbase.client.Admin)2 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)2