Search in sources :

Example 1 with RegionInfo

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

the class ServerCrashProcedure method deserializeStateData.

@Override
public void deserializeStateData(final InputStream stream) throws IOException {
    super.deserializeStateData(stream);
    MasterProcedureProtos.ServerCrashStateData state = MasterProcedureProtos.ServerCrashStateData.parseDelimitedFrom(stream);
    this.serverName = ProtobufUtil.toServerName(state.getServerName());
    this.distributedLogReplay = state.hasDistributedLogReplay() ? state.getDistributedLogReplay() : false;
    this.carryingMeta = state.hasCarryingMeta() ? state.getCarryingMeta() : false;
    // shouldSplitWAL has a default over in pb so this invocation will always work.
    this.shouldSplitWal = state.getShouldSplitWal();
    int size = state.getRegionsOnCrashedServerCount();
    if (size > 0) {
        this.regionsOnCrashedServer = new HashSet<>(size);
        for (RegionInfo ri : state.getRegionsOnCrashedServerList()) {
            this.regionsOnCrashedServer.add(HRegionInfo.convert(ri));
        }
    }
    size = state.getRegionsAssignedCount();
    if (size > 0) {
        this.regionsAssigned = new ArrayList<>(size);
        for (RegionInfo ri : state.getRegionsOnCrashedServerList()) {
            this.regionsAssigned.add(HRegionInfo.convert(ri));
        }
    }
}
Also used : MasterProcedureProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos) RegionInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionInfo) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo)

Example 2 with RegionInfo

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

the class TestHRegionInfo method testConvert.

@Test
public void testConvert() {
    final TableName tableName = TableName.valueOf("ns1:" + name.getMethodName());
    byte[] startKey = Bytes.toBytes("startKey");
    byte[] endKey = Bytes.toBytes("endKey");
    boolean split = false;
    long regionId = System.currentTimeMillis();
    int replicaId = 42;
    HRegionInfo hri = new HRegionInfo(tableName, startKey, endKey, split, regionId, replicaId);
    // convert two times, compare
    HRegionInfo convertedHri = HRegionInfo.convert(HRegionInfo.convert(hri));
    assertEquals(hri, convertedHri);
    // test convert RegionInfo without replicaId
    RegionInfo info = RegionInfo.newBuilder().setTableName(HBaseProtos.TableName.newBuilder().setQualifier(UnsafeByteOperations.unsafeWrap(tableName.getQualifier())).setNamespace(UnsafeByteOperations.unsafeWrap(tableName.getNamespace())).build()).setStartKey(UnsafeByteOperations.unsafeWrap(startKey)).setEndKey(UnsafeByteOperations.unsafeWrap(endKey)).setSplit(split).setRegionId(regionId).build();
    convertedHri = HRegionInfo.convert(info);
    HRegionInfo expectedHri = new HRegionInfo(tableName, startKey, endKey, split, regionId, // expecting default replicaId
    0);
    assertEquals(expectedHri, convertedHri);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) RegionInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionInfo) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Test(org.junit.Test)

Example 3 with RegionInfo

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

the class MasterRpcServices method reportRegionStateTransition.

@Override
public ReportRegionStateTransitionResponse reportRegionStateTransition(RpcController c, ReportRegionStateTransitionRequest req) throws ServiceException {
    try {
        master.checkServiceStarted();
        RegionStateTransition rt = req.getTransition(0);
        RegionStates regionStates = master.getAssignmentManager().getRegionStates();
        for (RegionInfo ri : rt.getRegionInfoList()) {
            TableName tableName = ProtobufUtil.toTableName(ri.getTableName());
            if (!(TableName.META_TABLE_NAME.equals(tableName) && regionStates.getRegionState(HRegionInfo.FIRST_META_REGIONINFO) != null) && !master.getAssignmentManager().isFailoverCleanupDone()) {
                // failover cleanup. So no need this check for it
                throw new PleaseHoldException("Master is rebuilding user regions");
            }
        }
        ServerName sn = ProtobufUtil.toServerName(req.getServer());
        String error = master.getAssignmentManager().onRegionTransition(sn, rt);
        ReportRegionStateTransitionResponse.Builder rrtr = ReportRegionStateTransitionResponse.newBuilder();
        if (error != null) {
            rrtr.setErrorMessage(error);
        }
        return rrtr.build();
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) PleaseHoldException(org.apache.hadoop.hbase.PleaseHoldException) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionInfo) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) RegionStateTransition(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition) ReportRegionStateTransitionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse)

Example 4 with RegionInfo

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

the class HRegionInfo method parseFrom.

/**
   * @param bytes A pb RegionInfo serialized with a pb magic prefix.
   * @param offset starting point in the byte array
   * @param len length to read on the byte array
   * @return A deserialized {@link HRegionInfo}
   * @throws DeserializationException
   * @see #toByteArray()
   */
public static HRegionInfo parseFrom(final byte[] bytes, int offset, int len) throws DeserializationException {
    if (ProtobufUtil.isPBMagicPrefix(bytes, offset, len)) {
        int pblen = ProtobufUtil.lengthOfPBMagic();
        try {
            HBaseProtos.RegionInfo.Builder builder = HBaseProtos.RegionInfo.newBuilder();
            ProtobufUtil.mergeFrom(builder, bytes, pblen + offset, len - pblen);
            HBaseProtos.RegionInfo ri = builder.build();
            return convert(ri);
        } catch (IOException e) {
            throw new DeserializationException(e);
        }
    } else {
        throw new DeserializationException("PB encoded HRegionInfo expected");
    }
}
Also used : RegionInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionInfo) IOException(java.io.IOException) RegionInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionInfo) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

RegionInfo (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionInfo)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)3 IOException (java.io.IOException)2 TableName (org.apache.hadoop.hbase.TableName)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 PleaseHoldException (org.apache.hadoop.hbase.PleaseHoldException)1 ServerName (org.apache.hadoop.hbase.ServerName)1 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)1 MasterProcedureProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos)1 RegionStateTransition (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition)1 ReportRegionStateTransitionResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse)1 Test (org.junit.Test)1