Search in sources :

Example 1 with MutateRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest in project hbase by apache.

the class RequestConverter method buildMutateRequest.

/**
   * Create a protocol buffer MutateRequest for a conditioned delete
   *
   * @param regionName
   * @param row
   * @param family
   * @param qualifier
   * @param comparator
   * @param compareType
   * @param delete
   * @return a mutate request
   * @throws IOException
   */
public static MutateRequest buildMutateRequest(final byte[] regionName, final byte[] row, final byte[] family, final byte[] qualifier, final ByteArrayComparable comparator, final CompareType compareType, final Delete delete) throws IOException {
    MutateRequest.Builder builder = MutateRequest.newBuilder();
    RegionSpecifier region = buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
    builder.setRegion(region);
    Condition condition = buildCondition(row, family, qualifier, comparator, compareType);
    builder.setMutation(ProtobufUtil.toMutation(MutationType.DELETE, delete, MutationProto.newBuilder()));
    builder.setCondition(condition);
    return builder.build();
}
Also used : Condition(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Condition) MutateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)

Example 2 with MutateRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest in project hbase by apache.

the class RequestConverter method buildMutateRequest.

/**
   * Create a protocol buffer MutateRequest for a conditioned put
   *
   * @param regionName
   * @param row
   * @param family
   * @param qualifier
   * @param comparator
   * @param compareType
   * @param put
   * @return a mutate request
   * @throws IOException
   */
public static MutateRequest buildMutateRequest(final byte[] regionName, final byte[] row, final byte[] family, final byte[] qualifier, final ByteArrayComparable comparator, final CompareType compareType, final Put put) throws IOException {
    MutateRequest.Builder builder = MutateRequest.newBuilder();
    RegionSpecifier region = buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
    builder.setRegion(region);
    Condition condition = buildCondition(row, family, qualifier, comparator, compareType);
    builder.setMutation(ProtobufUtil.toMutation(MutationType.PUT, put, MutationProto.newBuilder()));
    builder.setCondition(condition);
    return builder.build();
}
Also used : Condition(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Condition) MutateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)

Example 3 with MutateRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest in project hbase by apache.

the class HTable method incrementColumnValue.

/**
   * {@inheritDoc}
   */
@Override
public long incrementColumnValue(final byte[] row, final byte[] family, final byte[] qualifier, final long amount, final Durability durability) throws IOException {
    NullPointerException npe = null;
    if (row == null) {
        npe = new NullPointerException("row is null");
    } else if (family == null) {
        npe = new NullPointerException("family is null");
    } else if (qualifier == null) {
        npe = new NullPointerException("qualifier is null");
    }
    if (npe != null) {
        throw new IOException("Invalid arguments to incrementColumnValue", npe);
    }
    NoncedRegionServerCallable<Long> callable = new NoncedRegionServerCallable<Long>(this.connection, getName(), row, this.rpcControllerFactory.newController()) {

        @Override
        protected Long rpcCall() throws Exception {
            MutateRequest request = RequestConverter.buildIncrementRequest(getLocation().getRegionInfo().getRegionName(), row, family, qualifier, amount, durability, getNonceGroup(), getNonce());
            MutateResponse response = doMutate(request);
            Result result = ProtobufUtil.toResult(response.getResult(), getRpcControllerCellScanner());
            return Long.valueOf(Bytes.toLong(result.getValue(family, qualifier)));
        }
    };
    return rpcCallerFactory.<Long>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) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 4 with MutateRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest in project hbase by apache.

the class HTable method delete.

/**
   * {@inheritDoc}
   */
@Override
public void delete(final Delete delete) throws IOException {
    CancellableRegionServerCallable<SingleResponse> callable = new CancellableRegionServerCallable<SingleResponse>(connection, getName(), delete.getRow(), this.rpcControllerFactory.newController(), writeRpcTimeout, new RetryingTimeTracker().start()) {

        @Override
        protected SingleResponse rpcCall() throws Exception {
            MutateRequest request = RequestConverter.buildMutateRequest(getLocation().getRegionInfo().getRegionName(), delete);
            MutateResponse response = doMutate(request);
            return ResponseConverter.getResult(request, response, getRpcControllerCellScanner());
        }
    };
    List<Delete> rows = Collections.singletonList(delete);
    AsyncProcessTask task = AsyncProcessTask.newBuilder().setPool(pool).setTableName(tableName).setRowAccess(rows).setCallable(callable).setRpcTimeout(writeRpcTimeout).setOperationTimeout(operationTimeout).setSubmittedRows(AsyncProcessTask.SubmittedRows.ALL).build();
    AsyncRequestFuture ars = multiAp.submit(task);
    ars.waitUntilDone();
    if (ars.hasError()) {
        throw ars.getErrors();
    }
}
Also used : MutateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateResponse) MutateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest)

Example 5 with MutateRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest 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)

Aggregations

MutateRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest)18 MutateResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateResponse)9 RegionSpecifier (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)7 MutationProto (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)4 IOException (java.io.IOException)3 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)3 GetRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest)3 ColumnValue (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue)3 QualifierValue (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue.QualifierValue)3 ScanRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Cell (org.apache.hadoop.hbase.Cell)2 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)2 ServerName (org.apache.hadoop.hbase.ServerName)2 TableName (org.apache.hadoop.hbase.TableName)2 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 ClientProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)2 Condition (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Condition)2 RegionActionResult (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult)2