Search in sources :

Example 1 with MutateRowsResponse

use of org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse in project hbase by apache.

the class MetaTableAccessor method multiMutate.

/**
   * Performs an atomic multi-mutate operation against the given table.
   */
// Used by the RSGroup Coprocessor Endpoint. It had a copy/paste of the below. Need to reveal
// this facility for CPEP use or at least those CPEPs that are on their way to becoming part of
// core as is the intent for RSGroup eventually.
public static void multiMutate(Connection connection, final Table table, byte[] row, final List<Mutation> mutations) throws IOException {
    if (METALOG.isDebugEnabled()) {
        METALOG.debug(mutationsToString(mutations));
    }
    // TODO: Need rollback!!!!
    // TODO: Need Retry!!!
    // TODO: What for a timeout? Default write timeout? GET FROM HTABLE?
    // TODO: Review when we come through with ProcedureV2.
    RegionServerCallable<MutateRowsResponse, MultiRowMutationProtos.MultiRowMutationService.BlockingInterface> callable = new RegionServerCallable<MutateRowsResponse, MultiRowMutationProtos.MultiRowMutationService.BlockingInterface>(connection, table.getName(), row, null) {

        /*RpcController not used in this CPEP!*/
        @Override
        protected MutateRowsResponse rpcCall() throws Exception {
            final MutateRowsRequest.Builder builder = MutateRowsRequest.newBuilder();
            for (Mutation mutation : mutations) {
                if (mutation instanceof Put) {
                    builder.addMutationRequest(ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.PUT, mutation));
                } else if (mutation instanceof Delete) {
                    builder.addMutationRequest(ProtobufUtil.toMutation(ClientProtos.MutationProto.MutationType.DELETE, mutation));
                } else {
                    throw new DoNotRetryIOException("multi in MetaEditor doesn't support " + mutation.getClass().getName());
                }
            }
            // The call to #prepare that ran before this invocation will have populated HRegionLocation.
            HRegionLocation hrl = getLocation();
            RegionSpecifier region = ProtobufUtil.buildRegionSpecifier(RegionSpecifierType.REGION_NAME, hrl.getRegionInfo().getRegionName());
            builder.setRegion(region);
            // that makes com.google.protobuf.RpcController and then copy into it configs.
            return getStub().mutateRows(null, builder.build());
        }

        @Override
        protected // Called on the end of the super.prepare call. Set the stub.
        void setStubByServiceName(ServerName serviceName) throws /*Ignored*/
        IOException {
            CoprocessorRpcChannel channel = table.coprocessorService(getRow());
            setStub(MultiRowMutationProtos.MultiRowMutationService.newBlockingStub(channel));
        }
    };
    int writeTimeout = connection.getConfiguration().getInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, connection.getConfiguration().getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT));
    // The region location should be cached in connection. Call prepare so this callable picks
    // up the region location (see super.prepare method).
    callable.prepare(false);
    callable.call(writeTimeout);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) MultiRowMutationProtos(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos) Put(org.apache.hadoop.hbase.client.Put) RegionSpecifier(org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier) RegionServerCallable(org.apache.hadoop.hbase.client.RegionServerCallable) MutateRowsResponse(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse) MutateRowsRequest(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest) Mutation(org.apache.hadoop.hbase.client.Mutation)

Example 2 with MutateRowsResponse

use of org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse in project hbase by apache.

the class MultiRowMutationEndpoint method mutateRows.

@Override
public void mutateRows(RpcController controller, MutateRowsRequest request, RpcCallback<MutateRowsResponse> done) {
    MutateRowsResponse response = MutateRowsResponse.getDefaultInstance();
    try {
        // set of rows to lock, sorted to avoid deadlocks
        SortedSet<byte[]> rowsToLock = new TreeSet<>(Bytes.BYTES_COMPARATOR);
        List<MutationProto> mutateRequestList = request.getMutationRequestList();
        List<Mutation> mutations = new ArrayList<>(mutateRequestList.size());
        for (MutationProto m : mutateRequestList) {
            mutations.add(ProtobufUtil.toMutation(m));
        }
        HRegionInfo regionInfo = env.getRegion().getRegionInfo();
        for (Mutation m : mutations) {
            // check whether rows are in range for this region
            if (!HRegion.rowIsInRange(regionInfo, m.getRow())) {
                String msg = "Requested row out of range '" + Bytes.toStringBinary(m.getRow()) + "'";
                if (rowsToLock.isEmpty()) {
                    // allow client to retry
                    throw new WrongRegionException(msg);
                } else {
                    // rows are split between regions, do not retry
                    throw new org.apache.hadoop.hbase.DoNotRetryIOException(msg);
                }
            }
            rowsToLock.add(m.getRow());
        }
        // call utility method on region
        long nonceGroup = request.hasNonceGroup() ? request.getNonceGroup() : HConstants.NO_NONCE;
        long nonce = request.hasNonce() ? request.getNonce() : HConstants.NO_NONCE;
        env.getRegion().mutateRowsWithLocks(mutations, rowsToLock, nonceGroup, nonce);
    } catch (IOException e) {
        CoprocessorRpcUtils.setControllerException(controller, e);
    }
    done.run(response);
}
Also used : ArrayList(java.util.ArrayList) WrongRegionException(org.apache.hadoop.hbase.regionserver.WrongRegionException) IOException(java.io.IOException) MutationProto(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) MutateRowsResponse(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse) TreeSet(java.util.TreeSet) Mutation(org.apache.hadoop.hbase.client.Mutation)

Aggregations

Mutation (org.apache.hadoop.hbase.client.Mutation)2 MutateRowsResponse (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 Delete (org.apache.hadoop.hbase.client.Delete)1 Put (org.apache.hadoop.hbase.client.Put)1 RegionServerCallable (org.apache.hadoop.hbase.client.RegionServerCallable)1 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)1 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)1 RegionSpecifier (org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier)1 MultiRowMutationProtos (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos)1 MutateRowsRequest (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest)1 WrongRegionException (org.apache.hadoop.hbase.regionserver.WrongRegionException)1