Search in sources :

Example 1 with SetRegionStateInMetaResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetRegionStateInMetaResponse in project hbase by apache.

the class MasterRpcServices method setRegionStateInMeta.

/**
 * Update state of the region in meta only. This is required by hbck in some situations to cleanup
 * stuck assign/ unassign regions procedures for the table.
 *
 * @return previous states of the regions
 */
@Override
public SetRegionStateInMetaResponse setRegionStateInMeta(RpcController controller, SetRegionStateInMetaRequest request) throws ServiceException {
    rpcPreCheck("setRegionStateInMeta");
    SetRegionStateInMetaResponse.Builder builder = SetRegionStateInMetaResponse.newBuilder();
    try {
        for (RegionSpecifierAndState s : request.getStatesList()) {
            RegionSpecifier spec = s.getRegionSpecifier();
            String encodedName;
            if (spec.getType() == RegionSpecifierType.ENCODED_REGION_NAME) {
                encodedName = spec.getValue().toStringUtf8();
            } else {
                // TODO: actually, a full region name can save a lot on meta scan, improve later.
                encodedName = RegionInfo.encodeRegionName(spec.getValue().toByteArray());
            }
            RegionInfo info = this.server.getAssignmentManager().loadRegionFromMeta(encodedName);
            LOG.trace("region info loaded from meta table: {}", info);
            RegionState prevState = this.server.getAssignmentManager().getRegionStates().getRegionState(info);
            RegionState.State newState = RegionState.State.convert(s.getState());
            LOG.info("{} set region={} state from {} to {}", server.getClientIdAuditPrefix(), info, prevState.getState(), newState);
            Put metaPut = MetaTableAccessor.makePutFromRegionInfo(info, EnvironmentEdgeManager.currentTime());
            metaPut.addColumn(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER, Bytes.toBytes(newState.name()));
            List<Put> putList = new ArrayList<>();
            putList.add(metaPut);
            MetaTableAccessor.putsToMetaTable(this.server.getConnection(), putList);
            // Loads from meta again to refresh AM cache with the new region state
            this.server.getAssignmentManager().loadRegionFromMeta(encodedName);
            builder.addStates(RegionSpecifierAndState.newBuilder().setRegionSpecifier(spec).setState(prevState.getState().convert()));
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
    return builder.build();
}
Also used : RegionSpecifierAndState(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.RegionSpecifierAndState) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) Put(org.apache.hadoop.hbase.client.Put) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) IOException(java.io.IOException) RemoteProcedureException(org.apache.hadoop.hbase.procedure2.RemoteProcedureException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) KeeperException(org.apache.zookeeper.KeeperException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier) SetRegionStateInMetaResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetRegionStateInMetaResponse) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)

Aggregations

IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)1 Put (org.apache.hadoop.hbase.client.Put)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)1 UnknownProtocolException (org.apache.hadoop.hbase.exceptions.UnknownProtocolException)1 ServerNotRunningYetException (org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)1 RemoteProcedureException (org.apache.hadoop.hbase.procedure2.RemoteProcedureException)1 ReplicationException (org.apache.hadoop.hbase.replication.ReplicationException)1 RegionSpecifier (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)1 RegionSpecifierAndState (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.RegionSpecifierAndState)1 SetRegionStateInMetaResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetRegionStateInMetaResponse)1 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)1 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)1 KeeperException (org.apache.zookeeper.KeeperException)1