Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
  /**
   * 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="
              + responseRegionActionResultCount
              + " 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);
          // add the load stats, if we got any
          if (roe.hasLoadStats()) {
            ((Result) responseValue).addResults(roe.getLoadStats());
          }
        } else if (roe.hasServiceResult()) {
          responseValue = roe.getServiceResult();
        } else {
          // no result & no exception. Unexpected.
          throw new IllegalStateException(
              "No result & no exception roe=" + roe + " for region " + actions.getRegion());
        }
        results.add(regionName, roe.getIndex(), responseValue);
      }
    }

    return results;
  }