HBASE-24650 Change the return types of the new checkAndMutate methods introduced in HBASE-8458 (#2033)

Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
Toshihiro Suzuki 2020-07-08 08:00:48 +09:00 committed by GitHub
parent 28602d6fdb
commit f771fd26b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 342 additions and 238 deletions

View File

@ -367,7 +367,7 @@ public interface AsyncTable<C extends ScanResultConsumerBase> {
* @param checkAndMutate The CheckAndMutate object. * @param checkAndMutate The CheckAndMutate object.
* @return A {@link CompletableFuture}s that represent the result for the CheckAndMutate. * @return A {@link CompletableFuture}s that represent the result for the CheckAndMutate.
*/ */
CompletableFuture<Boolean> checkAndMutate(CheckAndMutate checkAndMutate); CompletableFuture<CheckAndMutateResult> checkAndMutate(CheckAndMutate checkAndMutate);
/** /**
* Batch version of checkAndMutate. The specified CheckAndMutates are batched only in the sense * Batch version of checkAndMutate. The specified CheckAndMutates are batched only in the sense
@ -378,15 +378,16 @@ public interface AsyncTable<C extends ScanResultConsumerBase> {
* @return A list of {@link CompletableFuture}s that represent the result for each * @return A list of {@link CompletableFuture}s that represent the result for each
* CheckAndMutate. * CheckAndMutate.
*/ */
List<CompletableFuture<Boolean>> checkAndMutate(List<CheckAndMutate> checkAndMutates); List<CompletableFuture<CheckAndMutateResult>> checkAndMutate(
List<CheckAndMutate> checkAndMutates);
/** /**
* A simple version of batch checkAndMutate. It will fail if there are any failures. * A simple version of batch checkAndMutate. It will fail if there are any failures.
* *
* @param checkAndMutates The list of rows to apply. * @param checkAndMutates The list of rows to apply.
* @return A {@link CompletableFuture} that wrapper the result boolean list. * @return A {@link CompletableFuture} that wrapper the result list.
*/ */
default CompletableFuture<List<Boolean>> checkAndMutateAll( default CompletableFuture<List<CheckAndMutateResult>> checkAndMutateAll(
List<CheckAndMutate> checkAndMutates) { List<CheckAndMutate> checkAndMutates) {
return allOf(checkAndMutate(checkAndMutates)); return allOf(checkAndMutate(checkAndMutates));
} }

View File

@ -205,12 +205,13 @@ class AsyncTableImpl implements AsyncTable<ScanResultConsumer> {
} }
@Override @Override
public CompletableFuture<Boolean> checkAndMutate(CheckAndMutate checkAndMutate) { public CompletableFuture<CheckAndMutateResult> checkAndMutate(CheckAndMutate checkAndMutate) {
return wrap(rawTable.checkAndMutate(checkAndMutate)); return wrap(rawTable.checkAndMutate(checkAndMutate));
} }
@Override @Override
public List<CompletableFuture<Boolean>> checkAndMutate(List<CheckAndMutate> checkAndMutates) { public List<CompletableFuture<CheckAndMutateResult>> checkAndMutate(
List<CheckAndMutate> checkAndMutates) {
return rawTable.checkAndMutate(checkAndMutates).stream() return rawTable.checkAndMutate(checkAndMutates).stream()
.map(this::wrap).collect(toList()); .map(this::wrap).collect(toList());
} }

View File

@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.client;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Represents a result of a CheckAndMutate operation
*/
@InterfaceAudience.Public
public class CheckAndMutateResult {
private final boolean success;
private final Result result;
public CheckAndMutateResult(boolean success, Result result) {
this.success = success;
this.result = result;
}
/**
* @return Whether the CheckAndMutate operation is successful or not
*/
public boolean isSuccess() {
return success;
}
/**
* @return It is used only for CheckAndMutate operations with Increment/Append. Otherwise null
*/
public Result getResult() {
return result;
}
}

View File

@ -676,7 +676,7 @@ public class HTable implements Table {
public boolean checkAndPut(final byte [] row, final byte [] family, final byte [] qualifier, public boolean checkAndPut(final byte [] row, final byte [] family, final byte [] qualifier,
final byte [] value, final Put put) throws IOException { final byte [] value, final Put put) throws IOException {
return doCheckAndPut(row, family, qualifier, CompareOperator.EQUAL, value, null, null, return doCheckAndPut(row, family, qualifier, CompareOperator.EQUAL, value, null, null,
put); put).isSuccess();
} }
@Override @Override
@ -684,7 +684,7 @@ public class HTable implements Table {
public boolean checkAndPut(final byte [] row, final byte [] family, final byte [] qualifier, public boolean checkAndPut(final byte [] row, final byte [] family, final byte [] qualifier,
final CompareOp compareOp, final byte [] value, final Put put) throws IOException { final CompareOp compareOp, final byte [] value, final Put put) throws IOException {
return doCheckAndPut(row, family, qualifier, toCompareOperator(compareOp), value, null, return doCheckAndPut(row, family, qualifier, toCompareOperator(compareOp), value, null,
null, put); null, put).isSuccess();
} }
@Override @Override
@ -693,25 +693,25 @@ public class HTable implements Table {
final CompareOperator op, final byte [] value, final Put put) throws IOException { final CompareOperator op, final byte [] value, final Put put) throws IOException {
// The name of the operators in CompareOperator are intentionally those of the // The name of the operators in CompareOperator are intentionally those of the
// operators in the filter's CompareOp enum. // operators in the filter's CompareOp enum.
return doCheckAndPut(row, family, qualifier, op, value, null, null, put); return doCheckAndPut(row, family, qualifier, op, value, null, null, put).isSuccess();
} }
private boolean doCheckAndPut(final byte[] row, final byte[] family, final byte[] qualifier, private CheckAndMutateResult doCheckAndPut(final byte[] row, final byte[] family,
final CompareOperator op, final byte[] value, final Filter filter, final TimeRange timeRange, final byte[] qualifier, final CompareOperator op, final byte[] value, final Filter filter,
final Put put) throws IOException { final TimeRange timeRange, final Put put) throws IOException {
ClientServiceCallable<Boolean> callable = ClientServiceCallable<CheckAndMutateResult> callable =
new ClientServiceCallable<Boolean>(this.connection, getName(), row, new ClientServiceCallable<CheckAndMutateResult>(this.connection, getName(), row,
this.rpcControllerFactory.newController(), put.getPriority()) { this.rpcControllerFactory.newController(), put.getPriority()) {
@Override @Override
protected Boolean rpcCall() throws Exception { protected CheckAndMutateResult rpcCall() throws Exception {
MutateRequest request = RequestConverter.buildMutateRequest( MutateRequest request = RequestConverter.buildMutateRequest(
getLocation().getRegionInfo().getRegionName(), row, family, qualifier, op, value, getLocation().getRegionInfo().getRegionName(), row, family, qualifier, op, value,
filter, timeRange, put); filter, timeRange, put);
MutateResponse response = doMutate(request); MutateResponse response = doMutate(request);
return Boolean.valueOf(response.getProcessed()); return new CheckAndMutateResult(response.getProcessed(), null);
} }
}; };
return rpcCallerFactory.<Boolean> newCaller(this.writeRpcTimeoutMs) return rpcCallerFactory.<CheckAndMutateResult> newCaller(this.writeRpcTimeoutMs)
.callWithRetries(callable, this.operationTimeoutMs); .callWithRetries(callable, this.operationTimeoutMs);
} }
@ -720,7 +720,7 @@ public class HTable implements Table {
public boolean checkAndDelete(final byte[] row, final byte[] family, final byte[] qualifier, public boolean checkAndDelete(final byte[] row, final byte[] family, final byte[] qualifier,
final byte[] value, final Delete delete) throws IOException { final byte[] value, final Delete delete) throws IOException {
return doCheckAndDelete(row, family, qualifier, CompareOperator.EQUAL, value, null, return doCheckAndDelete(row, family, qualifier, CompareOperator.EQUAL, value, null,
null, delete); null, delete).isSuccess();
} }
@Override @Override
@ -728,19 +728,19 @@ public class HTable implements Table {
public boolean checkAndDelete(final byte[] row, final byte[] family, final byte[] qualifier, public boolean checkAndDelete(final byte[] row, final byte[] family, final byte[] qualifier,
final CompareOp compareOp, final byte[] value, final Delete delete) throws IOException { final CompareOp compareOp, final byte[] value, final Delete delete) throws IOException {
return doCheckAndDelete(row, family, qualifier, toCompareOperator(compareOp), value, null, return doCheckAndDelete(row, family, qualifier, toCompareOperator(compareOp), value, null,
null, delete); null, delete).isSuccess();
} }
@Override @Override
@Deprecated @Deprecated
public boolean checkAndDelete(final byte[] row, final byte[] family, final byte[] qualifier, public boolean checkAndDelete(final byte[] row, final byte[] family, final byte[] qualifier,
final CompareOperator op, final byte[] value, final Delete delete) throws IOException { final CompareOperator op, final byte[] value, final Delete delete) throws IOException {
return doCheckAndDelete(row, family, qualifier, op, value, null, null, delete); return doCheckAndDelete(row, family, qualifier, op, value, null, null, delete).isSuccess();
} }
private boolean doCheckAndDelete(final byte[] row, final byte[] family, final byte[] qualifier, private CheckAndMutateResult doCheckAndDelete(final byte[] row, final byte[] family,
final CompareOperator op, final byte[] value, final Filter filter, final TimeRange timeRange, final byte[] qualifier, final CompareOperator op, final byte[] value, final Filter filter,
final Delete delete) throws IOException { final TimeRange timeRange, final Delete delete) throws IOException {
CancellableRegionServerCallable<SingleResponse> callable = CancellableRegionServerCallable<SingleResponse> callable =
new CancellableRegionServerCallable<SingleResponse>(this.connection, getName(), row, new CancellableRegionServerCallable<SingleResponse>(this.connection, getName(), row,
this.rpcControllerFactory.newController(), writeRpcTimeoutMs, this.rpcControllerFactory.newController(), writeRpcTimeoutMs,
@ -768,7 +768,7 @@ public class HTable implements Table {
if (ars.hasError()) { if (ars.hasError()) {
throw ars.getErrors(); throw ars.getErrors();
} }
return ((SingleResponse.Entry) results[0]).isProcessed(); return new CheckAndMutateResult(((SingleResponse.Entry) results[0]).isProcessed(), null);
} }
@Override @Override
@ -783,10 +783,9 @@ public class HTable implements Table {
return new CheckAndMutateWithFilterBuilderImpl(row, filter); return new CheckAndMutateWithFilterBuilderImpl(row, filter);
} }
private boolean doCheckAndMutate(final byte[] row, final byte[] family, final byte[] qualifier, private CheckAndMutateResult doCheckAndMutate(final byte[] row, final byte[] family,
final CompareOperator op, final byte[] value, final Filter filter, final TimeRange timeRange, final byte[] qualifier, final CompareOperator op, final byte[] value, final Filter filter,
final RowMutations rm) final TimeRange timeRange, final RowMutations rm) throws IOException {
throws IOException {
CancellableRegionServerCallable<MultiResponse> callable = CancellableRegionServerCallable<MultiResponse> callable =
new CancellableRegionServerCallable<MultiResponse>(connection, getName(), rm.getRow(), new CancellableRegionServerCallable<MultiResponse>(connection, getName(), rm.getRow(),
rpcControllerFactory.newController(), writeRpcTimeoutMs, new RetryingTimeTracker().start(), rpcControllerFactory.newController(), writeRpcTimeoutMs, new RetryingTimeTracker().start(),
@ -832,7 +831,7 @@ public class HTable implements Table {
throw ars.getErrors(); throw ars.getErrors();
} }
return ((Result)results[0]).getExists(); return (CheckAndMutateResult) results[0];
} }
@Override @Override
@ -841,18 +840,18 @@ public class HTable implements Table {
final CompareOp compareOp, final byte [] value, final RowMutations rm) final CompareOp compareOp, final byte [] value, final RowMutations rm)
throws IOException { throws IOException {
return doCheckAndMutate(row, family, qualifier, toCompareOperator(compareOp), value, null, return doCheckAndMutate(row, family, qualifier, toCompareOperator(compareOp), value, null,
null, rm); null, rm).isSuccess();
} }
@Override @Override
@Deprecated @Deprecated
public boolean checkAndMutate(final byte [] row, final byte [] family, final byte [] qualifier, public boolean checkAndMutate(final byte [] row, final byte [] family, final byte [] qualifier,
final CompareOperator op, final byte [] value, final RowMutations rm) throws IOException { final CompareOperator op, final byte [] value, final RowMutations rm) throws IOException {
return doCheckAndMutate(row, family, qualifier, op, value, null, null, rm); return doCheckAndMutate(row, family, qualifier, op, value, null, null, rm).isSuccess();
} }
@Override @Override
public boolean checkAndMutate(CheckAndMutate checkAndMutate) throws IOException { public CheckAndMutateResult checkAndMutate(CheckAndMutate checkAndMutate) throws IOException {
Row action = checkAndMutate.getAction(); Row action = checkAndMutate.getAction();
if (action instanceof Put) { if (action instanceof Put) {
Put put = (Put) action; Put put = (Put) action;
@ -872,12 +871,13 @@ public class HTable implements Table {
} }
@Override @Override
public boolean[] checkAndMutate(List<CheckAndMutate> checkAndMutates) throws IOException { public List<CheckAndMutateResult> checkAndMutate(List<CheckAndMutate> checkAndMutates)
throws IOException {
if (checkAndMutates.isEmpty()) { if (checkAndMutates.isEmpty()) {
return new boolean[]{}; return Collections.emptyList();
} }
if (checkAndMutates.size() == 1) { if (checkAndMutates.size() == 1) {
return new boolean[]{ checkAndMutate(checkAndMutates.get(0)) }; return Collections.singletonList(checkAndMutate(checkAndMutates.get(0)));
} }
Object[] results = new Object[checkAndMutates.size()]; Object[] results = new Object[checkAndMutates.size()];
@ -888,11 +888,10 @@ public class HTable implements Table {
} }
// translate. // translate.
boolean[] ret = new boolean[results.length]; List<CheckAndMutateResult> ret = new ArrayList<>(results.length);
int i = 0;
for (Object r : results) { for (Object r : results) {
// Batch ensures if there is a failure we get an exception instead // Batch ensures if there is a failure we get an exception instead
ret[i++] = ((Result) r).getExists(); ret.add((CheckAndMutateResult) r);
} }
return ret; return ret;
} }
@ -1329,20 +1328,21 @@ public class HTable implements Table {
public boolean thenPut(Put put) throws IOException { public boolean thenPut(Put put) throws IOException {
validatePut(put); validatePut(put);
preCheck(); preCheck();
return doCheckAndPut(row, family, qualifier, op, value, null, timeRange, put); return doCheckAndPut(row, family, qualifier, op, value, null, timeRange, put).isSuccess();
} }
@Override @Override
public boolean thenDelete(Delete delete) throws IOException { public boolean thenDelete(Delete delete) throws IOException {
preCheck(); preCheck();
return doCheckAndDelete(row, family, qualifier, op, value, null, timeRange, delete); return doCheckAndDelete(row, family, qualifier, op, value, null, timeRange, delete)
.isSuccess();
} }
@Override @Override
public boolean thenMutate(RowMutations mutation) throws IOException { public boolean thenMutate(RowMutations mutation) throws IOException {
preCheck(); preCheck();
return doCheckAndMutate(row, family, qualifier, op, value, null, timeRange, return doCheckAndMutate(row, family, qualifier, op, value, null, timeRange,
mutation); mutation).isSuccess();
} }
} }
@ -1366,17 +1366,18 @@ public class HTable implements Table {
@Override @Override
public boolean thenPut(Put put) throws IOException { public boolean thenPut(Put put) throws IOException {
validatePut(put); validatePut(put);
return doCheckAndPut(row, null, null, null, null, filter, timeRange, put); return doCheckAndPut(row, null, null, null, null, filter, timeRange, put).isSuccess();
} }
@Override @Override
public boolean thenDelete(Delete delete) throws IOException { public boolean thenDelete(Delete delete) throws IOException {
return doCheckAndDelete(row, null, null, null, null, filter, timeRange, delete); return doCheckAndDelete(row, null, null, null, null, filter, timeRange, delete).isSuccess();
} }
@Override @Override
public boolean thenMutate(RowMutations mutation) throws IOException { public boolean thenMutate(RowMutations mutation) throws IOException {
return doCheckAndMutate(row, null, null, null, null, filter, timeRange, mutation); return doCheckAndMutate(row, null, null, null, null, filter, timeRange, mutation)
.isSuccess();
} }
} }
} }

View File

@ -386,8 +386,7 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
.action((controller, loc, stub) -> RawAsyncTableImpl.this.mutateRow(controller, .action((controller, loc, stub) -> RawAsyncTableImpl.this.mutateRow(controller,
loc, stub, mutation, loc, stub, mutation,
(rn, rm) -> RequestConverter.buildMutateRequest(rn, row, family, qualifier, op, value, (rn, rm) -> RequestConverter.buildMutateRequest(rn, row, family, qualifier, op, value,
null, timeRange, rm), null, timeRange, rm), CheckAndMutateResult::isSuccess))
resp -> resp.getExists()))
.call(); .call();
} }
} }
@ -447,8 +446,7 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
.action((controller, loc, stub) -> RawAsyncTableImpl.this.mutateRow(controller, .action((controller, loc, stub) -> RawAsyncTableImpl.this.mutateRow(controller,
loc, stub, mutation, loc, stub, mutation,
(rn, rm) -> RequestConverter.buildMutateRequest(rn, row, null, null, null, null, (rn, rm) -> RequestConverter.buildMutateRequest(rn, row, null, null, null, null,
filter, timeRange, rm), filter, timeRange, rm), CheckAndMutateResult::isSuccess))
resp -> resp.getExists()))
.call(); .call();
} }
} }
@ -459,7 +457,7 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
} }
@Override @Override
public CompletableFuture<Boolean> checkAndMutate(CheckAndMutate checkAndMutate) { public CompletableFuture<CheckAndMutateResult> checkAndMutate(CheckAndMutate checkAndMutate) {
if (checkAndMutate.getAction() instanceof Put) { if (checkAndMutate.getAction() instanceof Put) {
validatePut((Put) checkAndMutate.getAction(), conn.connConf.getMaxKeyValueSize()); validatePut((Put) checkAndMutate.getAction(), conn.connConf.getMaxKeyValueSize());
} }
@ -469,7 +467,7 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
if (mutation instanceof Put) { if (mutation instanceof Put) {
validatePut((Put) mutation, conn.connConf.getMaxKeyValueSize()); validatePut((Put) mutation, conn.connConf.getMaxKeyValueSize());
} }
return RawAsyncTableImpl.this.<Boolean> newCaller(checkAndMutate.getRow(), return RawAsyncTableImpl.this.<CheckAndMutateResult> newCaller(checkAndMutate.getRow(),
mutation.getPriority(), rpcTimeoutNs) mutation.getPriority(), rpcTimeoutNs)
.action((controller, loc, stub) -> RawAsyncTableImpl.mutate(controller, .action((controller, loc, stub) -> RawAsyncTableImpl.mutate(controller,
loc, stub, mutation, loc, stub, mutation,
@ -477,22 +475,23 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
checkAndMutate.getFamily(), checkAndMutate.getQualifier(), checkAndMutate.getFamily(), checkAndMutate.getQualifier(),
checkAndMutate.getCompareOp(), checkAndMutate.getValue(), checkAndMutate.getFilter(), checkAndMutate.getCompareOp(), checkAndMutate.getValue(), checkAndMutate.getFilter(),
checkAndMutate.getTimeRange(), m), checkAndMutate.getTimeRange(), m),
(c, r) -> r.getProcessed())) (c, r) -> ResponseConverter.getCheckAndMutateResult(r)))
.call(); .call();
} else if (checkAndMutate.getAction() instanceof RowMutations) { } else if (checkAndMutate.getAction() instanceof RowMutations) {
RowMutations rowMutations = (RowMutations) checkAndMutate.getAction(); RowMutations rowMutations = (RowMutations) checkAndMutate.getAction();
return RawAsyncTableImpl.this.<Boolean> newCaller(checkAndMutate.getRow(), return RawAsyncTableImpl.this.<CheckAndMutateResult> newCaller(checkAndMutate.getRow(),
rowMutations.getMaxPriority(), rpcTimeoutNs) rowMutations.getMaxPriority(), rpcTimeoutNs)
.action((controller, loc, stub) -> RawAsyncTableImpl.this.mutateRow(controller, .action((controller, loc, stub) ->
loc, stub, rowMutations, RawAsyncTableImpl.this.<CheckAndMutateResult, CheckAndMutateResult> mutateRow(
(rn, rm) -> RequestConverter.buildMutateRequest(rn, checkAndMutate.getRow(), controller, loc, stub, rowMutations,
(rn, rm) -> RequestConverter.buildMutateRequest(rn, checkAndMutate.getRow(),
checkAndMutate.getFamily(), checkAndMutate.getQualifier(), checkAndMutate.getFamily(), checkAndMutate.getQualifier(),
checkAndMutate.getCompareOp(), checkAndMutate.getValue(), checkAndMutate.getFilter(), checkAndMutate.getCompareOp(), checkAndMutate.getValue(), checkAndMutate.getFilter(),
checkAndMutate.getTimeRange(), rm), checkAndMutate.getTimeRange(), rm),
resp -> resp.getExists())) resp -> resp))
.call(); .call();
} else { } else {
CompletableFuture<Boolean> future = new CompletableFuture<>(); CompletableFuture<CheckAndMutateResult> future = new CompletableFuture<>();
future.completeExceptionally(new DoNotRetryIOException( future.completeExceptionally(new DoNotRetryIOException(
"CheckAndMutate doesn't support " + checkAndMutate.getAction().getClass().getName())); "CheckAndMutate doesn't support " + checkAndMutate.getAction().getClass().getName()));
return future; return future;
@ -500,18 +499,19 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
} }
@Override @Override
public List<CompletableFuture<Boolean>> checkAndMutate(List<CheckAndMutate> checkAndMutates) { public List<CompletableFuture<CheckAndMutateResult>> checkAndMutate(
List<CheckAndMutate> checkAndMutates) {
return batch(checkAndMutates, rpcTimeoutNs).stream() return batch(checkAndMutates, rpcTimeoutNs).stream()
.map(f -> f.thenApply(r -> ((Result)r).getExists())) .map(f -> f.thenApply(r -> (CheckAndMutateResult) r)).collect(toList());
.collect(toList());
} }
// We need the MultiRequest when constructing the org.apache.hadoop.hbase.client.MultiResponse, // We need the MultiRequest when constructing the org.apache.hadoop.hbase.client.MultiResponse,
// so here I write a new method as I do not want to change the abstraction of call method. // so here I write a new method as I do not want to change the abstraction of call method.
private <RESP> CompletableFuture<RESP> mutateRow(HBaseRpcController controller, @SuppressWarnings("unchecked")
private <RES, RESP> CompletableFuture<RESP> mutateRow(HBaseRpcController controller,
HRegionLocation loc, ClientService.Interface stub, RowMutations mutation, HRegionLocation loc, ClientService.Interface stub, RowMutations mutation,
Converter<MultiRequest, byte[], RowMutations> reqConvert, Converter<MultiRequest, byte[], RowMutations> reqConvert,
Function<Result, RESP> respConverter) { Function<RES, RESP> respConverter) {
CompletableFuture<RESP> future = new CompletableFuture<>(); CompletableFuture<RESP> future = new CompletableFuture<>();
try { try {
byte[] regionName = loc.getRegion().getRegionName(); byte[] regionName = loc.getRegion().getRegionName();
@ -535,7 +535,7 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
"Failed to mutate row: " + Bytes.toStringBinary(mutation.getRow()), ex)); "Failed to mutate row: " + Bytes.toStringBinary(mutation.getRow()), ex));
} else { } else {
future.complete(respConverter future.complete(respConverter
.apply((Result) multiResp.getResults().get(regionName).result.get(0))); .apply((RES) multiResp.getResults().get(regionName).result.get(0)));
} }
} catch (IOException e) { } catch (IOException e) {
future.completeExceptionally(e); future.completeExceptionally(e);
@ -552,12 +552,15 @@ class RawAsyncTableImpl implements AsyncTable<AdvancedScanResultConsumer> {
@Override @Override
public CompletableFuture<Void> mutateRow(RowMutations mutation) { public CompletableFuture<Void> mutateRow(RowMutations mutation) {
return this.<Void> newCaller(mutation.getRow(), mutation.getMaxPriority(), writeRpcTimeoutNs) return this.<Void> newCaller(mutation.getRow(), mutation.getMaxPriority(), writeRpcTimeoutNs)
.action((controller, loc, stub) -> this.<Void> mutateRow(controller, loc, stub, mutation, .action((controller, loc, stub) ->
(rn, rm) -> { this.<Result, Void> mutateRow(controller, loc, stub, mutation,
RegionAction.Builder regionMutationBuilder = RequestConverter.buildRegionAction(rn, rm); (rn, rm) -> {
regionMutationBuilder.setAtomic(true); RegionAction.Builder regionMutationBuilder = RequestConverter
return MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build()).build(); .buildRegionAction(rn, rm);
}, resp -> null)) regionMutationBuilder.setAtomic(true);
return MultiRequest.newBuilder().addRegionAction(regionMutationBuilder.build())
.build();
}, resp -> null))
.call(); .call();
} }

View File

@ -617,11 +617,11 @@ public interface Table extends Closeable {
* it performs the specified action. * it performs the specified action.
* *
* @param checkAndMutate The CheckAndMutate object. * @param checkAndMutate The CheckAndMutate object.
* @return boolean that represents the result for the CheckAndMutate. * @return A CheckAndMutateResult object that represents the result for the CheckAndMutate.
* @throws IOException if a remote or network exception occurs. * @throws IOException if a remote or network exception occurs.
*/ */
default boolean checkAndMutate(CheckAndMutate checkAndMutate) throws IOException { default CheckAndMutateResult checkAndMutate(CheckAndMutate checkAndMutate) throws IOException {
return checkAndMutate(Collections.singletonList(checkAndMutate))[0]; return checkAndMutate(Collections.singletonList(checkAndMutate)).get(0);
} }
/** /**
@ -630,10 +630,12 @@ public interface Table extends Closeable {
* atomically (and thus, each may fail independently of others). * atomically (and thus, each may fail independently of others).
* *
* @param checkAndMutates The list of CheckAndMutate. * @param checkAndMutates The list of CheckAndMutate.
* @return A array of boolean that represents the result for each CheckAndMutate. * @return A list of CheckAndMutateResult objects that represents the result for each
* CheckAndMutate.
* @throws IOException if a remote or network exception occurs. * @throws IOException if a remote or network exception occurs.
*/ */
default boolean[] checkAndMutate(List<CheckAndMutate> checkAndMutates) throws IOException { default List<CheckAndMutateResult> checkAndMutate(List<CheckAndMutate> checkAndMutates)
throws IOException {
throw new NotImplementedException("Add an implementation!"); throw new NotImplementedException("Add an implementation!");
} }

View File

@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellScanner; import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.DoNotRetryIOException; import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.CheckAndMutateResult;
import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfo;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.SingleResponse; import org.apache.hadoop.hbase.client.SingleResponse;
@ -156,29 +157,55 @@ public final class ResponseConverter {
// This RegionAction is from a RowMutations/CheckAndMutate in a batch. // This RegionAction is from a RowMutations/CheckAndMutate in a batch.
// If there is an exception from the server, the exception is set at // If there is an exception from the server, the exception is set at
// the RegionActionResult level, which has been handled above. // the RegionActionResult level, which has been handled above.
responseValue = actionResult.getProcessed() ? if (actions.hasCondition()) {
Result result = null;
if (actionResult.getResultOrExceptionCount() > 0) {
ResultOrException roe = actionResult.getResultOrException(0);
if (roe.hasResult()) {
Result r = ProtobufUtil.toResult(roe.getResult(), cells);
if (!r.isEmpty()) {
result = r;
}
}
}
responseValue = new CheckAndMutateResult(actionResult.getProcessed(), result);
} else {
responseValue = actionResult.getProcessed() ?
ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE : ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE :
ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE; ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE;
}
results.add(regionName, index, responseValue); results.add(regionName, index, responseValue);
continue; continue;
} }
for (ResultOrException roe : actionResult.getResultOrExceptionList()) { if (actions.hasCondition()) {
if (roe.hasException()) { for (ResultOrException roe : actionResult.getResultOrExceptionList()) {
responseValue = ProtobufUtil.toException(roe.getException()); Result result = null;
} else if (roe.hasResult()) { Result r = ProtobufUtil.toResult(roe.getResult(), cells);
responseValue = ProtobufUtil.toResult(roe.getResult(), cells); if (!r.isEmpty()) {
} else if (roe.hasServiceResult()) { result = r;
responseValue = roe.getServiceResult(); }
} else { responseValue = new CheckAndMutateResult(actionResult.getProcessed(), result);
// Sometimes, the response is just "it was processed". Generally, this occurs for things results.add(regionName, roe.getIndex(), responseValue);
// like mutateRows where either we get back 'processed' (or not) and optionally some }
// statistics about the regions we touched. } else {
responseValue = actionResult.getProcessed() ? for (ResultOrException roe : actionResult.getResultOrExceptionList()) {
ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE : if (roe.hasException()) {
ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE; responseValue = ProtobufUtil.toException(roe.getException());
} else if (roe.hasResult()) {
responseValue = ProtobufUtil.toResult(roe.getResult(), cells);
} else if (roe.hasServiceResult()) {
responseValue = roe.getServiceResult();
} else {
// Sometimes, the response is just "it was processed". Generally, this occurs for things
// like mutateRows where either we get back 'processed' (or not) and optionally some
// statistics about the regions we touched.
responseValue = actionResult.getProcessed() ?
ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE :
ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE;
}
results.add(regionName, roe.getIndex(), responseValue);
} }
results.add(regionName, roe.getIndex(), responseValue);
} }
} }
@ -192,6 +219,21 @@ public final class ResponseConverter {
return results; return results;
} }
/**
* Create a CheckAndMutateResult object from a protocol buffer MutateResponse
*
* @return a CheckAndMutateResult object
*/
public static CheckAndMutateResult getCheckAndMutateResult(
ClientProtos.MutateResponse mutateResponse) {
boolean success = mutateResponse.getProcessed();
Result result = null;
if (mutateResponse.hasResult()) {
result = ProtobufUtil.toResult(mutateResponse.getResult());
}
return new CheckAndMutateResult(success, result);
}
/** /**
* Wrap a throwable to an action result. * Wrap a throwable to an action result.
* *

View File

@ -53,6 +53,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.CheckAndMutate; import org.apache.hadoop.hbase.client.CheckAndMutate;
import org.apache.hadoop.hbase.client.CheckAndMutateResult;
import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Increment; import org.apache.hadoop.hbase.client.Increment;
@ -812,13 +813,12 @@ public class RemoteHTable implements Table {
throw new UnsupportedOperationException("checkAndMutate not implemented"); throw new UnsupportedOperationException("checkAndMutate not implemented");
} }
@Override public CheckAndMutateResult checkAndMutate(CheckAndMutate checkAndMutate) {
public boolean checkAndMutate(CheckAndMutate checkAndMutate) {
throw new NotImplementedException("Implement later"); throw new NotImplementedException("Implement later");
} }
@Override @Override
public boolean[] checkAndMutate(List<CheckAndMutate> checkAndMutates) { public List<CheckAndMutateResult> checkAndMutate(List<CheckAndMutate> checkAndMutates) {
throw new NotImplementedException("Implement later"); throw new NotImplementedException("Implement later");
} }

View File

@ -632,7 +632,7 @@ public class TestAsyncTable {
.ifNotExists(FAMILY, QUALIFIER) .ifNotExists(FAMILY, QUALIFIER)
.build(new Put(row).addColumn(FAMILY, QUALIFIER, concat(VALUE, i)))) .build(new Put(row).addColumn(FAMILY, QUALIFIER, concat(VALUE, i))))
.thenAccept(x -> { .thenAccept(x -> {
if (x) { if (x.isSuccess()) {
successCount.incrementAndGet(); successCount.incrementAndGet();
successIndex.set(i); successIndex.set(i);
} }
@ -666,7 +666,7 @@ public class TestAsyncTable {
.build( .build(
new Delete(row).addColumn(FAMILY, QUALIFIER).addColumn(FAMILY, concat(QUALIFIER, i)))) new Delete(row).addColumn(FAMILY, QUALIFIER).addColumn(FAMILY, concat(QUALIFIER, i))))
.thenAccept(x -> { .thenAccept(x -> {
if (x) { if (x.isSuccess()) {
successCount.incrementAndGet(); successCount.incrementAndGet();
successIndex.set(i); successIndex.set(i);
} }
@ -713,7 +713,7 @@ public class TestAsyncTable {
.ifEquals(FAMILY, QUALIFIER, VALUE) .ifEquals(FAMILY, QUALIFIER, VALUE)
.build(mutation)) .build(mutation))
.thenAccept(x -> { .thenAccept(x -> {
if (x) { if (x.isSuccess()) {
successCount.incrementAndGet(); successCount.incrementAndGet();
successIndex.set(i); successIndex.set(i);
} }
@ -739,50 +739,50 @@ public class TestAsyncTable {
Put put = new Put(row); Put put = new Put(row);
put.addColumn(FAMILY, QUALIFIER, ts, VALUE); put.addColumn(FAMILY, QUALIFIER, ts, VALUE);
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifNotExists(FAMILY, QUALIFIER) .ifNotExists(FAMILY, QUALIFIER)
.build(put)).get(); .build(put)).get();
assertTrue(ok); assertTrue(result.isSuccess());
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifEquals(FAMILY, QUALIFIER, VALUE) .ifEquals(FAMILY, QUALIFIER, VALUE)
.timeRange(TimeRange.at(ts + 10000)) .timeRange(TimeRange.at(ts + 10000))
.build(put)).get(); .build(put)).get();
assertFalse(ok); assertFalse(result.isSuccess());
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifEquals(FAMILY, QUALIFIER, VALUE) .ifEquals(FAMILY, QUALIFIER, VALUE)
.timeRange(TimeRange.at(ts)) .timeRange(TimeRange.at(ts))
.build(put)).get(); .build(put)).get();
assertTrue(ok); assertTrue(result.isSuccess());
RowMutations rm = new RowMutations(row).add((Mutation) put); RowMutations rm = new RowMutations(row).add((Mutation) put);
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifEquals(FAMILY, QUALIFIER, VALUE) .ifEquals(FAMILY, QUALIFIER, VALUE)
.timeRange(TimeRange.at(ts + 10000)) .timeRange(TimeRange.at(ts + 10000))
.build(rm)).get(); .build(rm)).get();
assertFalse(ok); assertFalse(result.isSuccess());
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifEquals(FAMILY, QUALIFIER, VALUE) .ifEquals(FAMILY, QUALIFIER, VALUE)
.timeRange(TimeRange.at(ts)) .timeRange(TimeRange.at(ts))
.build(rm)).get(); .build(rm)).get();
assertTrue(ok); assertTrue(result.isSuccess());
Delete delete = new Delete(row).addColumn(FAMILY, QUALIFIER); Delete delete = new Delete(row).addColumn(FAMILY, QUALIFIER);
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifEquals(FAMILY, QUALIFIER, VALUE) .ifEquals(FAMILY, QUALIFIER, VALUE)
.timeRange(TimeRange.at(ts + 10000)) .timeRange(TimeRange.at(ts + 10000))
.build(delete)).get(); .build(delete)).get();
assertFalse(ok); assertFalse(result.isSuccess());
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifEquals(FAMILY, QUALIFIER, VALUE) .ifEquals(FAMILY, QUALIFIER, VALUE)
.timeRange(TimeRange.at(ts)) .timeRange(TimeRange.at(ts))
.build(delete)).get(); .build(delete)).get();
assertTrue(ok); assertTrue(result.isSuccess());
} }
@Test @Test
@ -797,45 +797,45 @@ public class TestAsyncTable {
table.put(put).get(); table.put(put).get();
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("a"))) CompareOperator.EQUAL, Bytes.toBytes("a")))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))).get(); .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))).get();
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get(); Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("b"))) CompareOperator.EQUAL, Bytes.toBytes("b")))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))).get(); .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))).get();
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());
// Delete with success // Delete with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("a"))) CompareOperator.EQUAL, Bytes.toBytes("a")))
.build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D")))).get(); .build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D")))).get();
assertTrue(ok); assertTrue(result.isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());
// Mutate with success // Mutate with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"),
CompareOperator.EQUAL, Bytes.toBytes("b"))) CompareOperator.EQUAL, Bytes.toBytes("b")))
.build(new RowMutations(row) .build(new RowMutations(row)
.add((Mutation) new Put(row) .add((Mutation) new Put(row)
.addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))) .addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))
.add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))))).get(); .add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))))).get();
assertTrue(ok); assertTrue(result.isSuccess());
result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get(); r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());
} }
@ -852,44 +852,44 @@ public class TestAsyncTable {
table.put(put).get(); table.put(put).get();
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,
Bytes.toBytes("b")))) Bytes.toBytes("b"))))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))).get(); .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))).get();
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get(); Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,
Bytes.toBytes("c")))) Bytes.toBytes("c"))))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))).get(); .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))).get();
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());
// Delete with success // Delete with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,
Bytes.toBytes("b")))) Bytes.toBytes("b"))))
.build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D")))).get(); .build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D")))).get();
assertTrue(ok); assertTrue(result.isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());
// Mutate with success // Mutate with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
@ -899,10 +899,10 @@ public class TestAsyncTable {
.add((Mutation) new Put(row) .add((Mutation) new Put(row)
.addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))) .addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))
.add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))))).get(); .add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))))).get();
assertTrue(ok); assertTrue(result.isSuccess());
result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get(); r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());
} }
@ -915,25 +915,25 @@ public class TestAsyncTable {
table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get(); table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),
new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),
new TimestampsFilter(Collections.singletonList(100L)))) new TimestampsFilter(Collections.singletonList(100L))))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get(); .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get(); Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B")))); assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),
new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),
new TimestampsFilter(Collections.singletonList(101L)))) new TimestampsFilter(Collections.singletonList(101L))))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))).get(); .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))).get();
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
} }
@ -947,24 +947,24 @@ public class TestAsyncTable {
.get(); .get();
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("a"))) CompareOperator.EQUAL, Bytes.toBytes("a")))
.timeRange(TimeRange.between(0, 101)) .timeRange(TimeRange.between(0, 101))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get(); .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get(); Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B")))); assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(row) result = table.checkAndMutate(CheckAndMutate.newBuilder(row)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("a"))) CompareOperator.EQUAL, Bytes.toBytes("a")))
.timeRange(TimeRange.between(0, 100)) .timeRange(TimeRange.between(0, 100))
.build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))) .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))))
.get(); .get();
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
} }
@ -993,11 +993,11 @@ public class TestAsyncTable {
.ifEquals(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("a")) .ifEquals(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("a"))
.build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f"))); .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f")));
List<Boolean> results = List<CheckAndMutateResult> results =
table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get(); Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get();
assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A")))); assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));
@ -1016,8 +1016,8 @@ public class TestAsyncTable {
results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());
@ -1041,8 +1041,8 @@ public class TestAsyncTable {
results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(row3)).get(); result = table.get(new Get(row3)).get();
assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F")))); assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));
@ -1075,11 +1075,11 @@ public class TestAsyncTable {
.ifNotExists(FAMILY, Bytes.toBytes("B")) .ifNotExists(FAMILY, Bytes.toBytes("B"))
.build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f"))); .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f")));
List<Boolean> results = List<CheckAndMutateResult> results =
table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get(); Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get();
assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A")))); assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));
@ -1098,8 +1098,8 @@ public class TestAsyncTable {
results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get(); result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get();
assertEquals("a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A")))); assertEquals("a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));
@ -1120,8 +1120,8 @@ public class TestAsyncTable {
results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(row3).addColumn(FAMILY, Bytes.toBytes("C"))).get(); result = table.get(new Get(row3).addColumn(FAMILY, Bytes.toBytes("C"))).get();
assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C")))); assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));
@ -1162,11 +1162,11 @@ public class TestAsyncTable {
Bytes.toBytes("b")))) Bytes.toBytes("b"))))
.build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h"))); .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h")));
List<Boolean> results = List<CheckAndMutateResult> results =
table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get(); Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get();
assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C")))); assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));
@ -1193,8 +1193,8 @@ public class TestAsyncTable {
results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get()); assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
@ -1226,8 +1226,8 @@ public class TestAsyncTable {
results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(row)).get(); result = table.get(new Get(row)).get();
assertNull(result.getValue(FAMILY, Bytes.toBytes("A"))); assertNull(result.getValue(FAMILY, Bytes.toBytes("A")));
@ -1269,11 +1269,11 @@ public class TestAsyncTable {
.timeRange(TimeRange.between(0, 100)) .timeRange(TimeRange.between(0, 100))
.build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h"))); .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h")));
List<Boolean> results = List<CheckAndMutateResult> results =
table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get(); table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();
assertTrue(results.get(0)); assertTrue(results.get(0).isSuccess());
assertFalse(results.get(1)); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get(); Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get();
assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C")))); assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));

View File

@ -367,11 +367,11 @@ public class TestAsyncTableBatch {
List<Row> actions = Arrays.asList(checkAndMutate1, get, mutations, checkAndMutate2, put); List<Row> actions = Arrays.asList(checkAndMutate1, get, mutations, checkAndMutate2, put);
List<Object> results = table.batchAll(actions).get(); List<Object> results = table.batchAll(actions).get();
assertTrue(((Result) results.get(0)).getExists()); assertTrue(((CheckAndMutateResult) results.get(0)).isSuccess());
assertEquals("b", assertEquals("b",
Bytes.toString(((Result) results.get(1)).getValue(FAMILY, Bytes.toBytes("B")))); Bytes.toString(((Result) results.get(1)).getValue(FAMILY, Bytes.toBytes("B"))));
assertTrue(((Result) results.get(2)).getExists()); assertTrue(((Result) results.get(2)).getExists());
assertFalse(((Result) results.get(3)).getExists()); assertFalse(((CheckAndMutateResult) results.get(3)).isSuccess());
assertTrue(((Result) results.get(4)).isEmpty()); assertTrue(((Result) results.get(4)).isEmpty());
Result result = table.get(new Get(row1)).get(); Result result = table.get(new Get(row1)).get();

View File

@ -26,6 +26,7 @@ import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import org.apache.hadoop.hbase.CompareOperator; import org.apache.hadoop.hbase.CompareOperator;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
@ -367,10 +368,10 @@ public class TestCheckAndMutate {
// put the same row again with C column deleted // put the same row again with C column deleted
RowMutations rm = makeRowMutationsWithColumnCDeleted(); RowMutations rm = makeRowMutationsWithColumnCDeleted();
boolean res = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) CheckAndMutateResult res = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")) .ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))
.build(rm)); .build(rm));
assertTrue(res); assertTrue(res.isSuccess());
// get row back and assert the values // get row back and assert the values
getOneRowAndAssertAllButCExist(table); getOneRowAndAssertAllButCExist(table);
@ -401,45 +402,45 @@ public class TestCheckAndMutate {
getOneRowAndAssertAllExist(table); getOneRowAndAssertAllExist(table);
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new SingleColumnValueFilter(FAMILY, .ifMatches(new SingleColumnValueFilter(FAMILY,
Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a"))) Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))));
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"))); Result r = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D")));
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("b"))) CompareOperator.EQUAL, Bytes.toBytes("b")))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e"))));
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E"))));
// Delete with success // Delete with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("a"))) CompareOperator.EQUAL, Bytes.toBytes("a")))
.build(new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("D")))); .build(new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("D"))));
assertTrue(ok); assertTrue(result.isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"))));
// Mutate with success // Mutate with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"),
CompareOperator.EQUAL, Bytes.toBytes("b"))) CompareOperator.EQUAL, Bytes.toBytes("b")))
.build(new RowMutations(ROWKEY) .build(new RowMutations(ROWKEY)
.add((Mutation) new Put(ROWKEY) .add((Mutation) new Put(ROWKEY)
.addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))) .addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))
.add((Mutation) new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("A"))))); .add((Mutation) new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("A")))));
assertTrue(ok); assertTrue(result.isSuccess());
result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"))); r = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D")));
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"))));
} }
@ -454,44 +455,44 @@ public class TestCheckAndMutate {
getOneRowAndAssertAllExist(table); getOneRowAndAssertAllExist(table);
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,
Bytes.toBytes("b")))) Bytes.toBytes("b"))))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))));
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"))); Result r = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D")));
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,
Bytes.toBytes("c")))) Bytes.toBytes("c"))))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e"))));
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("E"))));
// Delete with success // Delete with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,
Bytes.toBytes("b")))) Bytes.toBytes("b"))))
.build(new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("D")))); .build(new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("D"))));
assertTrue(ok); assertTrue(result.isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"))));
// Mutate with success // Mutate with success
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
Bytes.toBytes("a")), Bytes.toBytes("a")),
@ -501,10 +502,10 @@ public class TestCheckAndMutate {
.add((Mutation) new Put(ROWKEY) .add((Mutation) new Put(ROWKEY)
.addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))) .addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))
.add((Mutation) new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("A"))))); .add((Mutation) new Delete(ROWKEY).addColumns(FAMILY, Bytes.toBytes("A")))));
assertTrue(ok); assertTrue(result.isSuccess());
result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D"))); r = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("D")));
assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D")))); assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"))));
} }
@ -517,25 +518,25 @@ public class TestCheckAndMutate {
table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))); table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")));
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),
new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),
new TimestampsFilter(Collections.singletonList(100L)))) new TimestampsFilter(Collections.singletonList(100L))))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))));
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"))); Result r = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B")))); assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new FilterList( .ifMatches(new FilterList(
new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),
new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),
new TimestampsFilter(Collections.singletonList(101L)))) new TimestampsFilter(Collections.singletonList(101L))))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))));
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))));
} }
@ -548,23 +549,23 @@ public class TestCheckAndMutate {
table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))); table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")));
// Put with success // Put with success
boolean ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new SingleColumnValueFilter(FAMILY, .ifMatches(new SingleColumnValueFilter(FAMILY,
Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a"))) Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")))
.timeRange(TimeRange.between(0, 101)) .timeRange(TimeRange.between(0, 101))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))));
assertTrue(ok); assertTrue(result.isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"))); Result r = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B")))); assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure // Put with failure
ok = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY) result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY)
.ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"),
CompareOperator.EQUAL, Bytes.toBytes("a"))) CompareOperator.EQUAL, Bytes.toBytes("a")))
.timeRange(TimeRange.between(0, 100)) .timeRange(TimeRange.between(0, 100))
.build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))); .build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))));
assertFalse(ok); assertFalse(result.isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))));
} }
@ -596,10 +597,11 @@ public class TestCheckAndMutate {
.ifEquals(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("a")) .ifEquals(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("a"))
.build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f"))); .build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f")));
boolean[] results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); List<CheckAndMutateResult> results =
table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"))); Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A")));
assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A")))); assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));
@ -618,8 +620,8 @@ public class TestCheckAndMutate {
results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"))));
@ -643,8 +645,8 @@ public class TestCheckAndMutate {
results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(ROWKEY3)); result = table.get(new Get(ROWKEY3));
assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F")))); assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));
@ -674,10 +676,11 @@ public class TestCheckAndMutate {
.ifNotExists(FAMILY, Bytes.toBytes("B")) .ifNotExists(FAMILY, Bytes.toBytes("B"))
.build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f"))); .build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f")));
boolean[] results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); List<CheckAndMutateResult> results =
table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"))); Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A")));
assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A")))); assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));
@ -696,8 +699,8 @@ public class TestCheckAndMutate {
results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"))); result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A")));
assertEquals("a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A")))); assertEquals("a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));
@ -718,8 +721,8 @@ public class TestCheckAndMutate {
results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(ROWKEY3).addColumn(FAMILY, Bytes.toBytes("C"))); result = table.get(new Get(ROWKEY3).addColumn(FAMILY, Bytes.toBytes("C")));
assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C")))); assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));
@ -759,10 +762,11 @@ public class TestCheckAndMutate {
Bytes.toBytes("b")))) Bytes.toBytes("b"))))
.build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h"))); .build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h")));
boolean[] results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); List<CheckAndMutateResult> results =
table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))); Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C")));
assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C")))); assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));
@ -789,8 +793,8 @@ public class TestCheckAndMutate {
results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C")))); assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))));
@ -822,8 +826,8 @@ public class TestCheckAndMutate {
results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
result = table.get(new Get(ROWKEY)); result = table.get(new Get(ROWKEY));
assertNull(result.getValue(FAMILY, Bytes.toBytes("A"))); assertNull(result.getValue(FAMILY, Bytes.toBytes("A")));
@ -864,10 +868,11 @@ public class TestCheckAndMutate {
.timeRange(TimeRange.between(0, 100)) .timeRange(TimeRange.between(0, 100))
.build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h"))); .build(new Put(ROWKEY2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h")));
boolean[] results = table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2)); List<CheckAndMutateResult> results =
table.checkAndMutate(Arrays.asList(checkAndMutate1, checkAndMutate2));
assertTrue(results[0]); assertTrue(results.get(0).isSuccess());
assertFalse(results[1]); assertFalse(results.get(1).isSuccess());
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))); Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C")));
assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C")))); assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));

View File

@ -516,11 +516,11 @@ public class TestFromClientSide3 {
Object[] results = new Object[actions.size()]; Object[] results = new Object[actions.size()];
table.batch(actions, results); table.batch(actions, results);
assertTrue(((Result) results[0]).getExists()); assertTrue(((CheckAndMutateResult) results[0]).isSuccess());
assertEquals("b", assertEquals("b",
Bytes.toString(((Result) results[1]).getValue(FAMILY, Bytes.toBytes("B")))); Bytes.toString(((Result) results[1]).getValue(FAMILY, Bytes.toBytes("B"))));
assertTrue(((Result) results[2]).getExists()); assertTrue(((Result) results[2]).getExists());
assertFalse(((Result) results[3]).getExists()); assertFalse(((CheckAndMutateResult) results[3]).isSuccess());
assertTrue(((Result) results[4]).isEmpty()); assertTrue(((Result) results[4]).isEmpty());
Result result = table.get(new Get(row1)); Result result = table.get(new Get(row1));

View File

@ -37,6 +37,7 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.CheckAndMutate; import org.apache.hadoop.hbase.client.CheckAndMutate;
import org.apache.hadoop.hbase.client.CheckAndMutateResult;
import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Increment; import org.apache.hadoop.hbase.client.Increment;
@ -436,12 +437,12 @@ public class ThriftTable implements Table {
} }
@Override @Override
public boolean checkAndMutate(CheckAndMutate checkAndMutate) { public CheckAndMutateResult checkAndMutate(CheckAndMutate checkAndMutate) {
throw new NotImplementedException("Implement later"); throw new NotImplementedException("Implement later");
} }
@Override @Override
public boolean[] checkAndMutate(List<CheckAndMutate> checkAndMutates) { public List<CheckAndMutateResult> checkAndMutate(List<CheckAndMutate> checkAndMutates) {
throw new NotImplementedException("Implement later"); throw new NotImplementedException("Implement later");
} }