Search in sources :

Example 1 with GetResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetResponse in project hbase by apache.

the class TestClientNoCluster method doMetaGetResponse.

static GetResponse doMetaGetResponse(final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta, final GetRequest request) {
    ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder();
    ByteString row = request.getGet().getRow();
    Pair<HRegionInfo, ServerName> p = meta.get(row.toByteArray());
    if (p != null) {
        resultBuilder.addCell(getRegionInfo(row, p.getFirst()));
        resultBuilder.addCell(getServer(row, p.getSecond()));
    }
    resultBuilder.addCell(getStartCode(row));
    GetResponse.Builder builder = GetResponse.newBuilder();
    builder.setResult(resultBuilder.build());
    return builder.build();
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) ServerName(org.apache.hadoop.hbase.ServerName) GetResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetResponse) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)

Example 2 with GetResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetResponse in project hbase by apache.

the class RSRpcServices method get.

/**
   * Get data from a table.
   *
   * @param controller the RPC controller
   * @param request the get request
   * @throws ServiceException
   */
@Override
public GetResponse get(final RpcController controller, final GetRequest request) throws ServiceException {
    long before = EnvironmentEdgeManager.currentTime();
    OperationQuota quota = null;
    try {
        checkOpen();
        requestCount.increment();
        rpcGetRequestCount.increment();
        Region region = getRegion(request.getRegion());
        GetResponse.Builder builder = GetResponse.newBuilder();
        ClientProtos.Get get = request.getGet();
        Boolean existence = null;
        Result r = null;
        RpcCallContext context = RpcServer.getCurrentCall();
        quota = getQuotaManager().checkQuota(region, OperationQuota.OperationType.GET);
        Get clientGet = ProtobufUtil.toGet(get);
        if (get.getExistenceOnly() && region.getCoprocessorHost() != null) {
            existence = region.getCoprocessorHost().preExists(clientGet);
        }
        if (existence == null) {
            if (context != null) {
                r = get(clientGet, ((HRegion) region), null, context);
            } else {
                // for test purpose
                r = region.get(clientGet);
            }
            if (get.getExistenceOnly()) {
                boolean exists = r.getExists();
                if (region.getCoprocessorHost() != null) {
                    exists = region.getCoprocessorHost().postExists(clientGet, exists);
                }
                existence = exists;
            }
        }
        if (existence != null) {
            ClientProtos.Result pbr = ProtobufUtil.toResult(existence, region.getRegionInfo().getReplicaId() != 0);
            builder.setResult(pbr);
        } else if (r != null) {
            ClientProtos.Result pbr;
            if (isClientCellBlockSupport(context) && controller instanceof HBaseRpcController && VersionInfoUtil.hasMinimumVersion(context.getClientVersionInfo(), 1, 3)) {
                pbr = ProtobufUtil.toResultNoData(r);
                ((HBaseRpcController) controller).setCellScanner(CellUtil.createCellScanner(r.rawCells()));
                addSize(context, r, null);
            } else {
                pbr = ProtobufUtil.toResult(r);
            }
            builder.setResult(pbr);
        }
        if (r != null) {
            quota.addGetResult(r);
        }
        return builder.build();
    } catch (IOException ie) {
        throw new ServiceException(ie);
    } finally {
        if (regionServer.metricsRegionServer != null) {
            regionServer.metricsRegionServer.updateGet(EnvironmentEdgeManager.currentTime() - before);
        }
        if (quota != null) {
            quota.close();
        }
    }
}
Also used : RpcCallContext(org.apache.hadoop.hbase.ipc.RpcCallContext) OperationQuota(org.apache.hadoop.hbase.quotas.OperationQuota) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) GetResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetResponse) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) Result(org.apache.hadoop.hbase.client.Result) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) Get(org.apache.hadoop.hbase.client.Get) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Aggregations

GetResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetResponse)2 RegionActionResult (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 ServerName (org.apache.hadoop.hbase.ServerName)1 Get (org.apache.hadoop.hbase.client.Get)1 Result (org.apache.hadoop.hbase.client.Result)1 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)1 RpcCallContext (org.apache.hadoop.hbase.ipc.RpcCallContext)1 OperationQuota (org.apache.hadoop.hbase.quotas.OperationQuota)1 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)1