Search in sources :

Example 1 with RegionAction

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

the class TestClientNoCluster method doMultiResponse.

static MultiResponse doMultiResponse(final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta, final AtomicLong sequenceids, final MultiRequest request) {
    // Make a response to match the request.  Act like there were no failures.
    ClientProtos.MultiResponse.Builder builder = ClientProtos.MultiResponse.newBuilder();
    // Per Region.
    RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();
    ResultOrException.Builder roeBuilder = ResultOrException.newBuilder();
    for (RegionAction regionAction : request.getRegionActionList()) {
        regionActionResultBuilder.clear();
        // Per Action in a Region.
        for (ClientProtos.Action action : regionAction.getActionList()) {
            roeBuilder.clear();
            // Return empty Result and proper index as result.
            roeBuilder.setResult(ClientProtos.Result.getDefaultInstance());
            roeBuilder.setIndex(action.getIndex());
            regionActionResultBuilder.addResultOrException(roeBuilder.build());
        }
        builder.addRegionActionResult(regionActionResultBuilder.build());
    }
    return builder.build();
}
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) ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 2 with RegionAction

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction 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 3 with RegionAction

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

the class TestCatalogJanitor method buildMultiResponse.

private MultiResponse buildMultiResponse(MultiRequest req) {
    MultiResponse.Builder builder = MultiResponse.newBuilder();
    RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();
    ResultOrException.Builder roeBuilder = ResultOrException.newBuilder();
    for (RegionAction regionAction : req.getRegionActionList()) {
        regionActionResultBuilder.clear();
        for (ClientProtos.Action action : regionAction.getActionList()) {
            roeBuilder.clear();
            roeBuilder.setResult(ClientProtos.Result.getDefaultInstance());
            roeBuilder.setIndex(action.getIndex());
            regionActionResultBuilder.addResultOrException(roeBuilder.build());
        }
        builder.addRegionActionResult(regionActionResultBuilder.build());
    }
    return builder.build();
}
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) ResultOrException(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 4 with RegionAction

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

the class RSRpcServices method checkBatchSizeAndLogLargeSize.

private void checkBatchSizeAndLogLargeSize(MultiRequest request) throws ServiceException {
    int sum = 0;
    String firstRegionName = null;
    for (RegionAction regionAction : request.getRegionActionList()) {
        if (sum == 0) {
            firstRegionName = Bytes.toStringBinary(regionAction.getRegion().getValue().toByteArray());
        }
        sum += regionAction.getActionCount();
    }
    if (sum > rowSizeWarnThreshold) {
        LOG.warn("Large batch operation detected (greater than " + rowSizeWarnThreshold + ") (HBASE-18023)." + " Requested Number of Rows: " + sum + " Client: " + RpcServer.getRequestUserName().orElse(null) + "/" + RpcServer.getRemoteAddress().orElse(null) + " first region in multi=" + firstRegionName);
        if (rejectRowsWithSizeOverThreshold) {
            throw new ServiceException("Rejecting large batch operation for current batch with firstRegionName: " + firstRegionName + " , Requested Number of Rows: " + sum + " , Size Threshold: " + rowSizeWarnThreshold);
        }
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString)

Example 5 with RegionAction

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction 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)

Aggregations

RegionAction (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction)12 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)8 RegionActionResult (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)8 ResultOrException (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ResultOrException)8 MultiResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiResponse)6 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 IOException (java.io.IOException)3 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)3 Get (org.apache.hadoop.hbase.client.Get)3 Action (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Action)3 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)3 UncheckedIOException (java.io.UncheckedIOException)2 MultiActionResultTooLarge (org.apache.hadoop.hbase.MultiActionResultTooLarge)2 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)2 Result (org.apache.hadoop.hbase.client.Result)2 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)2 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)2 InterruptedIOException (java.io.InterruptedIOException)1 ArrayList (java.util.ArrayList)1