Search in sources :

Example 1 with RegionSpecifierType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType in project hbase by apache.

the class RSRpcServices method getRegion.

/**
   * Find the HRegion based on a region specifier
   *
   * @param regionSpecifier the region specifier
   * @return the corresponding region
   * @throws IOException if the specifier is not null,
   *    but failed to find the region
   */
@VisibleForTesting
public Region getRegion(final RegionSpecifier regionSpecifier) throws IOException {
    ByteString value = regionSpecifier.getValue();
    RegionSpecifierType type = regionSpecifier.getType();
    switch(type) {
        case REGION_NAME:
            byte[] regionName = value.toByteArray();
            String encodedRegionName = HRegionInfo.encodeRegionName(regionName);
            return regionServer.getRegionByEncodedName(regionName, encodedRegionName);
        case ENCODED_REGION_NAME:
            return regionServer.getRegionByEncodedName(value.toStringUtf8());
        default:
            throw new DoNotRetryIOException("Unsupported region specifier type: " + type);
    }
}
Also used : RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with RegionSpecifierType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType in project hbase by apache.

the class MasterRpcServices method assignRegion.

@Override
public AssignRegionResponse assignRegion(RpcController controller, AssignRegionRequest req) throws ServiceException {
    try {
        server.checkInitialized();
        final RegionSpecifierType type = req.getRegion().getType();
        if (type != RegionSpecifierType.REGION_NAME) {
            LOG.warn("assignRegion specifier type: expected: " + RegionSpecifierType.REGION_NAME + " actual: " + type);
        }
        final byte[] regionName = req.getRegion().getValue().toByteArray();
        final RegionInfo regionInfo = server.getAssignmentManager().getRegionInfo(regionName);
        if (regionInfo == null) {
            throw new UnknownRegionException(Bytes.toStringBinary(regionName));
        }
        final AssignRegionResponse arr = AssignRegionResponse.newBuilder().build();
        if (server.cpHost != null) {
            server.cpHost.preAssign(regionInfo);
        }
        LOG.info(server.getClientIdAuditPrefix() + " assign " + regionInfo.getRegionNameAsString());
        server.getAssignmentManager().assign(regionInfo);
        if (server.cpHost != null) {
            server.cpHost.postAssign(regionInfo);
        }
        return arr;
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) AssignRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AssignRegionResponse) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 3 with RegionSpecifierType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType in project hbase by apache.

the class MasterRpcServices method unassignRegion.

@Override
public UnassignRegionResponse unassignRegion(RpcController controller, UnassignRegionRequest req) throws ServiceException {
    try {
        final byte[] regionName = req.getRegion().getValue().toByteArray();
        RegionSpecifierType type = req.getRegion().getType();
        UnassignRegionResponse urr = UnassignRegionResponse.newBuilder().build();
        server.checkInitialized();
        if (type != RegionSpecifierType.REGION_NAME) {
            LOG.warn("unassignRegion specifier type: expected: " + RegionSpecifierType.REGION_NAME + " actual: " + type);
        }
        RegionStateNode rsn = server.getAssignmentManager().getRegionStates().getRegionStateNodeFromName(regionName);
        if (rsn == null) {
            throw new UnknownRegionException(Bytes.toString(regionName));
        }
        RegionInfo hri = rsn.getRegionInfo();
        if (server.cpHost != null) {
            server.cpHost.preUnassign(hri);
        }
        LOG.debug(server.getClientIdAuditPrefix() + " unassign " + hri.getRegionNameAsString() + " in current location if it is online");
        server.getAssignmentManager().unassign(hri);
        if (server.cpHost != null) {
            server.cpHost.postUnassign(hri);
        }
        return urr;
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : UnassignRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.UnassignRegionResponse) 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) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode)

Example 4 with RegionSpecifierType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType in project hbase by apache.

the class MasterRpcServices method moveRegion.

@Override
public MoveRegionResponse moveRegion(RpcController controller, MoveRegionRequest req) throws ServiceException {
    final byte[] encodedRegionName = req.getRegion().getValue().toByteArray();
    RegionSpecifierType type = req.getRegion().getType();
    final byte[] destServerName = (req.hasDestServerName()) ? Bytes.toBytes(ProtobufUtil.toServerName(req.getDestServerName()).getServerName()) : null;
    MoveRegionResponse mrr = MoveRegionResponse.newBuilder().build();
    if (type != RegionSpecifierType.ENCODED_REGION_NAME) {
        LOG.warn("moveRegion specifier type: expected: " + RegionSpecifierType.ENCODED_REGION_NAME + " actual: " + type);
    }
    try {
        server.checkInitialized();
        server.move(encodedRegionName, destServerName);
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
    return mrr;
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RegionSpecifierType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) MoveRegionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MoveRegionResponse)

Example 5 with RegionSpecifierType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType 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

DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)6 RegionSpecifierType (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType)6 IOException (java.io.IOException)4 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)4 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RegionStateNode (org.apache.hadoop.hbase.master.assignment.RegionStateNode)1 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)1 AssignRegionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.AssignRegionResponse)1 MoveRegionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MoveRegionResponse)1 UnassignRegionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.UnassignRegionResponse)1 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)1