Search in sources :

Example 1 with WrongRegionException

use of org.apache.hadoop.hbase.regionserver.WrongRegionException 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

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 Mutation (org.apache.hadoop.hbase.client.Mutation)1 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)1 MutateRowsResponse (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse)1 WrongRegionException (org.apache.hadoop.hbase.regionserver.WrongRegionException)1