Search in sources :

Example 21 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message in project hbase by apache.

the class AbstractRpcClient method callBlockingMethod.

/**
 * Make a blocking call. Throws exceptions if there are network problems or if the remote code
 * threw an exception.
 * @param ticket Be careful which ticket you pass. A new user will mean a new Connection.
 *          {@link UserProvider#getCurrent()} makes a new instance of User each time so will be a
 *          new Connection each time.
 * @return A pair with the Message response and the Cell data (if any).
 */
private Message callBlockingMethod(Descriptors.MethodDescriptor md, HBaseRpcController hrc, Message param, Message returnType, final User ticket, final Address isa) throws ServiceException {
    BlockingRpcCallback<Message> done = new BlockingRpcCallback<>();
    callMethod(md, hrc, param, returnType, ticket, isa, done);
    Message val;
    try {
        val = done.get();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
    if (hrc.failed()) {
        throw new ServiceException(hrc.getFailed());
    } else {
        return val;
    }
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) IOException(java.io.IOException)

Example 22 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message in project hbase by apache.

the class BlockingRpcConnection method readResponse.

/*
   * Receive a response. Because only one receiver, so no synchronization on in.
   */
private void readResponse() {
    Call call = null;
    boolean expectedCall = false;
    try {
        // See HBaseServer.Call.setResponse for where we write out the response.
        // Total size of the response. Unused. But have to read it in anyways.
        int totalSize = in.readInt();
        // Read the header
        ResponseHeader responseHeader = ResponseHeader.parseDelimitedFrom(in);
        int id = responseHeader.getCallId();
        // call.done have to be set before leaving this method
        call = calls.remove(id);
        expectedCall = (call != null && !call.isDone());
        if (!expectedCall) {
            // So we got a response for which we have no corresponding 'call' here on the client-side.
            // We probably timed out waiting, cleaned up all references, and now the server decides
            // to return a response. There is nothing we can do w/ the response at this stage. Clean
            // out the wire of the response so its out of the way and we can get other responses on
            // this connection.
            int readSoFar = getTotalSizeWhenWrittenDelimited(responseHeader);
            int whatIsLeftToRead = totalSize - readSoFar;
            IOUtils.skipFully(in, whatIsLeftToRead);
            if (call != null) {
                call.callStats.setResponseSizeBytes(totalSize);
                call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - call.callStats.getStartTime());
            }
            return;
        }
        if (responseHeader.hasException()) {
            ExceptionResponse exceptionResponse = responseHeader.getException();
            RemoteException re = createRemoteException(exceptionResponse);
            call.setException(re);
            call.callStats.setResponseSizeBytes(totalSize);
            call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - call.callStats.getStartTime());
            if (isFatalConnectionException(exceptionResponse)) {
                synchronized (this) {
                    closeConn(re);
                }
            }
        } else {
            Message value = null;
            if (call.responseDefaultType != null) {
                Builder builder = call.responseDefaultType.newBuilderForType();
                ProtobufUtil.mergeDelimitedFrom(builder, in);
                value = builder.build();
            }
            CellScanner cellBlockScanner = null;
            if (responseHeader.hasCellBlockMeta()) {
                int size = responseHeader.getCellBlockMeta().getLength();
                byte[] cellBlock = new byte[size];
                IOUtils.readFully(this.in, cellBlock, 0, cellBlock.length);
                cellBlockScanner = this.rpcClient.cellBlockBuilder.createCellScanner(this.codec, this.compressor, cellBlock);
            }
            call.setResponse(value, cellBlockScanner);
            call.callStats.setResponseSizeBytes(totalSize);
            call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - call.callStats.getStartTime());
        }
    } catch (IOException e) {
        if (expectedCall) {
            call.setException(e);
        }
        if (e instanceof SocketTimeoutException) {
            // {@link ConnectionId#rpcTimeout}.
            if (LOG.isTraceEnabled()) {
                LOG.trace("ignored", e);
            }
        } else {
            synchronized (this) {
                closeConn(e);
            }
        }
    }
}
Also used : ResponseHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ResponseHeader) ExceptionResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ExceptionResponse) SocketTimeoutException(java.net.SocketTimeoutException) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) Builder(org.apache.hbase.thirdparty.com.google.protobuf.Message.Builder) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) IPCUtil.createRemoteException(org.apache.hadoop.hbase.ipc.IPCUtil.createRemoteException) RemoteException(org.apache.hadoop.ipc.RemoteException) CellScanner(org.apache.hadoop.hbase.CellScanner)

Example 23 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message in project hbase by apache.

the class AsyncAggregationClient method std.

public static <R, S, P extends Message, Q extends Message, T extends Message> CompletableFuture<Double> std(AsyncTable<?> table, ColumnInterpreter<R, S, P, Q, T> ci, Scan scan) {
    CompletableFuture<Double> future = new CompletableFuture<>();
    AggregateRequest req;
    try {
        req = validateArgAndGetPB(scan, ci, false);
    } catch (IOException e) {
        future.completeExceptionally(e);
        return future;
    }
    AbstractAggregationCallback<Double> callback = new AbstractAggregationCallback<Double>(future) {

        private S sum;

        private S sumSq;

        private long count;

        @Override
        protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException {
            if (resp.getFirstPartCount() > 0) {
                sum = ci.add(sum, getPromotedValueFromProto(ci, resp, 0));
                sumSq = ci.add(sumSq, getPromotedValueFromProto(ci, resp, 1));
                count += resp.getSecondPart().asReadOnlyByteBuffer().getLong();
            }
        }

        @Override
        protected Double getFinalResult() {
            double avg = ci.divideForAvg(sum, count);
            double avgSq = ci.divideForAvg(sumSq, count);
            return Math.sqrt(avgSq - avg * avg);
        }
    };
    table.<AggregateService, AggregateResponse>coprocessorService(AggregateService::newStub, (stub, controller, rpcCallback) -> stub.getStd(controller, req, rpcCallback), callback).fromRow(nullToEmpty(scan.getStartRow()), scan.includeStartRow()).toRow(nullToEmpty(scan.getStopRow()), scan.includeStopRow()).execute();
    return future;
}
Also used : AdvancedScanResultConsumer(org.apache.hadoop.hbase.client.AdvancedScanResultConsumer) FutureUtils.addListener(org.apache.hadoop.hbase.util.FutureUtils.addListener) CoprocessorCallback(org.apache.hadoop.hbase.client.AsyncTable.CoprocessorCallback) ColumnInterpreter(org.apache.hadoop.hbase.coprocessor.ColumnInterpreter) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) Result(org.apache.hadoop.hbase.client.Result) CompletableFuture(java.util.concurrent.CompletableFuture) AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) HConstants(org.apache.hadoop.hbase.HConstants) Map(java.util.Map) AggregationHelper.validateArgAndGetPB(org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.validateArgAndGetPB) NoSuchElementException(java.util.NoSuchElementException) Cell(org.apache.hadoop.hbase.Cell) Bytes(org.apache.hadoop.hbase.util.Bytes) ReflectionUtils(org.apache.hadoop.hbase.util.ReflectionUtils) IOException(java.io.IOException) NavigableSet(java.util.NavigableSet) NavigableMap(java.util.NavigableMap) AggregateService(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService) Scan(org.apache.hadoop.hbase.client.Scan) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) TreeMap(java.util.TreeMap) AggregationHelper.getParsedGenericInstance(org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.getParsedGenericInstance) AsyncTable(org.apache.hadoop.hbase.client.AsyncTable) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CompletableFuture(java.util.concurrent.CompletableFuture) AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException)

Example 24 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message in project hbase by apache.

the class AsyncAggregationClient method rowCount.

public static <R, S, P extends Message, Q extends Message, T extends Message> CompletableFuture<Long> rowCount(AsyncTable<?> table, ColumnInterpreter<R, S, P, Q, T> ci, Scan scan) {
    CompletableFuture<Long> future = new CompletableFuture<>();
    AggregateRequest req;
    try {
        req = validateArgAndGetPB(scan, ci, true);
    } catch (IOException e) {
        future.completeExceptionally(e);
        return future;
    }
    AbstractAggregationCallback<Long> callback = new AbstractAggregationCallback<Long>(future) {

        private long count;

        @Override
        protected void aggregate(RegionInfo region, AggregateResponse resp) throws IOException {
            count += resp.getFirstPart(0).asReadOnlyByteBuffer().getLong();
        }

        @Override
        protected Long getFinalResult() {
            return count;
        }
    };
    table.<AggregateService, AggregateResponse>coprocessorService(AggregateService::newStub, (stub, controller, rpcCallback) -> stub.getRowNum(controller, req, rpcCallback), callback).fromRow(nullToEmpty(scan.getStartRow()), scan.includeStartRow()).toRow(nullToEmpty(scan.getStopRow()), scan.includeStopRow()).execute();
    return future;
}
Also used : AdvancedScanResultConsumer(org.apache.hadoop.hbase.client.AdvancedScanResultConsumer) FutureUtils.addListener(org.apache.hadoop.hbase.util.FutureUtils.addListener) CoprocessorCallback(org.apache.hadoop.hbase.client.AsyncTable.CoprocessorCallback) ColumnInterpreter(org.apache.hadoop.hbase.coprocessor.ColumnInterpreter) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) Result(org.apache.hadoop.hbase.client.Result) CompletableFuture(java.util.concurrent.CompletableFuture) AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) HConstants(org.apache.hadoop.hbase.HConstants) Map(java.util.Map) AggregationHelper.validateArgAndGetPB(org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.validateArgAndGetPB) NoSuchElementException(java.util.NoSuchElementException) Cell(org.apache.hadoop.hbase.Cell) Bytes(org.apache.hadoop.hbase.util.Bytes) ReflectionUtils(org.apache.hadoop.hbase.util.ReflectionUtils) IOException(java.io.IOException) NavigableSet(java.util.NavigableSet) NavigableMap(java.util.NavigableMap) AggregateService(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateService) Scan(org.apache.hadoop.hbase.client.Scan) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) TreeMap(java.util.TreeMap) AggregationHelper.getParsedGenericInstance(org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.getParsedGenericInstance) AsyncTable(org.apache.hadoop.hbase.client.AsyncTable) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) CompletableFuture(java.util.concurrent.CompletableFuture) AggregateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateRequest) AggregateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AggregateProtos.AggregateResponse) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) IOException(java.io.IOException)

Example 25 with Message

use of org.apache.hbase.thirdparty.com.google.protobuf.Message in project hbase by apache.

the class RSRpcServices method execService.

@Override
public CoprocessorServiceResponse execService(final RpcController controller, final CoprocessorServiceRequest request) throws ServiceException {
    try {
        checkOpen();
        requestCount.increment();
        HRegion region = getRegion(request.getRegion());
        Message result = execServiceOnRegion(region, request.getCall());
        CoprocessorServiceResponse.Builder builder = CoprocessorServiceResponse.newBuilder();
        builder.setRegion(RequestConverter.buildRegionSpecifier(RegionSpecifierType.REGION_NAME, region.getRegionInfo().getRegionName()));
        // TODO: COPIES!!!!!!
        builder.setValue(builder.getValueBuilder().setName(result.getClass().getName()).setValue(org.apache.hbase.thirdparty.com.google.protobuf.ByteString.copyFrom(result.toByteArray())));
        return builder.build();
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) CoprocessorServiceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)28 IOException (java.io.IOException)19 CompletableFuture (java.util.concurrent.CompletableFuture)11 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)11 Result (org.apache.hadoop.hbase.client.Result)8 Map (java.util.Map)7 NavigableMap (java.util.NavigableMap)7 NavigableSet (java.util.NavigableSet)7 NoSuchElementException (java.util.NoSuchElementException)7 TreeMap (java.util.TreeMap)7 Cell (org.apache.hadoop.hbase.Cell)7 HConstants (org.apache.hadoop.hbase.HConstants)7 AdvancedScanResultConsumer (org.apache.hadoop.hbase.client.AdvancedScanResultConsumer)7 AsyncTable (org.apache.hadoop.hbase.client.AsyncTable)7 CoprocessorCallback (org.apache.hadoop.hbase.client.AsyncTable.CoprocessorCallback)7 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)7 Scan (org.apache.hadoop.hbase.client.Scan)7 AggregationHelper.getParsedGenericInstance (org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.getParsedGenericInstance)7 AggregationHelper.validateArgAndGetPB (org.apache.hadoop.hbase.client.coprocessor.AggregationHelper.validateArgAndGetPB)7 ColumnInterpreter (org.apache.hadoop.hbase.coprocessor.ColumnInterpreter)7