Search in sources :

Example 1 with CompareType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.CompareType in project hbase by apache.

the class HTable method checkAndDelete.

/**
   * {@inheritDoc}
   */
@Override
public boolean checkAndDelete(final byte[] row, final byte[] family, final byte[] qualifier, final CompareOp compareOp, final byte[] value, final Delete delete) throws IOException {
    CancellableRegionServerCallable<SingleResponse> callable = new CancellableRegionServerCallable<SingleResponse>(this.connection, getName(), row, this.rpcControllerFactory.newController(), writeRpcTimeout, new RetryingTimeTracker().start()) {

        @Override
        protected SingleResponse rpcCall() throws Exception {
            CompareType compareType = CompareType.valueOf(compareOp.name());
            MutateRequest request = RequestConverter.buildMutateRequest(getLocation().getRegionInfo().getRegionName(), row, family, qualifier, new BinaryComparator(value), compareType, delete);
            MutateResponse response = doMutate(request);
            return ResponseConverter.getResult(request, response, getRpcControllerCellScanner());
        }
    };
    List<Delete> rows = Collections.singletonList(delete);
    Object[] results = new Object[1];
    AsyncProcessTask task = AsyncProcessTask.newBuilder().setPool(pool).setTableName(tableName).setRowAccess(rows).setCallable(callable).setRpcTimeout(Math.max(readRpcTimeout, writeRpcTimeout)).setOperationTimeout(operationTimeout).setSubmittedRows(AsyncProcessTask.SubmittedRows.ALL).setResults(results).build();
    AsyncRequestFuture ars = multiAp.submit(task);
    ars.waitUntilDone();
    if (ars.hasError()) {
        throw ars.getErrors();
    }
    return ((SingleResponse.Entry) results[0]).isProcessed();
}
Also used : MutateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest) CompareType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.CompareType) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) MutateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateResponse)

Example 2 with CompareType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.CompareType in project hbase by apache.

the class HTable method checkAndPut.

/**
   * {@inheritDoc}
   */
@Override
public boolean checkAndPut(final byte[] row, final byte[] family, final byte[] qualifier, final CompareOp compareOp, final byte[] value, final Put put) throws IOException {
    ClientServiceCallable<Boolean> callable = new ClientServiceCallable<Boolean>(this.connection, getName(), row, this.rpcControllerFactory.newController()) {

        @Override
        protected Boolean rpcCall() throws Exception {
            CompareType compareType = CompareType.valueOf(compareOp.name());
            MutateRequest request = RequestConverter.buildMutateRequest(getLocation().getRegionInfo().getRegionName(), row, family, qualifier, new BinaryComparator(value), compareType, put);
            MutateResponse response = doMutate(request);
            return Boolean.valueOf(response.getProcessed());
        }
    };
    return rpcCallerFactory.<Boolean>newCaller(this.writeRpcTimeout).callWithRetries(callable, this.operationTimeout);
}
Also used : MutateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateResponse) MutateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest) CompareType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.CompareType) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator)

Example 3 with CompareType

use of org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.CompareType in project hbase by apache.

the class HTable method checkAndMutate.

/**
   * {@inheritDoc}
   */
@Override
public boolean checkAndMutate(final byte[] row, final byte[] family, final byte[] qualifier, final CompareOp compareOp, final byte[] value, final RowMutations rm) throws IOException {
    CancellableRegionServerCallable<MultiResponse> callable = new CancellableRegionServerCallable<MultiResponse>(connection, getName(), rm.getRow(), rpcControllerFactory.newController(), writeRpcTimeout, new RetryingTimeTracker().start()) {

        @Override
        protected MultiResponse rpcCall() throws Exception {
            CompareType compareType = CompareType.valueOf(compareOp.name());
            MultiRequest request = RequestConverter.buildMutateRequest(getLocation().getRegionInfo().getRegionName(), row, family, qualifier, new BinaryComparator(value), compareType, rm);
            ClientProtos.MultiResponse response = doMulti(request);
            ClientProtos.RegionActionResult res = response.getRegionActionResultList().get(0);
            if (res.hasException()) {
                Throwable ex = ProtobufUtil.toException(res.getException());
                if (ex instanceof IOException) {
                    throw (IOException) ex;
                }
                throw new IOException("Failed to checkAndMutate row: " + Bytes.toStringBinary(rm.getRow()), ex);
            }
            return ResponseConverter.getResults(request, response, getRpcControllerCellScanner());
        }
    };
    /**
     *  Currently, we use one array to store 'processed' flag which is returned by server.
     *  It is excessive to send such a large array, but that is required by the framework right now
     * */
    Object[] results = new Object[rm.getMutations().size()];
    AsyncProcessTask task = AsyncProcessTask.newBuilder().setPool(pool).setTableName(tableName).setRowAccess(rm.getMutations()).setResults(results).setCallable(callable).setRpcTimeout(Math.max(readRpcTimeout, writeRpcTimeout)).setOperationTimeout(operationTimeout).setSubmittedRows(AsyncProcessTask.SubmittedRows.ALL).build();
    AsyncRequestFuture ars = multiAp.submit(task);
    ars.waitUntilDone();
    if (ars.hasError()) {
        throw ars.getErrors();
    }
    return ((Result) results[0]).getExists();
}
Also used : MultiRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest) CompareType(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.CompareType) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Aggregations

BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)3 CompareType (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.CompareType)3 MutateRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest)2 MutateResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateResponse)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)1 MultiRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest)1