Search in sources :

Example 1 with ResultOrException

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

the class ResponseConverter method getResults.

/**
   * Get the results from a protocol buffer MultiResponse
   *
   * @param request the protocol buffer MultiResponse to convert
   * @param cells Cells to go with the passed in <code>proto</code>.  Can be null.
   * @return the results that were in the MultiResponse (a Result or an Exception).
   * @throws IOException
   */
public static org.apache.hadoop.hbase.client.MultiResponse getResults(final MultiRequest request, final MultiResponse response, final CellScanner cells) throws IOException {
    int requestRegionActionCount = request.getRegionActionCount();
    int responseRegionActionResultCount = response.getRegionActionResultCount();
    if (requestRegionActionCount != responseRegionActionResultCount) {
        throw new IllegalStateException("Request mutation count=" + requestRegionActionCount + " does not match response mutation result count=" + responseRegionActionResultCount);
    }
    org.apache.hadoop.hbase.client.MultiResponse results = new org.apache.hadoop.hbase.client.MultiResponse();
    for (int i = 0; i < responseRegionActionResultCount; i++) {
        RegionAction actions = request.getRegionAction(i);
        RegionActionResult actionResult = response.getRegionActionResult(i);
        HBaseProtos.RegionSpecifier rs = actions.getRegion();
        if (rs.hasType() && (rs.getType() != HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)) {
            throw new IllegalArgumentException("We support only encoded types for protobuf multi response.");
        }
        byte[] regionName = rs.getValue().toByteArray();
        if (actionResult.hasException()) {
            Throwable regionException = ProtobufUtil.toException(actionResult.getException());
            results.addException(regionName, regionException);
            continue;
        }
        if (actions.getActionCount() != actionResult.getResultOrExceptionCount()) {
            throw new IllegalStateException("actions.getActionCount=" + actions.getActionCount() + ", actionResult.getResultOrExceptionCount=" + actionResult.getResultOrExceptionCount() + " for region " + actions.getRegion());
        }
        for (ResultOrException roe : actionResult.getResultOrExceptionList()) {
            Object responseValue;
            if (roe.hasException()) {
                responseValue = ProtobufUtil.toException(roe.getException());
            } else if (roe.hasResult()) {
                responseValue = ProtobufUtil.toResult(roe.getResult(), cells);
            } else if (roe.hasServiceResult()) {
                responseValue = roe.getServiceResult();
            } else {
                // Sometimes, the response is just "it was processed". Generally, this occurs for things
                // like mutateRows where either we get back 'processed' (or not) and optionally some
                // statistics about the regions we touched.
                responseValue = response.getProcessed() ? ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE : ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE;
            }
            results.add(regionName, roe.getIndex(), responseValue);
        }
    }
    if (response.hasRegionStatistics()) {
        ClientProtos.MultiRegionLoadStats stats = response.getRegionStatistics();
        for (int i = 0; i < stats.getRegionCount(); i++) {
            results.addStatistic(stats.getRegion(i).getValue().toByteArray(), stats.getStat(i));
        }
    }
    return results;
}
Also used : MultiResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiResponse) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 2 with ResultOrException

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

the class RSRpcServices method doNonAtomicRegionMutation.

/**
 * Run through the regionMutation <code>rm</code> and per Mutation, do the work, and then when
 * done, add an instance of a {@link ResultOrException} that corresponds to each Mutation.
 * @param cellsToReturn  Could be null. May be allocated in this method.  This is what this
 * method returns as a 'result'.
 * @param closeCallBack the callback to be used with multigets
 * @param context the current RpcCallContext
 * @return Return the <code>cellScanner</code> passed
 */
private List<CellScannable> doNonAtomicRegionMutation(final HRegion region, final OperationQuota quota, final RegionAction actions, final CellScanner cellScanner, final RegionActionResult.Builder builder, List<CellScannable> cellsToReturn, long nonceGroup, final RegionScannersCloseCallBack closeCallBack, RpcCallContext context, ActivePolicyEnforcement spaceQuotaEnforcement) {
    // Gather up CONTIGUOUS Puts and Deletes in this mutations List.  Idea is that rather than do
    // one at a time, we instead pass them in batch.  Be aware that the corresponding
    // ResultOrException instance that matches each Put or Delete is then added down in the
    // doNonAtomicBatchOp call.  We should be staying aligned though the Put and Delete are
    // deferred/batched
    List<ClientProtos.Action> mutations = null;
    long maxQuotaResultSize = Math.min(maxScannerResultSize, quota.getReadAvailable());
    IOException sizeIOE = null;
    Object lastBlock = null;
    ClientProtos.ResultOrException.Builder resultOrExceptionBuilder = ResultOrException.newBuilder();
    boolean hasResultOrException = false;
    for (ClientProtos.Action action : actions.getActionList()) {
        hasResultOrException = false;
        resultOrExceptionBuilder.clear();
        try {
            Result r = null;
            if (context != null && context.isRetryImmediatelySupported() && (context.getResponseCellSize() > maxQuotaResultSize || context.getResponseBlockSize() + context.getResponseExceptionSize() > maxQuotaResultSize)) {
                // change after the response size limit is reached.
                if (sizeIOE == null) {
                    // We don't need the stack un-winding do don't throw the exception.
                    // Throwing will kill the JVM's JIT.
                    // 
                    // Instead just create the exception and then store it.
                    sizeIOE = new MultiActionResultTooLarge("Max size exceeded" + " CellSize: " + context.getResponseCellSize() + " BlockSize: " + context.getResponseBlockSize());
                    // Only report the exception once since there's only one request that
                    // caused the exception. Otherwise this number will dominate the exceptions count.
                    rpcServer.getMetrics().exception(sizeIOE);
                }
                // Now that there's an exception is known to be created
                // use it for the response.
                // 
                // This will create a copy in the builder.
                NameBytesPair pair = ResponseConverter.buildException(sizeIOE);
                resultOrExceptionBuilder.setException(pair);
                context.incrementResponseExceptionSize(pair.getSerializedSize());
                resultOrExceptionBuilder.setIndex(action.getIndex());
                builder.addResultOrException(resultOrExceptionBuilder.build());
                skipCellsForMutation(action, cellScanner);
                continue;
            }
            if (action.hasGet()) {
                long before = EnvironmentEdgeManager.currentTime();
                ClientProtos.Get pbGet = action.getGet();
                // they are; its a problem for non-native clients like asynchbase. HBASE-20225.
                if (pbGet.hasClosestRowBefore() && pbGet.getClosestRowBefore()) {
                    throw new UnknownProtocolException("Is this a pre-hbase-1.0.0 or asynchbase client? " + "Client is invoking getClosestRowBefore removed in hbase-2.0.0 replaced by " + "reverse Scan.");
                }
                try {
                    Get get = ProtobufUtil.toGet(pbGet);
                    if (context != null) {
                        r = get(get, (region), closeCallBack, context);
                    } else {
                        r = region.get(get);
                    }
                } finally {
                    final MetricsRegionServer metricsRegionServer = server.getMetrics();
                    if (metricsRegionServer != null) {
                        metricsRegionServer.updateGet(region.getTableDescriptor().getTableName(), EnvironmentEdgeManager.currentTime() - before);
                    }
                }
            } else if (action.hasServiceCall()) {
                hasResultOrException = true;
                Message result = execServiceOnRegion(region, action.getServiceCall());
                ClientProtos.CoprocessorServiceResult.Builder serviceResultBuilder = ClientProtos.CoprocessorServiceResult.newBuilder();
                resultOrExceptionBuilder.setServiceResult(serviceResultBuilder.setValue(serviceResultBuilder.getValueBuilder().setName(result.getClass().getName()).setValue(UnsafeByteOperations.unsafeWrap(result.toByteArray()))));
            } else if (action.hasMutation()) {
                MutationType type = action.getMutation().getMutateType();
                if (type != MutationType.PUT && type != MutationType.DELETE && mutations != null && !mutations.isEmpty()) {
                    // Flush out any Puts or Deletes already collected.
                    doNonAtomicBatchOp(builder, region, quota, mutations, cellScanner, spaceQuotaEnforcement);
                    mutations.clear();
                }
                switch(type) {
                    case APPEND:
                        r = append(region, quota, action.getMutation(), cellScanner, nonceGroup, spaceQuotaEnforcement);
                        break;
                    case INCREMENT:
                        r = increment(region, quota, action.getMutation(), cellScanner, nonceGroup, spaceQuotaEnforcement);
                        break;
                    case PUT:
                    case DELETE:
                        // Collect the individual mutations and apply in a batch
                        if (mutations == null) {
                            mutations = new ArrayList<>(actions.getActionCount());
                        }
                        mutations.add(action);
                        break;
                    default:
                        throw new DoNotRetryIOException("Unsupported mutate type: " + type.name());
                }
            } else {
                throw new HBaseIOException("Unexpected Action type");
            }
            if (r != null) {
                ClientProtos.Result pbResult = null;
                if (isClientCellBlockSupport(context)) {
                    pbResult = ProtobufUtil.toResultNoData(r);
                    // Hard to guess the size here.  Just make a rough guess.
                    if (cellsToReturn == null) {
                        cellsToReturn = new ArrayList<>();
                    }
                    cellsToReturn.add(r);
                } else {
                    pbResult = ProtobufUtil.toResult(r);
                }
                lastBlock = addSize(context, r, lastBlock);
                hasResultOrException = true;
                resultOrExceptionBuilder.setResult(pbResult);
            }
        // Could get to here and there was no result and no exception.  Presumes we added
        // a Put or Delete to the collecting Mutations List for adding later.  In this
        // case the corresponding ResultOrException instance for the Put or Delete will be added
        // down in the doNonAtomicBatchOp method call rather than up here.
        } catch (IOException ie) {
            rpcServer.getMetrics().exception(ie);
            hasResultOrException = true;
            NameBytesPair pair = ResponseConverter.buildException(ie);
            resultOrExceptionBuilder.setException(pair);
            context.incrementResponseExceptionSize(pair.getSerializedSize());
        }
        if (hasResultOrException) {
            // Propagate index.
            resultOrExceptionBuilder.setIndex(action.getIndex());
            builder.addResultOrException(resultOrExceptionBuilder.build());
        }
    }
    // Finish up any outstanding mutations
    if (!CollectionUtils.isEmpty(mutations)) {
        doNonAtomicBatchOp(builder, region, quota, mutations, cellScanner, spaceQuotaEnforcement);
    }
    return cellsToReturn;
}
Also used : MultiActionResultTooLarge(org.apache.hadoop.hbase.MultiActionResultTooLarge) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) Action(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Action) MutationType(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) CacheBuilder(org.apache.hbase.thirdparty.com.google.common.cache.CacheBuilder) CacheEvictionStatsBuilder(org.apache.hadoop.hbase.CacheEvictionStatsBuilder) Action(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Action) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) UncheckedIOException(java.io.UncheckedIOException) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) Result(org.apache.hadoop.hbase.client.Result) CheckAndMutateResult(org.apache.hadoop.hbase.client.CheckAndMutateResult) NameBytesPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameBytesPair) Get(org.apache.hadoop.hbase.client.Get) MutableObject(org.apache.commons.lang3.mutable.MutableObject) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 3 with ResultOrException

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

the class RSRpcServices method multi.

/**
 * Execute multiple actions on a table: get, mutate, and/or execCoprocessor
 * @param rpcc the RPC controller
 * @param request the multi request
 * @throws ServiceException
 */
@Override
public MultiResponse multi(final RpcController rpcc, final MultiRequest request) throws ServiceException {
    try {
        checkOpen();
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
    checkBatchSizeAndLogLargeSize(request);
    // rpc controller is how we bring in data via the back door;  it is unprotobuf'ed data.
    // It is also the conduit via which we pass back data.
    HBaseRpcController controller = (HBaseRpcController) rpcc;
    CellScanner cellScanner = controller != null ? controller.cellScanner() : null;
    if (controller != null) {
        controller.setCellScanner(null);
    }
    long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE;
    MultiResponse.Builder responseBuilder = MultiResponse.newBuilder();
    RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();
    this.rpcMultiRequestCount.increment();
    this.requestCount.increment();
    ActivePolicyEnforcement spaceQuotaEnforcement = getSpaceQuotaManager().getActiveEnforcements();
    // MultiRequest#condition in case of checkAndMutate with RowMutations.
    if (request.hasCondition()) {
        if (request.getRegionActionList().isEmpty()) {
            // If the region action list is empty, do nothing.
            responseBuilder.setProcessed(true);
            return responseBuilder.build();
        }
        RegionAction regionAction = request.getRegionAction(0);
        // we can assume regionAction.getAtomic() is true here.
        assert regionAction.getAtomic();
        OperationQuota quota;
        HRegion region;
        RegionSpecifier regionSpecifier = regionAction.getRegion();
        try {
            region = getRegion(regionSpecifier);
            quota = getRpcQuotaManager().checkQuota(region, regionAction.getActionList());
        } catch (IOException e) {
            failRegionAction(responseBuilder, regionActionResultBuilder, regionAction, cellScanner, e);
            return responseBuilder.build();
        }
        try {
            boolean rejectIfFromClient = shouldRejectRequestsFromClient(region);
            // We only allow replication in standby state and it will not set the atomic flag.
            if (rejectIfFromClient) {
                failRegionAction(responseBuilder, regionActionResultBuilder, regionAction, cellScanner, new DoNotRetryIOException(region.getRegionInfo().getRegionNameAsString() + " is in STANDBY state"));
                return responseBuilder.build();
            }
            try {
                CheckAndMutateResult result = checkAndMutate(region, regionAction.getActionList(), cellScanner, request.getCondition(), nonceGroup, spaceQuotaEnforcement);
                responseBuilder.setProcessed(result.isSuccess());
                ClientProtos.ResultOrException.Builder resultOrExceptionOrBuilder = ClientProtos.ResultOrException.newBuilder();
                for (int i = 0; i < regionAction.getActionCount(); i++) {
                    // To unify the response format with doNonAtomicRegionMutation and read through
                    // client's AsyncProcess we have to add an empty result instance per operation
                    resultOrExceptionOrBuilder.clear();
                    resultOrExceptionOrBuilder.setIndex(i);
                    regionActionResultBuilder.addResultOrException(resultOrExceptionOrBuilder.build());
                }
            } catch (IOException e) {
                rpcServer.getMetrics().exception(e);
                // As it's an atomic operation with a condition, we may expect it's a global failure.
                regionActionResultBuilder.setException(ResponseConverter.buildException(e));
            }
        } finally {
            quota.close();
        }
        responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
        ClientProtos.RegionLoadStats regionLoadStats = region.getLoadStatistics();
        if (regionLoadStats != null) {
            responseBuilder.setRegionStatistics(MultiRegionLoadStats.newBuilder().addRegion(regionSpecifier).addStat(regionLoadStats).build());
        }
        return responseBuilder.build();
    }
    // this will contain all the cells that we need to return. It's created later, if needed.
    List<CellScannable> cellsToReturn = null;
    RegionScannersCloseCallBack closeCallBack = null;
    RpcCallContext context = RpcServer.getCurrentCall().orElse(null);
    Map<RegionSpecifier, ClientProtos.RegionLoadStats> regionStats = new HashMap<>(request.getRegionActionCount());
    for (RegionAction regionAction : request.getRegionActionList()) {
        OperationQuota quota;
        HRegion region;
        RegionSpecifier regionSpecifier = regionAction.getRegion();
        regionActionResultBuilder.clear();
        try {
            region = getRegion(regionSpecifier);
            quota = getRpcQuotaManager().checkQuota(region, regionAction.getActionList());
        } catch (IOException e) {
            failRegionAction(responseBuilder, regionActionResultBuilder, regionAction, cellScanner, e);
            // For this region it's a failure.
            continue;
        }
        try {
            boolean rejectIfFromClient = shouldRejectRequestsFromClient(region);
            if (regionAction.hasCondition()) {
                // We only allow replication in standby state and it will not set the atomic flag.
                if (rejectIfFromClient) {
                    failRegionAction(responseBuilder, regionActionResultBuilder, regionAction, cellScanner, new DoNotRetryIOException(region.getRegionInfo().getRegionNameAsString() + " is in STANDBY state"));
                    continue;
                }
                try {
                    ClientProtos.ResultOrException.Builder resultOrExceptionOrBuilder = ClientProtos.ResultOrException.newBuilder();
                    if (regionAction.getActionCount() == 1) {
                        CheckAndMutateResult result = checkAndMutate(region, quota, regionAction.getAction(0).getMutation(), cellScanner, regionAction.getCondition(), nonceGroup, spaceQuotaEnforcement);
                        regionActionResultBuilder.setProcessed(result.isSuccess());
                        resultOrExceptionOrBuilder.setIndex(0);
                        if (result.getResult() != null) {
                            resultOrExceptionOrBuilder.setResult(ProtobufUtil.toResult(result.getResult()));
                        }
                        regionActionResultBuilder.addResultOrException(resultOrExceptionOrBuilder.build());
                    } else {
                        CheckAndMutateResult result = checkAndMutate(region, regionAction.getActionList(), cellScanner, regionAction.getCondition(), nonceGroup, spaceQuotaEnforcement);
                        regionActionResultBuilder.setProcessed(result.isSuccess());
                        for (int i = 0; i < regionAction.getActionCount(); i++) {
                            if (i == 0 && result.getResult() != null) {
                                // Set the result of the Increment/Append operations to the first element of the
                                // ResultOrException list
                                resultOrExceptionOrBuilder.setIndex(i);
                                regionActionResultBuilder.addResultOrException(resultOrExceptionOrBuilder.setResult(ProtobufUtil.toResult(result.getResult())).build());
                                continue;
                            }
                            // To unify the response format with doNonAtomicRegionMutation and read through
                            // client's AsyncProcess we have to add an empty result instance per operation
                            resultOrExceptionOrBuilder.clear();
                            resultOrExceptionOrBuilder.setIndex(i);
                            regionActionResultBuilder.addResultOrException(resultOrExceptionOrBuilder.build());
                        }
                    }
                } catch (IOException e) {
                    rpcServer.getMetrics().exception(e);
                    // As it's an atomic operation with a condition, we may expect it's a global failure.
                    regionActionResultBuilder.setException(ResponseConverter.buildException(e));
                }
            } else if (regionAction.hasAtomic() && regionAction.getAtomic()) {
                // We only allow replication in standby state and it will not set the atomic flag.
                if (rejectIfFromClient) {
                    failRegionAction(responseBuilder, regionActionResultBuilder, regionAction, cellScanner, new DoNotRetryIOException(region.getRegionInfo().getRegionNameAsString() + " is in STANDBY state"));
                    continue;
                }
                try {
                    doAtomicBatchOp(regionActionResultBuilder, region, quota, regionAction.getActionList(), cellScanner, nonceGroup, spaceQuotaEnforcement);
                    regionActionResultBuilder.setProcessed(true);
                    // We no longer use MultiResponse#processed. Instead, we use
                    // RegionActionResult#processed. This is for backward compatibility for old clients.
                    responseBuilder.setProcessed(true);
                } catch (IOException e) {
                    rpcServer.getMetrics().exception(e);
                    // As it's atomic, we may expect it's a global failure.
                    regionActionResultBuilder.setException(ResponseConverter.buildException(e));
                }
            } else {
                if (rejectIfFromClient && regionAction.getActionCount() > 0 && !isReplicationRequest(regionAction.getAction(0))) {
                    // fail if it is not a replication request
                    failRegionAction(responseBuilder, regionActionResultBuilder, regionAction, cellScanner, new DoNotRetryIOException(region.getRegionInfo().getRegionNameAsString() + " is in STANDBY state"));
                    continue;
                }
                // doNonAtomicRegionMutation manages the exception internally
                if (context != null && closeCallBack == null) {
                    // An RpcCallBack that creates a list of scanners that needs to perform callBack
                    // operation on completion of multiGets.
                    // Set this only once
                    closeCallBack = new RegionScannersCloseCallBack();
                    context.setCallBack(closeCallBack);
                }
                cellsToReturn = doNonAtomicRegionMutation(region, quota, regionAction, cellScanner, regionActionResultBuilder, cellsToReturn, nonceGroup, closeCallBack, context, spaceQuotaEnforcement);
            }
        } finally {
            quota.close();
        }
        responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
        ClientProtos.RegionLoadStats regionLoadStats = region.getLoadStatistics();
        if (regionLoadStats != null) {
            regionStats.put(regionSpecifier, regionLoadStats);
        }
    }
    // Load the controller with the Cells to return.
    if (cellsToReturn != null && !cellsToReturn.isEmpty() && controller != null) {
        controller.setCellScanner(CellUtil.createCellScanner(cellsToReturn));
    }
    MultiRegionLoadStats.Builder builder = MultiRegionLoadStats.newBuilder();
    for (Entry<RegionSpecifier, ClientProtos.RegionLoadStats> stat : regionStats.entrySet()) {
        builder.addRegion(stat.getKey());
        builder.addStat(stat.getValue());
    }
    responseBuilder.setRegionStatistics(builder);
    return responseBuilder.build();
}
Also used : ActivePolicyEnforcement(org.apache.hadoop.hbase.quotas.ActivePolicyEnforcement) CellScannable(org.apache.hadoop.hbase.CellScannable) MultiResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiResponse) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CheckAndMutateResult(org.apache.hadoop.hbase.client.CheckAndMutateResult) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) CellScanner(org.apache.hadoop.hbase.CellScanner) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier) MultiRegionLoadStats(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRegionLoadStats) ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) RpcCallContext(org.apache.hadoop.hbase.ipc.RpcCallContext) OperationQuota(org.apache.hadoop.hbase.quotas.OperationQuota) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) UncheckedIOException(java.io.UncheckedIOException) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) MultiRegionLoadStats(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRegionLoadStats) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 4 with ResultOrException

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

the class ResponseConverter method getMutateRowResult.

private static Result getMutateRowResult(RegionActionResult actionResult, CellScanner cells) throws IOException {
    if (actionResult.getProcessed()) {
        Result result = null;
        if (actionResult.getResultOrExceptionCount() > 0) {
            // Get the result of the Increment/Append operations from the first element of the
            // ResultOrException list
            ResultOrException roe = actionResult.getResultOrException(0);
            Result r = ProtobufUtil.toResult(roe.getResult(), cells);
            if (!r.isEmpty()) {
                r.setExists(true);
                result = r;
            }
        }
        if (result != null) {
            return result;
        } else {
            return ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE;
        }
    } else {
        return ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE;
    }
}
Also used : ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) Result(org.apache.hadoop.hbase.client.Result) CheckAndMutateResult(org.apache.hadoop.hbase.client.CheckAndMutateResult) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)

Example 5 with ResultOrException

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

the class ResponseConverter method getResults.

/**
 * Get the results from a protocol buffer MultiResponse
 *
 * @param request the original protocol buffer MultiRequest
 * @param indexMap Used to support RowMutations/CheckAndMutate in batch
 * @param response the protocol buffer MultiResponse to convert
 * @param cells Cells to go with the passed in <code>proto</code>.  Can be null.
 * @return the results that were in the MultiResponse (a Result or an Exception).
 * @throws IOException
 */
public static org.apache.hadoop.hbase.client.MultiResponse getResults(final MultiRequest request, final Map<Integer, Integer> indexMap, final MultiResponse response, final CellScanner cells) throws IOException {
    int requestRegionActionCount = request.getRegionActionCount();
    int responseRegionActionResultCount = response.getRegionActionResultCount();
    if (requestRegionActionCount != responseRegionActionResultCount) {
        throw new IllegalStateException("Request mutation count=" + requestRegionActionCount + " does not match response mutation result count=" + responseRegionActionResultCount);
    }
    org.apache.hadoop.hbase.client.MultiResponse results = new org.apache.hadoop.hbase.client.MultiResponse();
    for (int i = 0; i < responseRegionActionResultCount; i++) {
        RegionAction actions = request.getRegionAction(i);
        RegionActionResult actionResult = response.getRegionActionResult(i);
        HBaseProtos.RegionSpecifier rs = actions.getRegion();
        if (rs.hasType() && (rs.getType() != HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)) {
            throw new IllegalArgumentException("We support only encoded types for protobuf multi response.");
        }
        byte[] regionName = rs.getValue().toByteArray();
        if (actionResult.hasException()) {
            Throwable regionException = ProtobufUtil.toException(actionResult.getException());
            results.addException(regionName, regionException);
            continue;
        }
        if (actions.getActionCount() != actionResult.getResultOrExceptionCount()) {
            throw new IllegalStateException("actions.getActionCount=" + actions.getActionCount() + ", actionResult.getResultOrExceptionCount=" + actionResult.getResultOrExceptionCount() + " for region " + actions.getRegion());
        }
        // For RowMutations/CheckAndMutate action, if there is an exception, the exception is set
        // at the RegionActionResult level and the ResultOrException is null at the original index
        Integer index = (indexMap == null ? null : indexMap.get(i));
        if (index != null) {
            // the RegionActionResult level, which has been handled above.
            if (actions.hasCondition()) {
                results.add(regionName, index, getCheckAndMutateResult(actionResult, cells));
            } else {
                results.add(regionName, index, getMutateRowResult(actionResult, cells));
            }
            continue;
        }
        if (actions.hasCondition()) {
            results.add(regionName, 0, getCheckAndMutateResult(actionResult, cells));
        } else {
            if (actionResult.hasProcessed()) {
                results.add(regionName, 0, getMutateRowResult(actionResult, cells));
                continue;
            }
            for (ResultOrException roe : actionResult.getResultOrExceptionList()) {
                Object responseValue;
                if (roe.hasException()) {
                    responseValue = ProtobufUtil.toException(roe.getException());
                } else if (roe.hasResult()) {
                    responseValue = ProtobufUtil.toResult(roe.getResult(), cells);
                } else if (roe.hasServiceResult()) {
                    responseValue = roe.getServiceResult();
                } else {
                    responseValue = ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE;
                }
                results.add(regionName, roe.getIndex(), responseValue);
            }
        }
    }
    if (response.hasRegionStatistics()) {
        ClientProtos.MultiRegionLoadStats stats = response.getRegionStatistics();
        for (int i = 0; i < stats.getRegionCount(); i++) {
            results.addStatistic(stats.getRegion(i).getValue().toByteArray(), stats.getStat(i));
        }
    }
    return results;
}
Also used : MultiResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiResponse) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Aggregations

RegionActionResult (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)7 ResultOrException (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException)7 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)6 RegionAction (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction)6 IOException (java.io.IOException)4 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)4 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)4 Result (org.apache.hadoop.hbase.client.Result)4 UncheckedIOException (java.io.UncheckedIOException)3 Action (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Action)3 MultiResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiResponse)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 MultiActionResultTooLarge (org.apache.hadoop.hbase.MultiActionResultTooLarge)2 Get (org.apache.hadoop.hbase.client.Get)2 UnknownProtocolException (org.apache.hadoop.hbase.exceptions.UnknownProtocolException)2 MutationType (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType)2 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)2 NameBytesPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameBytesPair)2