Package org.apache.hadoop.hbase.ipc

Examples of org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController


      throw new ServiceException(ie);
    }

    // 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.
    PayloadCarryingRpcController controller = (PayloadCarryingRpcController)rpcc;
    CellScanner cellScanner = controller != null ? controller.cellScanner(): null;
    if (controller != null) controller.setCellScanner(null);

    long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE;

    // this will contain all the cells that we need to return. It's created later, if needed.
    List<CellScannable> cellsToReturn = null;
    MultiResponse.Builder responseBuilder = MultiResponse.newBuilder();
    RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();

    for (RegionAction regionAction : request.getRegionActionList()) {
      this.requestCount.add(regionAction.getActionCount());
      HRegion region;
      regionActionResultBuilder.clear();
      try {
        region = getRegion(regionAction.getRegion());
      } catch (IOException e) {
        regionActionResultBuilder.setException(ResponseConverter.buildException(e));
        responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
        continue// For this region it's a failure.
      }

      if (regionAction.hasAtomic() && regionAction.getAtomic()) {
        // How does this call happen?  It may need some work to play well w/ the surroundings.
        // Need to return an item per Action along w/ Action index.  TODO.
        try {
          mutateRows(region, regionAction.getActionList(), cellScanner);
        } catch (IOException e) {
          // As it's atomic, we may expect it's a global failure.
          regionActionResultBuilder.setException(ResponseConverter.buildException(e));
        }
      } else {
        // doNonAtomicRegionMutation manages the exception internally
        cellsToReturn = doNonAtomicRegionMutation(region, regionAction, cellScanner,
            regionActionResultBuilder, cellsToReturn, nonceGroup);
      }
      responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
    }
    // Load the controller with the Cells to return.
    if (cellsToReturn != null && !cellsToReturn.isEmpty() && controller != null) {
      controller.setCellScanner(CellUtil.createCellScanner(cellsToReturn));
    }
    return responseBuilder.build();
  }
View Full Code Here


  @Override
  public MutateResponse mutate(final RpcController rpcc,
      final MutateRequest request) throws ServiceException {
    // 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.
    PayloadCarryingRpcController controller = (PayloadCarryingRpcController)rpcc;
    CellScanner cellScanner = controller != null? controller.cellScanner(): null;
    // Clear scanner so we are not holding on to reference across call.
    controller.setCellScanner(null);
    try {
      requestCount.increment();
      HRegion region = getRegion(request.getRegion());
      MutateResponse.Builder builder = MutateResponse.newBuilder();
      MutationProto mutation = request.getMutation();
      if (!region.getRegionInfo().isMetaTable()) {
        cacheFlusher.reclaimMemStoreMemory();
      }
      Result r = null;
      Boolean processed = null;
      MutationType type = mutation.getMutateType();
      switch (type) {
      case APPEND:
        r = append(region, mutation, cellScanner);
        break;
      case INCREMENT:
        r = increment(region, mutation, cellScanner);
        break;
      case PUT:
        Put put = ProtobufUtil.toPut(mutation, cellScanner);
        if (request.hasCondition()) {
          Condition condition = request.getCondition();
          byte[] row = condition.getRow().toByteArray();
          byte[] family = condition.getFamily().toByteArray();
          byte[] qualifier = condition.getQualifier().toByteArray();
          CompareOp compareOp = CompareOp.valueOf(condition.getCompareType().name());
          ByteArrayComparable comparator =
            ProtobufUtil.toComparator(condition.getComparator());
          if (region.getCoprocessorHost() != null) {
            processed = region.getCoprocessorHost().preCheckAndPut(
              row, family, qualifier, compareOp, comparator, put);
          }
          if (processed == null) {
            boolean result = region.checkAndMutate(row, family,
              qualifier, compareOp, comparator, put, true);
            if (region.getCoprocessorHost() != null) {
              result = region.getCoprocessorHost().postCheckAndPut(row, family,
                qualifier, compareOp, comparator, put, result);
            }
            processed = result;
          }
        } else {
          region.put(put);
          processed = Boolean.TRUE;
        }
        break;
      case DELETE:
        Delete delete = ProtobufUtil.toDelete(mutation, cellScanner);
        if (request.hasCondition()) {
          Condition condition = request.getCondition();
          byte[] row = condition.getRow().toByteArray();
          byte[] family = condition.getFamily().toByteArray();
          byte[] qualifier = condition.getQualifier().toByteArray();
          CompareOp compareOp = CompareOp.valueOf(condition.getCompareType().name());
          ByteArrayComparable comparator =
            ProtobufUtil.toComparator(condition.getComparator());
          if (region.getCoprocessorHost() != null) {
            processed = region.getCoprocessorHost().preCheckAndDelete(
              row, family, qualifier, compareOp, comparator, delete);
          }
          if (processed == null) {
            boolean result = region.checkAndMutate(row, family,
              qualifier, compareOp, comparator, delete, true);
            if (region.getCoprocessorHost() != null) {
              result = region.getCoprocessorHost().postCheckAndDelete(row, family,
                qualifier, compareOp, comparator, delete, result);
            }
            processed = result;
          }
        } else {
          region.delete(delete, delete.getWriteToWAL());
          processed = Boolean.TRUE;
        }
        break;
        default:
          throw new DoNotRetryIOException(
            "Unsupported mutate type: " + type.name());
      }
      CellScannable cellsToReturn = null;
      if (processed != null) {
        builder.setProcessed(processed.booleanValue());
      } else if (r != null) {
        builder.setResult(ProtobufUtil.toResultNoData(r));
        cellsToReturn = r;
      }
      if (cellsToReturn != null) {
        controller.setCellScanner(cellsToReturn.cellScanner());
      }
      return builder.build();
    } catch (IOException ie) {
      checkFileSystem();
      throw new ServiceException(ie);
View Full Code Here

  @Override
  public MultiResponse multi(final RpcController rpcc, final MultiRequest request)
  throws ServiceException {
    // 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.
    PayloadCarryingRpcController controller = (PayloadCarryingRpcController)rpcc;
    CellScanner cellScanner = controller != null? controller.cellScanner(): null;
    // Clear scanner so we are not holding on to reference across call.
    controller.setCellScanner(null);
    List<CellScannable> cellsToReturn = null;
    try {
      HRegion region = getRegion(request.getRegion());
      MultiResponse.Builder builder = MultiResponse.newBuilder();
      List<MutationProto> mutations = new ArrayList<MutationProto>(request.getActionCount());
      // Do a bunch of mutations atomically.  Mutations are Puts and Deletes.  NOT Gets.
      if (request.hasAtomic() && request.getAtomic()) {
        // MultiAction is union type.  Has a Get or a Mutate.
        for (ClientProtos.MultiAction actionUnion : request.getActionList()) {
          if (actionUnion.hasMutation()) {
            mutations.add(actionUnion.getMutation());
          } else {
            throw new DoNotRetryIOException("Unsupported atomic action type: " + actionUnion);
          }
        }
        // TODO: We are not updating a metric here.  Should we up requestCount?
        if (!mutations.isEmpty()) mutateRows(region, mutations, cellScanner);
      } else {
        // Do a bunch of Actions.
        ActionResult.Builder resultBuilder = null;
        cellsToReturn = new ArrayList<CellScannable>(request.getActionCount());
        for (ClientProtos.MultiAction actionUnion : request.getActionList()) {
          this.requestCount.increment();
          ClientProtos.Result result = null;
          try {
            if (actionUnion.hasGet()) {
              Get get = ProtobufUtil.toGet(actionUnion.getGet());
              Result r = region.get(get);
              if (r != null) {
                // Get a result with no data.  The data will be carried alongside pbs, not as pbs.
                result = ProtobufUtil.toResultNoData(r);
                // Add the Result to controller so it gets serialized apart from pb.  Get
                // Results could be big so good if they are not serialized as pb.
                cellsToReturn.add(r);
              }
            } else if (actionUnion.hasMutation()) {
              MutationProto mutation = actionUnion.getMutation();
              MutationType type = mutation.getMutateType();
              if (type != MutationType.PUT && type != MutationType.DELETE) {
                if (!mutations.isEmpty()) {
                  doBatchOp(builder, region, mutations, cellScanner);
                  mutations.clear();
                } else if (!region.getRegionInfo().isMetaTable()) {
                  cacheFlusher.reclaimMemStoreMemory();
                }
              }
              Result r = null;
              switch (type) {
              case APPEND:
                r = append(region, mutation, cellScanner);
                break;
              case INCREMENT:
                r = increment(region, mutation, cellScanner);
                break;
              case PUT:
              case DELETE:
                mutations.add(mutation);
                break;
              default:
                throw new DoNotRetryIOException("Unsupported mutate type: " + type.name());
              }
              if (r != null) {
                // Put the data into the cellsToReturn and the metadata about the result is all that
                // we will pass back in the protobuf result.
                result = ProtobufUtil.toResultNoData(r);
                cellsToReturn.add(r);
              }
            } else {
              LOG.warn("Error: invalid action: " + actionUnion + ". "
                + "it must be a Get, Mutate, or Exec.");
              throw new DoNotRetryIOException("Invalid action, "
                + "it must be a Get, Mutate, or Exec.");
            }
            if (result != null) {
              if (resultBuilder == null) {
                resultBuilder = ActionResult.newBuilder();
              } else {
                resultBuilder.clear();
              }
              resultBuilder.setValue(result);
              builder.addResult(resultBuilder.build());
            }
          } catch (IOException ie) {
            builder.addResult(ResponseConverter.buildActionResult(ie));
          }
        }
        if (!mutations.isEmpty()) {
          doBatchOp(builder, region, mutations, cellScanner);
        }
      }
      // Load the controller with the Cells to return.
      if (cellsToReturn != null && !cellsToReturn.isEmpty()) {
        controller.setCellScanner(CellUtil.createCellScanner(cellsToReturn));
      }
      return builder.build();
    } catch (IOException ie) {
      throw new ServiceException(ie);
    }
View Full Code Here

      AdminService.BlockingInterface remoteSvr = conn.getAdmin(getLocation().getServerName());

      Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> p =
          ReplicationProtbufUtil.buildReplicateWALEntryRequest(entriesArray);
      try {
        PayloadCarryingRpcController controller = new PayloadCarryingRpcController(p.getSecond());
        remoteSvr.replay(controller, p.getFirst());
      } catch (ServiceException se) {
        throw ProtobufUtil.getRemoteException(se);
      }
    }
View Full Code Here

    return new ServerCallable<Result>(connection, tableName, append.getRow(), operationTimeout) {
          public Result call() throws IOException {
            try {
              MutateRequest request = RequestConverter.buildMutateRequest(
                location.getRegionInfo().getRegionName(), append);
              PayloadCarryingRpcController rpcController =
                new PayloadCarryingRpcController();
              MutateResponse response = server.mutate(rpcController, request);
              if (!response.hasResult()) return null;
              return ProtobufUtil.toResult(response.getResult(), rpcController.cellScanner());
            } catch (ServiceException se) {
              throw ProtobufUtil.getRemoteException(se);
            }
          }
        }.withRetries();
View Full Code Here

    return new ServerCallable<Result>(connection, tableName, increment.getRow(), operationTimeout) {
          public Result call() throws IOException {
            try {
              MutateRequest request = RequestConverter.buildMutateRequest(
                location.getRegionInfo().getRegionName(), increment);
              PayloadCarryingRpcController rpcContoller = new PayloadCarryingRpcController();
              MutateResponse response = server.mutate(rpcContoller, request);
              return ProtobufUtil.toResult(response.getResult(), rpcContoller.cellScanner());
            } catch (ServiceException se) {
              throw ProtobufUtil.getRemoteException(se);
            }
          }
        }.withRetries();
View Full Code Here

          public Long call() throws IOException {
            try {
              MutateRequest request = RequestConverter.buildMutateRequest(
                location.getRegionInfo().getRegionName(), row, family,
                qualifier, amount, writeToWAL);
              PayloadCarryingRpcController rpcController = new PayloadCarryingRpcController();
              MutateResponse response = server.mutate(rpcController, request);
              Result result =
                ProtobufUtil.toResult(response.getResult(), rpcController.cellScanner());
              return Long.valueOf(Bytes.toLong(result.getValue(family, qualifier)));
            } catch (ServiceException se) {
              throw ProtobufUtil.getRemoteException(se);
            }
          }
View Full Code Here

            // Build a multi request absent its Cell payload (this is the 'nodata' in the below).
            MultiRequest multiRequest =
                RequestConverter.buildNoDataMultiRequest(regionName, rms, cells);
            // Carry the cells over the proxy/pb Service interface using the payload carrying
            // rpc controller.
            server.multi(new PayloadCarryingRpcController(cells), multiRequest);
            // This multi call does not return results.
            response.add(regionName, action.getOriginalIndex(), Result.EMPTY_RESULT);
          } catch (ServiceException se) {
            response.add(regionName, action.getOriginalIndex(),
              ProtobufUtil.getRemoteException(se));
          }
          rowMutations++;
        }
      }
      // Are there any non-RowMutation actions to send for this region?
      if (actions.size() > rowMutations) {
        Exception ex = null;
        List<Object> results = null;
        // Stick all Cells for the multiRequest in here into 'cells'.  Gets filled in when we
        // call buildNoDataMultiRequest
        List<CellScannable> cells = new ArrayList<CellScannable>(actions.size() - rowMutations);
        try {
          // The call to buildNoDataMultiRequest will skip RowMutations.  They have
          // already been handled above.
          MultiRequest multiRequest =
              RequestConverter.buildNoDataMultiRequest(regionName, actions, cells);
          // Controller optionally carries cell data over the proxy/service boundary and also
          // optionally ferries cell response data back out again.
          PayloadCarryingRpcController controller = new PayloadCarryingRpcController(cells);
          ClientProtos.MultiResponse responseProto = server.multi(controller, multiRequest);
          results = ResponseConverter.getResults(responseProto, controller.cellScanner());
        } catch (ServiceException se) {
          ex = ProtobufUtil.getRemoteException(se);
        }
        for (int i = 0, n = actions.size(); i < n; i++) {
          int originalIndex = actions.get(i).getOriginalIndex();
View Full Code Here

  @Override
  public MutateResponse mutate(final RpcController rpcc,
      final MutateRequest request) throws ServiceException {
    // 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.
    PayloadCarryingRpcController controller = (PayloadCarryingRpcController)rpcc;
    CellScanner cellScanner = controller != null? controller.cellScanner(): null;
    // Clear scanner so we are not holding on to reference across call.
    if (controller != null) controller.setCellScanner(null);
    try {
      checkOpen();
      requestCount.increment();
      HRegion region = getRegion(request.getRegion());
      MutateResponse.Builder builder = MutateResponse.newBuilder();
View Full Code Here

      throw new ServiceException(ie);
    }

    // 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.
    PayloadCarryingRpcController controller = (PayloadCarryingRpcController)rpcc;
    CellScanner cellScanner = controller != null ? controller.cellScanner(): null;
    if (controller != null) controller.setCellScanner(null);

    long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE;

    // this will contain all the cells that we need to return. It's created later, if needed.
    List<CellScannable> cellsToReturn = null;
    MultiResponse.Builder responseBuilder = MultiResponse.newBuilder();
    RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();

    for (RegionAction regionAction : request.getRegionActionList()) {
      this.requestCount.add(regionAction.getActionCount());
      HRegion region;
      regionActionResultBuilder.clear();
      try {
        region = getRegion(regionAction.getRegion());
      } catch (IOException e) {
        regionActionResultBuilder.setException(ResponseConverter.buildException(e));
        responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
        continue// For this region it's a failure.
      }

      if (regionAction.hasAtomic() && regionAction.getAtomic()) {
        // How does this call happen?  It may need some work to play well w/ the surroundings.
        // Need to return an item per Action along w/ Action index.  TODO.
        try {
          mutateRows(region, regionAction.getActionList(), cellScanner);
        } catch (IOException e) {
          // As it's atomic, we may expect it's a global failure.
          regionActionResultBuilder.setException(ResponseConverter.buildException(e));
        }
      } else {
        // doNonAtomicRegionMutation manages the exception internally
        cellsToReturn = doNonAtomicRegionMutation(region, regionAction, cellScanner,
            regionActionResultBuilder, cellsToReturn, nonceGroup);
      }
      responseBuilder.addRegionActionResult(regionActionResultBuilder.build());
    }
    // Load the controller with the Cells to return.
    if (cellsToReturn != null && !cellsToReturn.isEmpty() && controller != null) {
      controller.setCellScanner(CellUtil.createCellScanner(cellsToReturn));
    }
    return responseBuilder.build();
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.