org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos Java Examples

The following examples show how to use org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos. 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: DeleteTableProcedure.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.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 #2
Source File: SingleColumnValueFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
FilterProtos.SingleColumnValueFilter convert() {
  FilterProtos.SingleColumnValueFilter.Builder builder =
    FilterProtos.SingleColumnValueFilter.newBuilder();
  if (this.columnFamily != null) {
    builder.setColumnFamily(UnsafeByteOperations.unsafeWrap(this.columnFamily));
  }
  if (this.columnQualifier != null) {
    builder.setColumnQualifier(UnsafeByteOperations.unsafeWrap(this.columnQualifier));
  }
  HBaseProtos.CompareType compareOp = CompareType.valueOf(this.op.name());
  builder.setCompareOp(compareOp);
  builder.setComparator(ProtobufUtil.toComparator(this.comparator));
  builder.setFilterIfMissing(this.filterIfMissing);
  builder.setLatestVersionOnly(this.latestVersionOnly);

  return builder.build();
}
 
Example #3
Source File: TableState.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Covert to PB version of State
 *
 * @return PB
 */
public HBaseProtos.TableState.State convert() {
  HBaseProtos.TableState.State state;
  switch (this) {
  case ENABLED:
    state = HBaseProtos.TableState.State.ENABLED;
    break;
  case DISABLED:
    state = HBaseProtos.TableState.State.DISABLED;
    break;
  case DISABLING:
    state = HBaseProtos.TableState.State.DISABLING;
    break;
  case ENABLING:
    state = HBaseProtos.TableState.State.ENABLING;
    break;
  default:
    throw new IllegalStateException(this.toString());
  }
  return state;
}
 
Example #4
Source File: TestThrottleSettings.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncompatibleThrottleTypes() throws IOException {
  TimedQuota requestsQuota = TimedQuota.newBuilder().setSoftLimit(10)
      .setScope(QuotaProtos.QuotaScope.MACHINE)
      .setTimeUnit(HBaseProtos.TimeUnit.MINUTES).build();
  ThrottleRequest requestsQuotaReq = ThrottleRequest.newBuilder().setTimedQuota(requestsQuota)
      .setType(QuotaProtos.ThrottleType.REQUEST_NUMBER).build();
  ThrottleSettings orig = new ThrottleSettings("joe", null, null, null, requestsQuotaReq);

  TimedQuota readsQuota = TimedQuota.newBuilder().setSoftLimit(10)
      .setScope(QuotaProtos.QuotaScope.MACHINE)
      .setTimeUnit(HBaseProtos.TimeUnit.SECONDS).build();
  ThrottleRequest readsQuotaReq = ThrottleRequest.newBuilder().setTimedQuota(readsQuota)
      .setType(QuotaProtos.ThrottleType.READ_NUMBER).build();

  try {
    orig.merge(new ThrottleSettings("joe", null, null, null, readsQuotaReq));
    fail("A read throttle should not be capable of being merged with a request quota");
  } catch (IllegalArgumentException e) {
    // Pass
  }
}
 
Example #5
Source File: RegionServerSpaceQuotaManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the protobuf message to inform the Master of files being archived.
 *
 * @param tn The table the files previously belonged to.
 * @param archivedFiles The files and their size in bytes that were archived.
 * @return The protobuf representation
 */
public RegionServerStatusProtos.FileArchiveNotificationRequest buildFileArchiveRequest(
    TableName tn, Collection<Entry<String,Long>> archivedFiles) {
  RegionServerStatusProtos.FileArchiveNotificationRequest.Builder builder =
      RegionServerStatusProtos.FileArchiveNotificationRequest.newBuilder();
  HBaseProtos.TableName protoTn = ProtobufUtil.toProtoTableName(tn);
  for (Entry<String,Long> archivedFile : archivedFiles) {
    RegionServerStatusProtos.FileArchiveNotificationRequest.FileWithSize fws =
        RegionServerStatusProtos.FileArchiveNotificationRequest.FileWithSize.newBuilder()
            .setName(archivedFile.getKey())
            .setSize(archivedFile.getValue())
            .setTableName(protoTn)
            .build();
    builder.addArchivedFiles(fws);
  }
  final RegionServerStatusProtos.FileArchiveNotificationRequest request = builder.build();
  if (LOG.isTraceEnabled()) {
    LOG.trace("Reporting file archival to Master: " + TextFormat.shortDebugString(request));
  }
  return request;
}
 
Example #6
Source File: RegionInfo.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * @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 #7
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static ScanMetrics toScanMetrics(final byte[] bytes) {
  MapReduceProtos.ScanMetrics pScanMetrics = null;
  try {
    pScanMetrics = MapReduceProtos.ScanMetrics.parseFrom(bytes);
  } catch (InvalidProtocolBufferException e) {
    // Ignored there are just no key values to add.
  }
  ScanMetrics scanMetrics = new ScanMetrics();
  if (pScanMetrics != null) {
    for (HBaseProtos.NameInt64Pair pair : pScanMetrics.getMetricsList()) {
      if (pair.hasName() && pair.hasValue()) {
        scanMetrics.setCounter(pair.getName(), pair.getValue());
      }
    }
  }
  return scanMetrics;
}
 
Example #8
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) {
  List<HBaseProtos.TableName> tables = new ArrayList<>(pojo.getTables().size());
  for (TableName arg : pojo.getTables()) {
    tables.add(ProtobufUtil.toProtoTableName(arg));
  }
  List<HBaseProtos.ServerName> hostports = new ArrayList<>(pojo.getServers().size());
  for (Address el : pojo.getServers()) {
    hostports.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
        .setPort(el.getPort()).build());
  }
  List<NameStringPair> configuration = pojo.getConfiguration().entrySet()
      .stream().map(entry -> NameStringPair.newBuilder()
          .setName(entry.getKey()).setValue(entry.getValue()).build())
      .collect(Collectors.toList());
  return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName()).addAllServers(hostports)
      .addAllTables(tables).addAllConfiguration(configuration).build();
}
 
Example #9
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 #10
Source File: TableNamespaceManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void loadNamespaceIntoCache() throws IOException {
  try (Table table = masterServices.getConnection().getTable(TableName.META_TABLE_NAME);
    ResultScanner scanner = table.getScanner(HConstants.NAMESPACE_FAMILY)) {
    for (Result result;;) {
      result = scanner.next();
      if (result == null) {
        break;
      }
      Cell cell = result.getColumnLatestCell(HConstants.NAMESPACE_FAMILY,
        HConstants.NAMESPACE_COL_DESC_QUALIFIER);
      NamespaceDescriptor ns = ProtobufUtil
        .toNamespaceDescriptor(HBaseProtos.NamespaceDescriptor.parseFrom(CodedInputStream
          .newInstance(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())));
      cache.put(ns.getName(), ns);
    }
  }
}
 
Example #11
Source File: RegionInfo.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Parses an RegionInfo instance from the passed in stream.
 * Presumes the RegionInfo was serialized to the stream with
 * {@link #toDelimitedByteArray(RegionInfo)}.
 * @return An instance of RegionInfo.
 */
static RegionInfo parseFrom(final DataInputStream in) throws IOException {
  // I need to be able to move back in the stream if this is not a pb
  // serialization so I can do the Writable decoding instead.
  int pblen = ProtobufUtil.lengthOfPBMagic();
  byte [] pbuf = new byte[pblen];
  if (in.markSupported()) { //read it with mark()
    in.mark(pblen);
  }

  //assumption: if Writable serialization, it should be longer than pblen.
  int read = in.read(pbuf);
  if (read != pblen) throw new IOException("read=" + read + ", wanted=" + pblen);
  if (ProtobufUtil.isPBMagicPrefix(pbuf)) {
    return ProtobufUtil.toRegionInfo(HBaseProtos.RegionInfo.parseDelimitedFrom(in));
  } else {
    throw new IOException("PB encoded RegionInfo expected");
  }
}
 
Example #12
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Convert a ServerName to a protocol buffer ServerName
 *
 * @param serverName the ServerName to convert
 * @return the converted protocol buffer ServerName
 * @see #toServerName(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ServerName)
 */
public static HBaseProtos.ServerName toServerName(final ServerName serverName) {
  if (serverName == null) {
    return null;
  }
  HBaseProtos.ServerName.Builder builder =
    HBaseProtos.ServerName.newBuilder();
  builder.setHostName(serverName.getHostname());
  if (serverName.getPort() >= 0) {
    builder.setPort(serverName.getPort());
  }
  if (serverName.getStartcode() >= 0) {
    builder.setStartCode(serverName.getStartcode());
  }
  return builder.build();
}
 
Example #13
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public MasterProtos.ScheduleServerCrashProcedureResponse scheduleServerCrashProcedure(
    RpcController controller, MasterProtos.ScheduleServerCrashProcedureRequest request)
    throws ServiceException {
  List<Long> pids = new ArrayList<>();
  for (HBaseProtos.ServerName sn: request.getServerNameList()) {
    ServerName serverName = ProtobufUtil.toServerName(sn);
    LOG.info("{} schedule ServerCrashProcedure for {}",
        this.master.getClientIdAuditPrefix(), serverName);
    if (shouldSubmitSCP(serverName)) {
      pids.add(this.master.getServerManager().expireServer(serverName, true));
    } else {
      pids.add(Procedure.NO_PROC_ID);
    }
  }
  return MasterProtos.ScheduleServerCrashProcedureResponse.newBuilder().addAllPid(pids).build();
}
 
Example #14
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public MoveServersResponse moveServers(RpcController controller, MoveServersRequest request)
    throws ServiceException {
  Set<Address> hostPorts = Sets.newHashSet();
  MoveServersResponse.Builder builder = MoveServersResponse.newBuilder();
  for (HBaseProtos.ServerName el : request.getServersList()) {
    hostPorts.add(Address.fromParts(el.getHostName(), el.getPort()));
  }
  LOG.info(master.getClientIdAuditPrefix() + " move servers " + hostPorts + " to rsgroup " +
      request.getTargetGroup());
  try {
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().preMoveServers(hostPorts, request.getTargetGroup());
    }
    master.getRSGroupInfoManager().moveServers(hostPorts, request.getTargetGroup());
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().postMoveServers(hostPorts, request.getTargetGroup());
    }
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return builder.build();
}
 
Example #15
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static HBaseProtos.CacheEvictionStats toCacheEvictionStats(
    CacheEvictionStats cacheEvictionStats) {
  HBaseProtos.CacheEvictionStats.Builder builder
      = HBaseProtos.CacheEvictionStats.newBuilder();
  for (Map.Entry<byte[], Throwable> entry : cacheEvictionStats.getExceptions().entrySet()) {
    builder.addException(
        RegionExceptionMessage.newBuilder()
        .setRegion(RequestConverter.buildRegionSpecifier(
                RegionSpecifierType.REGION_NAME, entry.getKey()))
        .setException(ResponseConverter.buildException(entry.getValue()))
        .build()
    );
  }
  return builder
      .setEvictedBlocks(cacheEvictionStats.getEvictedBlocks())
      .setMaxCacheSize(cacheEvictionStats.getMaxCacheSize())
      .build();
}
 
Example #16
Source File: ServerMetricsBuilder.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static ServerMetrics toServerMetrics(ServerName serverName, int versionNumber,
    String version, ClusterStatusProtos.ServerLoad serverLoadPB) {
  return ServerMetricsBuilder.newBuilder(serverName)
    .setRequestCountPerSecond(serverLoadPB.getNumberOfRequests())
    .setRequestCount(serverLoadPB.getTotalNumberOfRequests())
    .setInfoServerPort(serverLoadPB.getInfoServerPort())
    .setMaxHeapSize(new Size(serverLoadPB.getMaxHeapMB(), Size.Unit.MEGABYTE))
    .setUsedHeapSize(new Size(serverLoadPB.getUsedHeapMB(), Size.Unit.MEGABYTE))
    .setCoprocessorNames(serverLoadPB.getCoprocessorsList().stream()
      .map(HBaseProtos.Coprocessor::getName).collect(Collectors.toList()))
    .setRegionMetrics(serverLoadPB.getRegionLoadsList().stream()
      .map(RegionMetricsBuilder::toRegionMetrics).collect(Collectors.toList()))
      .setUserMetrics(serverLoadPB.getUserLoadsList().stream()
          .map(UserMetricsBuilder::toUserMetrics).collect(Collectors.toList()))
    .setReplicationLoadSources(serverLoadPB.getReplLoadSourceList().stream()
        .map(ProtobufUtil::toReplicationLoadSource).collect(Collectors.toList()))
    .setReplicationLoadSink(serverLoadPB.hasReplLoadSink()
      ? ProtobufUtil.toReplicationLoadSink(serverLoadPB.getReplLoadSink())
      : null)
    .setReportTimestamp(serverLoadPB.getReportEndTime())
    .setLastReportTimestamp(serverLoadPB.getReportStartTime()).setVersionNumber(versionNumber)
    .setVersion(version).build();
}
 
Example #17
Source File: RSGroupAdminServiceImpl.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void removeServers(RpcController controller, RemoveServersRequest request,
    RpcCallback<RemoveServersResponse> done) {
  RemoveServersResponse.Builder builder = RemoveServersResponse.newBuilder();
  Set<Address> servers = Sets.newHashSet();
  for (HBaseProtos.ServerName el : request.getServersList()) {
    servers.add(Address.fromParts(el.getHostName(), el.getPort()));
  }
  LOG.info(
    master.getClientIdAuditPrefix() + " remove decommissioned servers from rsgroup: " + servers);
  try {
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().preRemoveServers(servers);
    }
    rsGroupInfoManager.removeServers(servers);
    if (master.getMasterCoprocessorHost() != null) {
      master.getMasterCoprocessorHost().postRemoveServers(servers);
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  }
  done.run(builder.build());
}
 
Example #18
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Move given set of servers and tables to the specified target RegionServer group.
 * @param servers set of servers to move
 * @param tables set of tables to move
 * @param targetGroup the target group name
 * @throws IOException if moving the server and tables fail
 */
public void moveServersAndTables(Set<Address> servers, Set<TableName> tables, String targetGroup)
  throws IOException {
  MoveServersAndTablesRequest.Builder builder =
    MoveServersAndTablesRequest.newBuilder().setTargetGroup(targetGroup);
  for (Address el : servers) {
    builder.addServers(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
      .setPort(el.getPort()).build());
  }
  for (TableName tableName : tables) {
    builder.addTableName(ProtobufUtil.toProtoTableName(tableName));
    if (!admin.tableExists(tableName)) {
      throw new TableNotFoundException(tableName);
    }
  }
  try {
    stub.moveServersAndTables(null, builder.build());
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example #19
Source File: TestMetaCache.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Throw some exceptions. Mostly throw exceptions which do not clear meta cache.
 * Periodically throw NotSevingRegionException which clears the meta cache.
 * @throws ServiceException
 */
private void throwSomeExceptions(FakeRSRpcServices rpcServices,
                                 HBaseProtos.RegionSpecifier regionSpec)
    throws ServiceException {
  if (!isTestTable(rpcServices, regionSpec)) {
    return;
  }

  numReqs++;
  // Succeed every 5 request, throw cache clearing exceptions twice every 5 requests and throw
  // meta cache preserving exceptions otherwise.
  if (numReqs % 5 ==0) {
    return;
  } else if (numReqs % 5 == 1 || numReqs % 5 == 2) {
    throw new ServiceException(new NotServingRegionException());
  }
  // Round robin between different special exceptions.
  // This is not ideal since exception types are not tied to the operation performed here,
  // But, we don't really care here if we throw MultiActionTooLargeException while doing
  // single Gets.
  expCount++;
  Throwable t = metaCachePreservingExceptions.get(
      expCount % metaCachePreservingExceptions.size());
  throw new ServiceException(t);
}
 
Example #20
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static TableName[] getTableNameArray(List<HBaseProtos.TableName> tableNamesList) {
  if (tableNamesList == null) {
    return new TableName[0];
  }
  TableName[] tableNames = new TableName[tableNamesList.size()];
  for (int i = 0; i < tableNamesList.size(); i++) {
    tableNames[i] = toTableName(tableNamesList.get(i));
  }
  return tableNames;
}
 
Example #21
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static NamespaceDescriptor toNamespaceDescriptor(HBaseProtos.NamespaceDescriptor desc) {
  NamespaceDescriptor.Builder b = NamespaceDescriptor.create(desc.getName().toStringUtf8());
  for (HBaseProtos.NameStringPair prop : desc.getConfigurationList()) {
    b.addConfiguration(prop.getName(), prop.getValue());
  }
  return b.build();
}
 
Example #22
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ServerName from the passed in data bytes.
 * @param data Data with a serialize server name in it; can handle the old style
 * servername where servername was host and port.  Works too with data that
 * begins w/ the pb 'PBUF' magic and that is then followed by a protobuf that
 * has a serialized {@link ServerName} in it.
 * @return Returns null if <code>data</code> is null else converts passed data
 * to a ServerName instance.
 * @throws DeserializationException
 */
public static ServerName parseServerNameFrom(final byte [] data) throws DeserializationException {
  if (data == null || data.length <= 0) return null;
  if (ProtobufMagic.isPBMagicPrefix(data)) {
    int prefixLen = ProtobufMagic.lengthOfPBMagic();
    try {
      ZooKeeperProtos.Master rss =
        ZooKeeperProtos.Master.PARSER.parseFrom(data, prefixLen, data.length - prefixLen);
      org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ServerName sn =
          rss.getMaster();
      return ServerName.valueOf(sn.getHostName(), sn.getPort(), sn.getStartCode());
    } catch (/*InvalidProtocolBufferException*/IOException e) {
      // A failed parse of the znode is pretty catastrophic. Rather than loop
      // retrying hoping the bad bytes will changes, and rather than change
      // the signature on this method to add an IOE which will send ripples all
      // over the code base, throw a RuntimeException.  This should "never" happen.
      // Fail fast if it does.
      throw new DeserializationException(e);
    }
  }
  // The str returned could be old style -- pre hbase-1502 -- which was
  // hostname and port seperated by a colon rather than hostname, port and
  // startcode delimited by a ','.
  String str = Bytes.toString(data);
  int index = str.indexOf(ServerName.SERVERNAME_SEPARATOR);
  if (index != -1) {
    // Presume its ServerName serialized with versioned bytes.
    return ServerName.parseVersionedServerName(data);
  }
  // Presume it a hostname:port format.
  String hostname = Addressing.parseHostname(str);
  int port = Addressing.parsePort(str);
  return ServerName.valueOf(hostname, port, -1L);
}
 
Example #23
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);
    }
}
 
Example #24
Source File: TestRegionInfo.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: TestMasterQosFunction.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: ProtobufUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #27
Source File: CompareFilter.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @return A pb instance to represent this instance.
 */
FilterProtos.CompareFilter convert() {
  FilterProtos.CompareFilter.Builder builder =
    FilterProtos.CompareFilter.newBuilder();
  HBaseProtos.CompareType compareOp = CompareType.valueOf(this.op.name());
  builder.setCompareOp(compareOp);
  if (this.comparator != null) builder.setComparator(ProtobufUtil.toComparator(this.comparator));
  return builder.build();
}
 
Example #28
Source File: TestMetaCache.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected boolean isTestTable(FakeRSRpcServices rpcServices,
                              HBaseProtos.RegionSpecifier regionSpec) throws ServiceException {
  try {
    return TABLE_NAME.equals(
        rpcServices.getRegion(regionSpec).getTableDescriptor().getTableName());
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
 
Example #29
Source File: ZKConnectionRegistry.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<ServerName> getActiveMaster() {
  return getAndConvert(znodePaths.masterAddressZNode, ZKConnectionRegistry::getMasterProto)
      .thenApply(proto -> {
        if (proto == null) {
          return null;
        }
        HBaseProtos.ServerName snProto = proto.getMaster();
        return ServerName.valueOf(snProto.getHostName(), snProto.getPort(),
          snProto.getStartCode());
      });
}
 
Example #30
Source File: HBCK2.java    From hbase-operator-tools with Apache License 2.0 5 votes vote down vote up
List<Long> scheduleRecoveries(Hbck hbck, String[] args) throws IOException {
  List<HBaseProtos.ServerName> serverNames = new ArrayList<>();
  for (String serverName: args) {
    serverNames.add(parseServerName(serverName));
  }
  return hbck.scheduleServerCrashProcedure(serverNames);
}