Java Code Examples for org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos#RegionInfo
The following examples show how to use
org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos#RegionInfo .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateTableProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { super.deserializeStateData(serializer); MasterProcedureProtos.CreateTableStateData state = serializer.deserialize(MasterProcedureProtos.CreateTableStateData.class); setUser(MasterProcedureUtil.toUserInfo(state.getUserInfo())); tableDescriptor = ProtobufUtil.toTableDescriptor(state.getTableSchema()); if (state.getRegionInfoCount() == 0) { newRegions = null; } else { newRegions = new ArrayList<>(state.getRegionInfoCount()); for (HBaseProtos.RegionInfo hri: state.getRegionInfoList()) { newRegions.add(ProtobufUtil.toRegionInfo(hri)); } } }
Example 2
Source File: TruncateTableProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { super.deserializeStateData(serializer); MasterProcedureProtos.TruncateTableStateData state = serializer.deserialize(MasterProcedureProtos.TruncateTableStateData.class); setUser(MasterProcedureUtil.toUserInfo(state.getUserInfo())); if (state.hasTableSchema()) { tableDescriptor = ProtobufUtil.toTableDescriptor(state.getTableSchema()); tableName = tableDescriptor.getTableName(); } else { tableName = ProtobufUtil.toTableName(state.getTableName()); } preserveSplits = state.getPreserveSplits(); if (state.getRegionInfoCount() == 0) { regions = null; } else { regions = new ArrayList<>(state.getRegionInfoCount()); for (HBaseProtos.RegionInfo hri: state.getRegionInfoList()) { regions.add(ProtobufUtil.toRegionInfo(hri)); } } }
Example 3
Source File: DeleteTableProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Override protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { super.deserializeStateData(serializer); MasterProcedureProtos.DeleteTableStateData state = serializer.deserialize(MasterProcedureProtos.DeleteTableStateData.class); setUser(MasterProcedureUtil.toUserInfo(state.getUserInfo())); tableName = ProtobufUtil.toTableName(state.getTableName()); if (state.getRegionInfoCount() == 0) { regions = null; } else { regions = new ArrayList<>(state.getRegionInfoCount()); for (HBaseProtos.RegionInfo hri: state.getRegionInfoList()) { regions.add(ProtobufUtil.toRegionInfo(hri)); } } }
Example 4
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 6 votes |
/** * Convert a RegionInfo to a Proto RegionInfo * * @param info the RegionInfo to convert * @return the converted Proto RegionInfo */ public static HBaseProtos.RegionInfo toRegionInfo(final org.apache.hadoop.hbase.client.RegionInfo info) { if (info == null) { return null; } HBaseProtos.RegionInfo.Builder builder = HBaseProtos.RegionInfo.newBuilder(); builder.setTableName(ProtobufUtil.toProtoTableName(info.getTable())); builder.setRegionId(info.getRegionId()); if (info.getStartKey() != null) { builder.setStartKey(UnsafeByteOperations.unsafeWrap(info.getStartKey())); } if (info.getEndKey() != null) { builder.setEndKey(UnsafeByteOperations.unsafeWrap(info.getEndKey())); } builder.setOffline(info.isOffline()); builder.setSplit(info.isSplit()); builder.setReplicaId(info.getReplicaId()); return builder.build(); }
Example 5
Source File: RegionInfo.java From hbase with Apache License 2.0 | 6 votes |
/** * @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 RegionInfo} */ @InterfaceAudience.Private static RegionInfo 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 ProtobufUtil.toRegionInfo(ri); } catch (IOException e) { throw new DeserializationException(e); } } else { throw new DeserializationException("PB encoded RegionInfo expected"); } }
Example 6
Source File: CloneSnapshotProcedure.java From hbase with Apache License 2.0 | 5 votes |
@Override protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException { super.deserializeStateData(serializer); MasterProcedureProtos.CloneSnapshotStateData cloneSnapshotMsg = serializer.deserialize(MasterProcedureProtos.CloneSnapshotStateData.class); setUser(MasterProcedureUtil.toUserInfo(cloneSnapshotMsg.getUserInfo())); snapshot = cloneSnapshotMsg.getSnapshot(); tableDescriptor = ProtobufUtil.toTableDescriptor(cloneSnapshotMsg.getTableSchema()); if (cloneSnapshotMsg.getRegionInfoCount() == 0) { newRegions = null; } else { newRegions = new ArrayList<>(cloneSnapshotMsg.getRegionInfoCount()); for (HBaseProtos.RegionInfo hri: cloneSnapshotMsg.getRegionInfoList()) { newRegions.add(ProtobufUtil.toRegionInfo(hri)); } } if (cloneSnapshotMsg.getParentToChildRegionsPairListCount() > 0) { parentsToChildrenPairMap = new HashMap<>(); for (MasterProcedureProtos.RestoreParentToChildRegionsPair parentToChildrenPair: cloneSnapshotMsg.getParentToChildRegionsPairListList()) { parentsToChildrenPairMap.put( parentToChildrenPair.getParentRegionName(), new Pair<>( parentToChildrenPair.getChild1RegionName(), parentToChildrenPair.getChild2RegionName())); } } // Make sure that the monitor status is set up getMonitorStatus(); }
Example 7
Source File: TestMasterQosFunction.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testRegionInTransition() throws IOException { // Check ReportRegionInTransition HBaseProtos.RegionInfo meta_ri = ProtobufUtil.toRegionInfo(RegionInfoBuilder.FIRST_META_REGIONINFO); HBaseProtos.RegionInfo normal_ri = ProtobufUtil.toRegionInfo(RegionInfoBuilder.newBuilder(TableName.valueOf("test:table")) .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("b")).build()); RegionServerStatusProtos.RegionStateTransition metaTransition = RegionServerStatusProtos .RegionStateTransition.newBuilder() .addRegionInfo(meta_ri) .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED) .build(); RegionServerStatusProtos.RegionStateTransition normalTransition = RegionServerStatusProtos .RegionStateTransition.newBuilder() .addRegionInfo(normal_ri) .setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED) .build(); RegionServerStatusProtos.ReportRegionStateTransitionRequest metaTransitionRequest = RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder() .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100))) .addTransition(normalTransition) .addTransition(metaTransition).build(); RegionServerStatusProtos.ReportRegionStateTransitionRequest normalTransitionRequest = RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder() .setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100))) .addTransition(normalTransition).build(); final String reportFuncName = "ReportRegionStateTransition"; checkMethod(conf, reportFuncName, HConstants.META_QOS, qosFunction, metaTransitionRequest); checkMethod(conf, reportFuncName, HConstants.HIGH_QOS, qosFunction, normalTransitionRequest); }
Example 8
Source File: TestRegionInfo.java From hbase with Apache License 2.0 | 5 votes |
@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; RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey).setEndKey(endKey) .setSplit(split).setRegionId(regionId).setReplicaId(replicaId).build(); // convert two times, compare RegionInfo convertedHri = ProtobufUtil.toRegionInfo(ProtobufUtil.toRegionInfo(hri)); assertEquals(hri, convertedHri); // test convert RegionInfo without replicaId HBaseProtos.RegionInfo info = HBaseProtos.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 = ProtobufUtil.toRegionInfo(info); // expecting default replicaId RegionInfo expectedHri = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey) .setEndKey(endKey).setSplit(split).setRegionId(regionId).setReplicaId(0).build(); assertEquals(expectedHri, convertedHri); }
Example 9
Source File: ProtobufUtil.java From hbase with Apache License 2.0 | 5 votes |
/** * Convert HBaseProto.RegionInfo to a RegionInfo * * @param proto the RegionInfo to convert * @return the converted RegionInfo */ public static org.apache.hadoop.hbase.client.RegionInfo toRegionInfo(final HBaseProtos.RegionInfo proto) { if (proto == null) { return null; } TableName tableName = ProtobufUtil.toTableName(proto.getTableName()); long regionId = proto.getRegionId(); int defaultReplicaId = org.apache.hadoop.hbase.client.RegionInfo.DEFAULT_REPLICA_ID; int replicaId = proto.hasReplicaId()? proto.getReplicaId(): defaultReplicaId; if (tableName.equals(TableName.META_TABLE_NAME) && replicaId == defaultReplicaId) { return RegionInfoBuilder.FIRST_META_REGIONINFO; } byte[] startKey = null; byte[] endKey = null; if (proto.hasStartKey()) { startKey = proto.getStartKey().toByteArray(); } if (proto.hasEndKey()) { endKey = proto.getEndKey().toByteArray(); } boolean split = false; if (proto.hasSplit()) { split = proto.getSplit(); } RegionInfoBuilder rib = RegionInfoBuilder.newBuilder(tableName) .setStartKey(startKey) .setEndKey(endKey) .setRegionId(regionId) .setReplicaId(replicaId) .setSplit(split); if (proto.hasOffline()) { rib.setOffline(proto.getOffline()); } return rib.build(); }
Example 10
Source File: TestRegionInfoBuilder.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testConvert() { final TableName tableName = TableName.valueOf("ns1:" + name.getTableName().getQualifierAsString()); byte[] startKey = Bytes.toBytes("startKey"); byte[] endKey = Bytes.toBytes("endKey"); boolean split = false; long regionId = System.currentTimeMillis(); int replicaId = 42; RegionInfo ri = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey).setEndKey(endKey) .setSplit(split).setRegionId(regionId).setReplicaId(replicaId).build(); // convert two times, compare RegionInfo convertedRi = ProtobufUtil.toRegionInfo(ProtobufUtil.toRegionInfo(ri)); assertEquals(ri, convertedRi); // test convert RegionInfo without replicaId HBaseProtos.RegionInfo info = HBaseProtos.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(); convertedRi = ProtobufUtil.toRegionInfo(info); RegionInfo expectedRi = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey) .setEndKey(endKey).setSplit(split).setRegionId(regionId).setReplicaId(0).build(); assertEquals(expectedRi, convertedRi); }
Example 11
Source File: MasterAnnotationReadingPriorityFunction.java From hbase with Apache License 2.0 | 4 votes |
@Override public int getPriority(RPCProtos.RequestHeader header, Message param, User user) { // Yes this is copy pasted from the base class but it keeps from having to look in the // annotatedQos table twice something that could get costly since this is called for // every single RPC request. int priorityByAnnotation = getAnnotatedPriority(header); if (priorityByAnnotation >= 0) { // no one can have higher priority than meta transition. if (priorityByAnnotation >= META_TRANSITION_QOS) { return META_TRANSITION_QOS - 1; } else { return priorityByAnnotation; } } // If meta is moving then all the other of reports of state transitions will be // un able to edit meta. Those blocked reports should not keep the report that opens meta from // running. Hence all reports of meta transition should always be in a different thread. // This keeps from deadlocking the cluster. if (param instanceof RegionServerStatusProtos.ReportRegionStateTransitionRequest) { // Regions are moving. Lets see which ones. RegionServerStatusProtos.ReportRegionStateTransitionRequest tRequest = (RegionServerStatusProtos.ReportRegionStateTransitionRequest) param; for (RegionServerStatusProtos.RegionStateTransition rst : tRequest.getTransitionList()) { if (rst.getRegionInfoList() != null) { for (HBaseProtos.RegionInfo info : rst.getRegionInfoList()) { TableName tn = ProtobufUtil.toTableName(info.getTableName()); if (TableName.META_TABLE_NAME.equals(tn)) { return META_TRANSITION_QOS; } } } } return HConstants.HIGH_QOS; } // also use HIGH_QOS for region server report if (param instanceof RegionServerStatusProtos.RegionServerReportRequest) { return HConstants.HIGH_QOS; } // Handle the rest of the different reasons to change priority. return getBasePriority(header, param); }