Java Code Examples for org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil#toTableDescriptor()

The following examples show how to use org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil#toTableDescriptor() . 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 vote down vote up
@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 vote down vote up
@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: ModifyTableProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
protected void deserializeStateData(ProcedureStateSerializer serializer)
    throws IOException {
  super.deserializeStateData(serializer);

  MasterProcedureProtos.ModifyTableStateData modifyTableMsg =
      serializer.deserialize(MasterProcedureProtos.ModifyTableStateData.class);
  setUser(MasterProcedureUtil.toUserInfo(modifyTableMsg.getUserInfo()));
  modifiedTableDescriptor = ProtobufUtil.toTableDescriptor(modifyTableMsg.getModifiedTableSchema());
  deleteColumnFamilyInModify = modifyTableMsg.getDeleteColumnFamilyInModify();
  shouldCheckDescriptor = modifyTableMsg.hasShouldCheckDescriptor()
      ? modifyTableMsg.getShouldCheckDescriptor() : false;

  if (modifyTableMsg.hasUnmodifiedTableSchema()) {
    unmodifiedTableDescriptor =
        ProtobufUtil.toTableDescriptor(modifyTableMsg.getUnmodifiedTableSchema());
  }
}
 
Example 4
Source File: CloneSnapshotProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public CreateTableResponse createTable(RpcController controller, CreateTableRequest req)
    throws ServiceException {
  TableDescriptor tableDescriptor = ProtobufUtil.toTableDescriptor(req.getTableSchema());
  byte [][] splitKeys = ProtobufUtil.getSplitKeysArray(req);
  try {
    long procId =
        master.createTable(tableDescriptor, splitKeys, req.getNonceGroup(), req.getNonce());
    LOG.info(master.getClientIdAuditPrefix() + " procedure request for creating table: " +
            req.getTableSchema().getTableName() + " procId is: " + procId);
    return CreateTableResponse.newBuilder().setProcId(procId).build();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
 
Example 6
Source File: TableSnapshotInputFormatImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
  int len = in.readInt();
  byte[] buf = new byte[len];
  in.readFully(buf);
  TableSnapshotRegionSplit split = TableSnapshotRegionSplit.parser().parseFrom(buf);
  this.htd = ProtobufUtil.toTableDescriptor(split.getTable());
  this.regionInfo = ProtobufUtil.toRegionInfo(split.getRegion());
  List<String> locationsList = split.getLocationsList();
  this.locations = locationsList.toArray(new String[locationsList.size()]);

  this.scan = Bytes.toString(Bytes.readByteArray(in));
  this.restoreDir = Bytes.toString(Bytes.readByteArray(in));
}
 
Example 7
Source File: TableDescriptorBuilder.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @param bytes A pb serialized {@link ModifyableTableDescriptor} instance
 * with pb magic prefix
 * @return An instance of {@link ModifyableTableDescriptor} made from
 * <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray()
 */
private static TableDescriptor parseFrom(final byte[] bytes)
        throws DeserializationException {
  if (!ProtobufUtil.isPBMagicPrefix(bytes)) {
    throw new DeserializationException("Expected PB encoded ModifyableTableDescriptor");
  }
  int pblen = ProtobufUtil.lengthOfPBMagic();
  HBaseProtos.TableSchema.Builder builder = HBaseProtos.TableSchema.newBuilder();
  try {
    ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
    return ProtobufUtil.toTableDescriptor(builder.build());
  } catch (IOException e) {
    throw new DeserializationException(e);
  }
}
 
Example 8
Source File: AdapterPartition.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public PartitionDescriptor getDescriptor() throws IOException {
    if (!useProxy) {
        try {
            return delegate.getDescriptor();
        } catch (AccessDeniedException ade) {
            activateProxy(ade);
        }
    }

    try {
        try (java.sql.Connection jdbcConnection = connectionPool.getConnection();
             PreparedStatement statement = jdbcConnection.prepareStatement("call SYSCS_UTIL.SYSCS_HBASE_OPERATION(?, ?, ?)")) {
            statement.setString(1, tableName.toString());
            statement.setString(2, "descriptor");
            statement.setNull(3, Types.BLOB);
            try (ResultSet rs = statement.executeQuery()) {
                if (!rs.next()) {
                    throw new IOException("No results for descriptor");
                }

                Blob blob = rs.getBlob(1);
                byte[] bytes =  blob.getBytes(1, (int) blob.length());
                HBaseProtos.TableSchema result = HBaseProtos.TableSchema.parseFrom(bytes);
                TableDescriptor d = ProtobufUtil.toTableDescriptor(result);
                HTableDescriptor htd = new HTableDescriptor(d);
                return new HPartitionDescriptor(htd);
            }
        }
    } catch (SQLException e) {
        throw new IOException(e);
    }
}