HBASE-19213 Align check and mutate operations in Table and AsyncTable
- Deprecates old checkAnd*() operations in Table - Adds Table#CheckAndMutateBuilder and implements it in HTable Commiter note: When committing the patch, noticed redundant {@inheritDoc} being added in HTable. Removed new and olds ones. Signed-off-by: Apekshit Sharma <appy@apache.org>
This commit is contained in:
parent
7755a98227
commit
941acc5c05
|
@ -240,6 +240,10 @@ public interface AsyncTable<C extends ScanResultConsumerBase> {
|
||||||
*/
|
*/
|
||||||
CheckAndMutateBuilder ifNotExists();
|
CheckAndMutateBuilder ifNotExists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for equality.
|
||||||
|
* @param value the expected value
|
||||||
|
*/
|
||||||
default CheckAndMutateBuilder ifEquals(byte[] value) {
|
default CheckAndMutateBuilder ifEquals(byte[] value) {
|
||||||
return ifMatches(CompareOperator.EQUAL, value);
|
return ifMatches(CompareOperator.EQUAL, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
|
||||||
import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
|
import org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel;
|
||||||
import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
|
import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
|
||||||
import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
|
import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
|
||||||
|
import org.apache.hadoop.hbase.shaded.com.google.common.base.Preconditions;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter;
|
import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter;
|
||||||
import org.apache.hadoop.hbase.shaded.protobuf.ResponseConverter;
|
import org.apache.hadoop.hbase.shaded.protobuf.ResponseConverter;
|
||||||
|
@ -206,9 +207,6 @@ public class HTable implements Table {
|
||||||
return conf.getInt(ConnectionConfiguration.MAX_KEYVALUE_SIZE_KEY, -1);
|
return conf.getInt(ConnectionConfiguration.MAX_KEYVALUE_SIZE_KEY, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Configuration getConfiguration() {
|
public Configuration getConfiguration() {
|
||||||
return configuration;
|
return configuration;
|
||||||
|
@ -229,9 +227,6 @@ public class HTable implements Table {
|
||||||
return this.connection;
|
return this.connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public HTableDescriptor getTableDescriptor() throws IOException {
|
public HTableDescriptor getTableDescriptor() throws IOException {
|
||||||
|
@ -362,9 +357,6 @@ public class HTable implements Table {
|
||||||
return getScanner(scan);
|
return getScanner(scan);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Result get(final Get get) throws IOException {
|
public Result get(final Get get) throws IOException {
|
||||||
return get(get, get.isCheckExistenceOnly());
|
return get(get, get.isCheckExistenceOnly());
|
||||||
|
@ -405,9 +397,6 @@ public class HTable implements Table {
|
||||||
return callable.call(operationTimeoutMs);
|
return callable.call(operationTimeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Result[] get(List<Get> gets) throws IOException {
|
public Result[] get(List<Get> gets) throws IOException {
|
||||||
if (gets.size() == 1) {
|
if (gets.size() == 1) {
|
||||||
|
@ -429,9 +418,6 @@ public class HTable implements Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void batch(final List<? extends Row> actions, final Object[] results)
|
public void batch(final List<? extends Row> actions, final Object[] results)
|
||||||
throws InterruptedException, IOException {
|
throws InterruptedException, IOException {
|
||||||
|
@ -472,9 +458,6 @@ public class HTable implements Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public <R> void batchCallback(
|
public <R> void batchCallback(
|
||||||
final List<? extends Row> actions, final Object[] results, final Batch.Callback<R> callback)
|
final List<? extends Row> actions, final Object[] results, final Batch.Callback<R> callback)
|
||||||
|
@ -505,9 +488,6 @@ public class HTable implements Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(final Delete delete)
|
public void delete(final Delete delete)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -540,9 +520,6 @@ public class HTable implements Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(final List<Delete> deletes)
|
public void delete(final List<Delete> deletes)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -565,10 +542,6 @@ public class HTable implements Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void put(final Put put) throws IOException {
|
public void put(final Put put) throws IOException {
|
||||||
validatePut(put);
|
validatePut(put);
|
||||||
|
@ -578,8 +551,7 @@ public class HTable implements Table {
|
||||||
@Override
|
@Override
|
||||||
protected Void rpcCall() throws Exception {
|
protected Void rpcCall() throws Exception {
|
||||||
MutateRequest request =
|
MutateRequest request =
|
||||||
RequestConverter.buildMutateRequest(getLocation().getRegionInfo().getRegionName(),
|
RequestConverter.buildMutateRequest(getLocation().getRegionInfo().getRegionName(), put);
|
||||||
put);
|
|
||||||
doMutate(request);
|
doMutate(request);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -588,10 +560,6 @@ public class HTable implements Table {
|
||||||
this.operationTimeoutMs);
|
this.operationTimeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void put(final List<Put> puts) throws IOException {
|
public void put(final List<Put> puts) throws IOException {
|
||||||
for (Put put : puts) {
|
for (Put put : puts) {
|
||||||
|
@ -605,9 +573,6 @@ public class HTable implements Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void mutateRow(final RowMutations rm) throws IOException {
|
public void mutateRow(final RowMutations rm) throws IOException {
|
||||||
CancellableRegionServerCallable<MultiResponse> callable =
|
CancellableRegionServerCallable<MultiResponse> callable =
|
||||||
|
@ -649,9 +614,6 @@ public class HTable implements Table {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Result append(final Append append) throws IOException {
|
public Result append(final Append append) throws IOException {
|
||||||
checkHasFamilies(append);
|
checkHasFamilies(append);
|
||||||
|
@ -671,9 +633,6 @@ public class HTable implements Table {
|
||||||
callWithRetries(callable, this.operationTimeoutMs);
|
callWithRetries(callable, this.operationTimeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Result increment(final Increment increment) throws IOException {
|
public Result increment(final Increment increment) throws IOException {
|
||||||
checkHasFamilies(increment);
|
checkHasFamilies(increment);
|
||||||
|
@ -693,9 +652,6 @@ public class HTable implements Table {
|
||||||
this.operationTimeoutMs);
|
this.operationTimeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public long incrementColumnValue(final byte [] row, final byte [] family,
|
public long incrementColumnValue(final byte [] row, final byte [] family,
|
||||||
final byte [] qualifier, final long amount)
|
final byte [] qualifier, final long amount)
|
||||||
|
@ -703,9 +659,6 @@ public class HTable implements Table {
|
||||||
return incrementColumnValue(row, family, qualifier, amount, Durability.SYNC_WAL);
|
return incrementColumnValue(row, family, qualifier, amount, Durability.SYNC_WAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public long incrementColumnValue(final byte [] row, final byte [] family,
|
public long incrementColumnValue(final byte [] row, final byte [] family,
|
||||||
final byte [] qualifier, final long amount, final Durability durability)
|
final byte [] qualifier, final long amount, final Durability durability)
|
||||||
|
@ -738,21 +691,31 @@ public class HTable implements Table {
|
||||||
callWithRetries(callable, this.operationTimeoutMs);
|
callWithRetries(callable, this.operationTimeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkAndPut(final byte [] row,
|
@Deprecated
|
||||||
final byte [] family, final byte [] qualifier, final byte [] value,
|
public boolean checkAndPut(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
final Put put)
|
final byte [] value, final Put put) throws IOException {
|
||||||
throws IOException {
|
return doCheckAndPut(row, family, qualifier, CompareOperator.EQUAL.name(), value, put);
|
||||||
return checkAndPut(row, family, qualifier, CompareOperator.EQUAL, value, put);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doCheckAndPut(final byte [] row, final byte [] family,
|
@Override
|
||||||
final byte [] qualifier, final String opName,
|
@Deprecated
|
||||||
final byte [] value, final Put put)
|
public boolean checkAndPut(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
throws IOException {
|
final CompareOp compareOp, final byte [] value, final Put put) throws IOException {
|
||||||
|
return doCheckAndPut(row, family, qualifier, compareOp.name(), value, put);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean checkAndPut(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
|
final CompareOperator op, final byte [] value, final Put put) throws IOException {
|
||||||
|
// The name of the operators in CompareOperator are intentionally those of the
|
||||||
|
// operators in the filter's CompareOp enum.
|
||||||
|
return doCheckAndPut(row, family, qualifier, op.name(), value, put);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doCheckAndPut(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
|
final String opName, final byte [] value, final Put put) throws IOException {
|
||||||
ClientServiceCallable<Boolean> callable =
|
ClientServiceCallable<Boolean> callable =
|
||||||
new ClientServiceCallable<Boolean>(this.connection, getName(), row,
|
new ClientServiceCallable<Boolean>(this.connection, getName(), row,
|
||||||
this.rpcControllerFactory.newController(), put.getPriority()) {
|
this.rpcControllerFactory.newController(), put.getPriority()) {
|
||||||
|
@ -766,52 +729,37 @@ public class HTable implements Table {
|
||||||
return Boolean.valueOf(response.getProcessed());
|
return Boolean.valueOf(response.getProcessed());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return rpcCallerFactory.<Boolean> newCaller(this.writeRpcTimeoutMs).
|
return rpcCallerFactory.<Boolean> newCaller(this.writeRpcTimeoutMs)
|
||||||
callWithRetries(callable, this.operationTimeoutMs);
|
.callWithRetries(callable, this.operationTimeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean checkAndPut(final byte [] row, final byte [] family,
|
|
||||||
final byte [] qualifier, final CompareOp compareOp, final byte [] value,
|
|
||||||
final Put put)
|
|
||||||
throws IOException {
|
|
||||||
return doCheckAndPut(row, family, qualifier, compareOp.name(), value, put);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean checkAndPut(final byte [] row, final byte [] family,
|
|
||||||
final byte [] qualifier, final CompareOperator op,
|
|
||||||
final byte [] value, final Put put)
|
|
||||||
throws IOException {
|
|
||||||
// The name of the operators in CompareOperator are intentionally those of the
|
|
||||||
// operators in the filter's CompareOp enum.
|
|
||||||
return doCheckAndPut(row, family, qualifier, op.name(), value, put);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
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 checkAndDelete(row, family, qualifier, CompareOperator.EQUAL, value, delete);
|
return doCheckAndDelete(row, family, qualifier, CompareOperator.EQUAL.name(), value, delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doCheckAndDelete(final byte [] row, final byte [] family,
|
@Override
|
||||||
final byte [] qualifier, final String opName,
|
@Deprecated
|
||||||
final byte [] value, final Delete delete)
|
public boolean checkAndDelete(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
throws IOException {
|
final CompareOp compareOp, final byte [] value, final Delete delete) throws IOException {
|
||||||
|
return doCheckAndDelete(row, family, qualifier, compareOp.name(), value, delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean checkAndDelete(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
|
final CompareOperator op, final byte [] value, final Delete delete) throws IOException {
|
||||||
|
return doCheckAndDelete(row, family, qualifier, op.name(), value, delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doCheckAndDelete(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
|
final String opName, final byte [] value, final Delete delete) throws IOException {
|
||||||
CancellableRegionServerCallable<SingleResponse> callable =
|
CancellableRegionServerCallable<SingleResponse> callable =
|
||||||
new CancellableRegionServerCallable<SingleResponse>(
|
new CancellableRegionServerCallable<SingleResponse>(
|
||||||
this.connection, getName(), row, this.rpcControllerFactory.newController(), writeRpcTimeoutMs,
|
this.connection, getName(), row, this.rpcControllerFactory.newController(),
|
||||||
new RetryingTimeTracker().start(), delete.getPriority()) {
|
writeRpcTimeoutMs, new RetryingTimeTracker().start(), delete.getPriority()) {
|
||||||
@Override
|
@Override
|
||||||
protected SingleResponse rpcCall() throws Exception {
|
protected SingleResponse rpcCall() throws Exception {
|
||||||
CompareType compareType = CompareType.valueOf(opName);
|
CompareType compareType = CompareType.valueOf(opName);
|
||||||
|
@ -843,27 +791,9 @@ public class HTable implements Table {
|
||||||
return ((SingleResponse.Entry)results[0]).isProcessed();
|
return ((SingleResponse.Entry)results[0]).isProcessed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family) {
|
||||||
public boolean checkAndDelete(final byte [] row, final byte [] family,
|
return new CheckAndMutateBuilderImpl(row, family);
|
||||||
final byte [] qualifier, final CompareOp compareOp, final byte [] value,
|
|
||||||
final Delete delete)
|
|
||||||
throws IOException {
|
|
||||||
return doCheckAndDelete(row, family, qualifier, compareOp.name(), value, delete);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean checkAndDelete(final byte [] row, final byte [] family,
|
|
||||||
final byte [] qualifier, final CompareOperator op,
|
|
||||||
final byte [] value, final Delete delete)
|
|
||||||
throws IOException {
|
|
||||||
return doCheckAndDelete(row, family, qualifier, op.name(), value, delete);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doCheckAndMutate(final byte [] row, final byte [] family, final byte [] qualifier,
|
private boolean doCheckAndMutate(final byte [] row, final byte [] family, final byte [] qualifier,
|
||||||
|
@ -918,9 +848,6 @@ public class HTable implements Table {
|
||||||
return ((Result)results[0]).getExists();
|
return ((Result)results[0]).getExists();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@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,
|
||||||
|
@ -929,19 +856,13 @@ public class HTable implements Table {
|
||||||
return doCheckAndMutate(row, family, qualifier, compareOp.name(), value, rm);
|
return doCheckAndMutate(row, family, qualifier, compareOp.name(), value, rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
|
@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)
|
final CompareOperator op, final byte [] value, final RowMutations rm) throws IOException {
|
||||||
throws IOException {
|
|
||||||
return doCheckAndMutate(row, family, qualifier, op.name(), value, rm);
|
return doCheckAndMutate(row, family, qualifier, op.name(), value, rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(final Get get) throws IOException {
|
public boolean exists(final Get get) throws IOException {
|
||||||
Result r = get(get, true);
|
Result r = get(get, true);
|
||||||
|
@ -1054,17 +975,11 @@ public class HTable implements Table {
|
||||||
this.connection.clearRegionCache();
|
this.connection.clearRegionCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public CoprocessorRpcChannel coprocessorService(byte[] row) {
|
public CoprocessorRpcChannel coprocessorService(byte[] row) {
|
||||||
return new RegionCoprocessorRpcChannel(connection, tableName, row);
|
return new RegionCoprocessorRpcChannel(connection, tableName, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Service, R> Map<byte[],R> coprocessorService(final Class<T> service,
|
public <T extends Service, R> Map<byte[],R> coprocessorService(final Class<T> service,
|
||||||
byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable)
|
byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable)
|
||||||
|
@ -1082,9 +997,6 @@ public class HTable implements Table {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Service, R> void coprocessorService(final Class<T> service,
|
public <T extends Service, R> void coprocessorService(final Class<T> service,
|
||||||
byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable,
|
byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable,
|
||||||
|
@ -1227,9 +1139,6 @@ public class HTable implements Table {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public <R extends Message> void batchCoprocessorService(
|
public <R extends Message> void batchCoprocessorService(
|
||||||
final Descriptors.MethodDescriptor methodDescriptor, final Message request,
|
final Descriptors.MethodDescriptor methodDescriptor, final Message request,
|
||||||
|
@ -1323,4 +1232,62 @@ public class HTable implements Table {
|
||||||
public RegionLocator getRegionLocator() {
|
public RegionLocator getRegionLocator() {
|
||||||
return this.locator;
|
return this.locator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class CheckAndMutateBuilderImpl implements CheckAndMutateBuilder {
|
||||||
|
|
||||||
|
private final byte[] row;
|
||||||
|
private final byte[] family;
|
||||||
|
private byte[] qualifier;
|
||||||
|
private CompareOperator op;
|
||||||
|
private byte[] value;
|
||||||
|
|
||||||
|
CheckAndMutateBuilderImpl(byte[] row, byte[] family) {
|
||||||
|
this.row = Preconditions.checkNotNull(row, "row is null");
|
||||||
|
this.family = Preconditions.checkNotNull(family, "family is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder qualifier(byte[] qualifier) {
|
||||||
|
this.qualifier = Preconditions.checkNotNull(qualifier, "qualifier is null. Consider using" +
|
||||||
|
" an empty byte array, or just do not call this method if you want a null qualifier");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder ifNotExists() {
|
||||||
|
this.op = CompareOperator.EQUAL;
|
||||||
|
this.value = null;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder ifMatches(CompareOperator compareOp, byte[] value) {
|
||||||
|
this.op = Preconditions.checkNotNull(compareOp, "compareOp is null");
|
||||||
|
this.value = Preconditions.checkNotNull(value, "value is null");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void preCheck() {
|
||||||
|
Preconditions.checkNotNull(op, "condition is null. You need to specify the condition by" +
|
||||||
|
" calling ifNotExists/ifEquals/ifMatches before executing the request");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean thenPut(Put put) throws IOException {
|
||||||
|
preCheck();
|
||||||
|
return doCheckAndPut(row, family, qualifier, op.name(), value, put);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean thenDelete(Delete delete) throws IOException {
|
||||||
|
preCheck();
|
||||||
|
return doCheckAndDelete(row, family, qualifier, op.name(), value, delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean thenMutate(RowMutations mutation) throws IOException {
|
||||||
|
preCheck();
|
||||||
|
return doCheckAndMutate(row, family, qualifier, op.name(), value, mutation);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,9 @@ public interface Table extends Closeable {
|
||||||
* @param put data to put if check succeeds
|
* @param put data to put if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new put was executed, false otherwise
|
* @return true if the new put was executed, false otherwise
|
||||||
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
||||||
byte[] value, Put put) throws IOException;
|
byte[] value, Put put) throws IOException;
|
||||||
|
|
||||||
|
@ -281,8 +283,7 @@ public interface Table extends Closeable {
|
||||||
* @param put data to put if check succeeds
|
* @param put data to put if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new put was executed, false otherwise
|
* @return true if the new put was executed, false otherwise
|
||||||
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
* {@link #checkAndPut(byte[], byte[], byte[], CompareOperator, byte[], Put)}}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
||||||
|
@ -306,9 +307,11 @@ public interface Table extends Closeable {
|
||||||
* @param put data to put if check succeeds
|
* @param put data to put if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new put was executed, false otherwise
|
* @return true if the new put was executed, false otherwise
|
||||||
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
*/
|
*/
|
||||||
boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
@Deprecated
|
||||||
CompareOperator op, byte[] value, Put put) throws IOException;
|
boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, CompareOperator op,
|
||||||
|
byte[] value, Put put) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the specified cells/row.
|
* Deletes the specified cells/row.
|
||||||
|
@ -356,7 +359,9 @@ public interface Table extends Closeable {
|
||||||
* @param delete data to delete if check succeeds
|
* @param delete data to delete if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new delete was executed, false otherwise
|
* @return true if the new delete was executed, false otherwise
|
||||||
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
||||||
byte[] value, Delete delete) throws IOException;
|
byte[] value, Delete delete) throws IOException;
|
||||||
|
|
||||||
|
@ -378,8 +383,7 @@ public interface Table extends Closeable {
|
||||||
* @param delete data to delete if check succeeds
|
* @param delete data to delete if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new delete was executed, false otherwise
|
* @return true if the new delete was executed, false otherwise
|
||||||
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
* {@link #checkAndDelete(byte[], byte[], byte[], byte[], Delete)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
||||||
|
@ -403,10 +407,74 @@ public interface Table extends Closeable {
|
||||||
* @param delete data to delete if check succeeds
|
* @param delete data to delete if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new delete was executed, false otherwise
|
* @return true if the new delete was executed, false otherwise
|
||||||
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
||||||
CompareOperator op, byte[] value, Delete delete) throws IOException;
|
CompareOperator op, byte[] value, Delete delete) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atomically checks if a row/family/qualifier value matches the expected value. If it does, it
|
||||||
|
* adds the Put/Delete/RowMutations.
|
||||||
|
* <p>
|
||||||
|
* Use the returned {@link CheckAndMutateBuilder} to construct your request and then execute it.
|
||||||
|
* This is a fluent style API, the code is like:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <code>
|
||||||
|
* table.checkAndMutate(row, family).qualifier(qualifier).ifNotExists().thenPut(put);
|
||||||
|
* </code>
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family);
|
||||||
|
/**
|
||||||
|
* A helper class for sending checkAndMutate request.
|
||||||
|
*/
|
||||||
|
interface CheckAndMutateBuilder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param qualifier column qualifier to check.
|
||||||
|
*/
|
||||||
|
CheckAndMutateBuilder qualifier(byte[] qualifier);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for lack of column.
|
||||||
|
*/
|
||||||
|
CheckAndMutateBuilder ifNotExists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for equality.
|
||||||
|
* @param value the expected value
|
||||||
|
*/
|
||||||
|
default CheckAndMutateBuilder ifEquals(byte[] value) {
|
||||||
|
return ifMatches(CompareOperator.EQUAL, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param compareOp comparison operator to use
|
||||||
|
* @param value the expected value
|
||||||
|
*/
|
||||||
|
CheckAndMutateBuilder ifMatches(CompareOperator compareOp, byte[] value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param put data to put if check succeeds
|
||||||
|
* @return {@code true} if the new put was executed, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
boolean thenPut(Put put) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param delete data to delete if check succeeds
|
||||||
|
* @return {@code true} if the new delete was executed, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
boolean thenDelete(Delete delete) throws IOException;
|
||||||
|
/**
|
||||||
|
* @param mutation mutations to perform if check succeeds
|
||||||
|
* @return true if the new mutation was executed, false otherwise.
|
||||||
|
*/
|
||||||
|
boolean thenMutate(RowMutations mutation) throws IOException;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs multiple mutations atomically on a single row. Currently
|
* Performs multiple mutations atomically on a single row. Currently
|
||||||
* {@link Put} and {@link Delete} are supported.
|
* {@link Put} and {@link Delete} are supported.
|
||||||
|
@ -649,8 +717,7 @@ public interface Table extends Closeable {
|
||||||
* @param mutation mutations to perform if check succeeds
|
* @param mutation mutations to perform if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new put was executed, false otherwise
|
* @return true if the new put was executed, false otherwise
|
||||||
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
* {@link #checkAndMutate(byte[], byte[], byte[], CompareOperator, byte[], RowMutations)}
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
||||||
|
@ -674,7 +741,9 @@ public interface Table extends Closeable {
|
||||||
* @param mutation mutations to perform if check succeeds
|
* @param mutation mutations to perform if check succeeds
|
||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
* @return true if the new put was executed, false otherwise
|
* @return true if the new put was executed, false otherwise
|
||||||
|
* @deprecated Since 2.0.0. Will be removed in 3.0.0. Use {@link #checkAndMutate(byte[], byte[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareOperator op,
|
boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareOperator op,
|
||||||
byte[] value, RowMutations mutation) throws IOException;
|
byte[] value, RowMutations mutation) throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -1892,8 +1892,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
||||||
this.table.put(put);
|
this.table.put(put);
|
||||||
RowMutations mutations = new RowMutations(bytes);
|
RowMutations mutations = new RowMutations(bytes);
|
||||||
mutations.add(put);
|
mutations.add(put);
|
||||||
this.table.checkAndMutate(bytes, FAMILY_NAME, getQualifier(), CompareOperator.EQUAL, bytes,
|
this.table.checkAndMutate(bytes, FAMILY_NAME).qualifier(getQualifier())
|
||||||
mutations);
|
.ifEquals(bytes).thenMutate(mutations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1909,7 +1909,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
||||||
Put put = new Put(bytes);
|
Put put = new Put(bytes);
|
||||||
put.addColumn(FAMILY_NAME, getQualifier(), bytes);
|
put.addColumn(FAMILY_NAME, getQualifier(), bytes);
|
||||||
this.table.put(put);
|
this.table.put(put);
|
||||||
this.table.checkAndPut(bytes, FAMILY_NAME, getQualifier(), CompareOperator.EQUAL, bytes, put);
|
this.table.checkAndMutate(bytes, FAMILY_NAME).qualifier(getQualifier())
|
||||||
|
.ifEquals(bytes).thenPut(put);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1927,8 +1928,8 @@ public class PerformanceEvaluation extends Configured implements Tool {
|
||||||
this.table.put(put);
|
this.table.put(put);
|
||||||
Delete delete = new Delete(put.getRow());
|
Delete delete = new Delete(put.getRow());
|
||||||
delete.addColumn(FAMILY_NAME, getQualifier());
|
delete.addColumn(FAMILY_NAME, getQualifier());
|
||||||
this.table.checkAndDelete(bytes, FAMILY_NAME, getQualifier(),
|
this.table.checkAndMutate(bytes, FAMILY_NAME).qualifier(getQualifier())
|
||||||
CompareOperator.EQUAL, bytes, delete);
|
.ifEquals(bytes).thenDelete(delete);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -363,8 +363,8 @@ public class TableBasedReplicationQueuesImpl extends ReplicationTableBase
|
||||||
*/
|
*/
|
||||||
private void safeQueueUpdate(RowMutations mutate) throws ReplicationException, IOException{
|
private void safeQueueUpdate(RowMutations mutate) throws ReplicationException, IOException{
|
||||||
try (Table replicationTable = getOrBlockOnReplicationTable()) {
|
try (Table replicationTable = getOrBlockOnReplicationTable()) {
|
||||||
boolean updateSuccess = replicationTable.checkAndMutate(mutate.getRow(),
|
boolean updateSuccess = replicationTable.checkAndMutate(mutate.getRow(), CF_QUEUE)
|
||||||
CF_QUEUE, COL_QUEUE_OWNER, CompareOperator.EQUAL, serverNameBytes, mutate);
|
.qualifier(COL_QUEUE_OWNER).ifEquals(serverNameBytes).thenMutate(mutate);
|
||||||
if (!updateSuccess) {
|
if (!updateSuccess) {
|
||||||
throw new ReplicationException("Failed to update Replication Table because we lost queue " +
|
throw new ReplicationException("Failed to update Replication Table because we lost queue " +
|
||||||
" ownership");
|
" ownership");
|
||||||
|
@ -408,9 +408,9 @@ public class TableBasedReplicationQueuesImpl extends ReplicationTableBase
|
||||||
// server. If it is not then another RS has already claimed it. If it is we set ourselves as the
|
// server. If it is not then another RS has already claimed it. If it is we set ourselves as the
|
||||||
// new owner and update the queue's history
|
// new owner and update the queue's history
|
||||||
try (Table replicationTable = getOrBlockOnReplicationTable()) {
|
try (Table replicationTable = getOrBlockOnReplicationTable()) {
|
||||||
boolean success = replicationTable.checkAndMutate(queue.getRow(),
|
boolean success = replicationTable.checkAndMutate(queue.getRow(), CF_QUEUE)
|
||||||
CF_QUEUE, COL_QUEUE_OWNER, CompareOperator.EQUAL, Bytes.toBytes(originalServer),
|
.qualifier(COL_QUEUE_OWNER).ifEquals(Bytes.toBytes(originalServer))
|
||||||
claimAndRenameQueue);
|
.thenMutate(claimAndRenameQueue);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,8 +509,8 @@ public class RowResource extends ResourceBase {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
|
return Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT)
|
||||||
.entity("Bad request: The column to put and check do not match." + CRLF).build();
|
.entity("Bad request: The column to put and check do not match." + CRLF).build();
|
||||||
} else {
|
} else {
|
||||||
retValue = table.checkAndPut(key, valueToPutParts[0], valueToPutParts[1],
|
retValue = table.checkAndMutate(key, valueToPutParts[0]).qualifier(valueToPutParts[1])
|
||||||
valueToCheckCell.getValue(), put);
|
.ifEquals(valueToCheckCell.getValue()).thenPut(put);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
servlet.getMetrics().incrementFailedPutRequests(1);
|
servlet.getMetrics().incrementFailedPutRequests(1);
|
||||||
|
@ -630,15 +630,15 @@ public class RowResource extends ResourceBase {
|
||||||
if(cellModelCount == 1) {
|
if(cellModelCount == 1) {
|
||||||
delete.addColumns(parts[0], parts[1]);
|
delete.addColumns(parts[0], parts[1]);
|
||||||
}
|
}
|
||||||
retValue = table.checkAndDelete(key, parts[0], parts[1],
|
retValue = table.checkAndMutate(key, parts[0]).qualifier(parts[1])
|
||||||
valueToDeleteCell.getValue(), delete);
|
.ifEquals(valueToDeleteCell.getValue()).thenDelete(delete);
|
||||||
} else {
|
} else {
|
||||||
// The case of empty qualifier.
|
// The case of empty qualifier.
|
||||||
if(cellModelCount == 1) {
|
if(cellModelCount == 1) {
|
||||||
delete.addColumns(parts[0], Bytes.toBytes(StringUtils.EMPTY));
|
delete.addColumns(parts[0], Bytes.toBytes(StringUtils.EMPTY));
|
||||||
}
|
}
|
||||||
retValue = table.checkAndDelete(key, parts[0], Bytes.toBytes(StringUtils.EMPTY),
|
retValue = table.checkAndMutate(key, parts[0])
|
||||||
valueToDeleteCell.getValue(), delete);
|
.ifEquals(valueToDeleteCell.getValue()).thenDelete(delete);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
servlet.getMetrics().incrementFailedDeleteRequests(1);
|
servlet.getMetrics().incrementFailedDeleteRequests(1);
|
||||||
|
|
|
@ -76,6 +76,8 @@ import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.hadoop.hbase.shaded.com.google.common.base.Preconditions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTable interface to remote tables accessed via REST gateway
|
* HTable interface to remote tables accessed via REST gateway
|
||||||
*/
|
*/
|
||||||
|
@ -666,8 +668,14 @@ public class RemoteHTable implements Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
||||||
byte[] value, Put put) throws IOException {
|
byte[] value, Put put) throws IOException {
|
||||||
|
return doCheckAndPut(row, family, qualifier, value, put);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doCheckAndPut(byte[] row, byte[] family, byte[] qualifier,
|
||||||
|
byte[] value, Put put) throws IOException {
|
||||||
// column to check-the-value
|
// column to check-the-value
|
||||||
put.add(new KeyValue(row, family, qualifier, value));
|
put.add(new KeyValue(row, family, qualifier, value));
|
||||||
|
|
||||||
|
@ -710,6 +718,7 @@ public class RemoteHTable implements Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
||||||
CompareOperator compareOp, byte[] value, Put put) throws IOException {
|
CompareOperator compareOp, byte[] value, Put put) throws IOException {
|
||||||
throw new IOException("checkAndPut for non-equal comparison not implemented");
|
throw new IOException("checkAndPut for non-equal comparison not implemented");
|
||||||
|
@ -718,6 +727,11 @@ public class RemoteHTable implements Table {
|
||||||
@Override
|
@Override
|
||||||
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
||||||
byte[] value, Delete delete) throws IOException {
|
byte[] value, Delete delete) throws IOException {
|
||||||
|
return doCheckAndDelete(row, family, qualifier, value, delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doCheckAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
||||||
|
byte[] value, Delete delete) throws IOException {
|
||||||
Put put = new Put(row);
|
Put put = new Put(row);
|
||||||
put.setFamilyCellMap(delete.getFamilyCellMap());
|
put.setFamilyCellMap(delete.getFamilyCellMap());
|
||||||
// column to check-the-value
|
// column to check-the-value
|
||||||
|
@ -761,11 +775,31 @@ public class RemoteHTable implements Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
||||||
CompareOperator compareOp, byte[] value, Delete delete) throws IOException {
|
CompareOperator compareOp, byte[] value, Delete delete) throws IOException {
|
||||||
throw new IOException("checkAndDelete for non-equal comparison not implemented");
|
throw new IOException("checkAndDelete for non-equal comparison not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family) {
|
||||||
|
return new CheckAndMutateBuilderImpl(row, family);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
||||||
|
CompareOp compareOp, byte[] value, RowMutations rm) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("checkAndMutate not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
||||||
|
CompareOperator compareOp, byte[] value, RowMutations rm) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("checkAndMutate not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result increment(Increment increment) throws IOException {
|
public Result increment(Increment increment) throws IOException {
|
||||||
throw new IOException("Increment not supported");
|
throw new IOException("Increment not supported");
|
||||||
|
@ -838,19 +872,6 @@ public class RemoteHTable implements Table {
|
||||||
throw new UnsupportedOperationException("batchCoprocessorService not implemented");
|
throw new UnsupportedOperationException("batchCoprocessorService not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
|
||||||
CompareOp compareOp, byte[] value, RowMutations rm) throws IOException {
|
|
||||||
throw new UnsupportedOperationException("checkAndMutate not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
|
||||||
CompareOperator compareOp, byte[] value, RowMutations rm) throws IOException {
|
|
||||||
throw new UnsupportedOperationException("checkAndMutate not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setOperationTimeout(int operationTimeout) {
|
public void setOperationTimeout(int operationTimeout) {
|
||||||
|
@ -933,4 +954,62 @@ public class RemoteHTable implements Table {
|
||||||
throw new IllegalStateException("URLEncoder doesn't support UTF-8", e);
|
throw new IllegalStateException("URLEncoder doesn't support UTF-8", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class CheckAndMutateBuilderImpl implements CheckAndMutateBuilder {
|
||||||
|
|
||||||
|
private final byte[] row;
|
||||||
|
private final byte[] family;
|
||||||
|
private byte[] qualifier;
|
||||||
|
private byte[] value;
|
||||||
|
|
||||||
|
CheckAndMutateBuilderImpl(byte[] row, byte[] family) {
|
||||||
|
this.row = Preconditions.checkNotNull(row, "row is null");
|
||||||
|
this.family = Preconditions.checkNotNull(family, "family is null");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder qualifier(byte[] qualifier) {
|
||||||
|
this.qualifier = Preconditions.checkNotNull(qualifier, "qualifier is null. Consider using" +
|
||||||
|
" an empty byte array, or just do not call this method if you want a null qualifier");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder ifNotExists() {
|
||||||
|
throw new UnsupportedOperationException("CheckAndMutate for non-equal comparison "
|
||||||
|
+ "not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder ifMatches(CompareOperator compareOp, byte[] value) {
|
||||||
|
if (compareOp == CompareOperator.EQUAL) {
|
||||||
|
this.value = Preconditions.checkNotNull(value, "value is null");
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException("CheckAndMutate for non-equal comparison " +
|
||||||
|
"not implemented");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder ifEquals(byte[] value) {
|
||||||
|
this.value = Preconditions.checkNotNull(value, "value is null");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean thenPut(Put put) throws IOException {
|
||||||
|
return doCheckAndPut(row, family, qualifier, value, put);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean thenDelete(Delete delete) throws IOException {
|
||||||
|
return doCheckAndDelete(row, family, qualifier, value, delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean thenMutate(RowMutations mutation) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("thenMutate not implemented");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,8 @@ public class TestRemoteHTableRetries {
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
Put put = new Put(ROW_1);
|
Put put = new Put(ROW_1);
|
||||||
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1);
|
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||||
remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, put );
|
remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1)
|
||||||
|
.ifEquals(VALUE_1).thenPut(put);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
verify(client, times(RETRIES)).put(anyString(), anyString(), any());
|
verify(client, times(RETRIES)).put(anyString(), anyString(), any());
|
||||||
|
@ -166,7 +167,9 @@ public class TestRemoteHTableRetries {
|
||||||
Put put = new Put(ROW_1);
|
Put put = new Put(ROW_1);
|
||||||
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1);
|
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||||
Delete delete= new Delete(ROW_1);
|
Delete delete= new Delete(ROW_1);
|
||||||
remoteTable.checkAndDelete(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, delete );
|
//remoteTable.checkAndDelete(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, delete );
|
||||||
|
remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1)
|
||||||
|
.ifEquals(VALUE_1).thenDelete(delete);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,17 +481,18 @@ public class TestRemoteTable {
|
||||||
assertEquals(1, remoteTable.existsAll(Collections.singletonList(get)).length);
|
assertEquals(1, remoteTable.existsAll(Collections.singletonList(get)).length);
|
||||||
Delete delete = new Delete(ROW_1);
|
Delete delete = new Delete(ROW_1);
|
||||||
|
|
||||||
remoteTable.checkAndDelete(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1, delete);
|
remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1)
|
||||||
|
.ifEquals(VALUE_1).thenDelete(delete);
|
||||||
assertFalse(remoteTable.exists(get));
|
assertFalse(remoteTable.exists(get));
|
||||||
|
|
||||||
Put put = new Put(ROW_1);
|
Put put = new Put(ROW_1);
|
||||||
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1);
|
put.addColumn(COLUMN_1, QUALIFIER_1, VALUE_1);
|
||||||
remoteTable.put(put);
|
remoteTable.put(put);
|
||||||
|
|
||||||
assertTrue(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_1,
|
assertTrue(remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1)
|
||||||
put));
|
.ifEquals(VALUE_1).thenPut(put));
|
||||||
assertFalse(remoteTable.checkAndPut(ROW_1, COLUMN_1, QUALIFIER_1, VALUE_2,
|
assertFalse(remoteTable.checkAndMutate(ROW_1, COLUMN_1).qualifier(QUALIFIER_1)
|
||||||
put));
|
.ifEquals(VALUE_2).thenPut(put));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.client;
|
package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.CompareOperator;
|
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.TableName;
|
import org.apache.hadoop.hbase.TableName;
|
||||||
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
|
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
|
||||||
|
@ -124,8 +123,8 @@ 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(ROWKEY, FAMILY, Bytes.toBytes("A"),
|
boolean res = table.checkAndMutate(ROWKEY, FAMILY).qualifier(Bytes.toBytes("A"))
|
||||||
CompareOperator.EQUAL, Bytes.toBytes("a"), rm);
|
.ifEquals(Bytes.toBytes("a")).thenMutate(rm);
|
||||||
assertTrue(res);
|
assertTrue(res);
|
||||||
|
|
||||||
// get row back and assert the values
|
// get row back and assert the values
|
||||||
|
@ -134,8 +133,41 @@ public class TestCheckAndMutate {
|
||||||
//Test that we get a region level exception
|
//Test that we get a region level exception
|
||||||
try {
|
try {
|
||||||
rm = getBogusRowMutations();
|
rm = getBogusRowMutations();
|
||||||
table.checkAndMutate(ROWKEY, FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,
|
table.checkAndMutate(ROWKEY, FAMILY).qualifier(Bytes.toBytes("A"))
|
||||||
Bytes.toBytes("a"), rm);
|
.ifEquals(Bytes.toBytes("a")).thenMutate(rm);
|
||||||
|
fail("Expected NoSuchColumnFamilyException");
|
||||||
|
} catch (RetriesExhaustedWithDetailsException e) {
|
||||||
|
try {
|
||||||
|
throw e.getCause(0);
|
||||||
|
} catch (NoSuchColumnFamilyException e1) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCheckAndMutateWithBuilder() throws Throwable {
|
||||||
|
try (Table table = createTable()) {
|
||||||
|
// put one row
|
||||||
|
putOneRow(table);
|
||||||
|
// get row back and assert the values
|
||||||
|
getOneRowAndAssertAllExist(table);
|
||||||
|
|
||||||
|
// put the same row again with C column deleted
|
||||||
|
RowMutations rm = makeRowMutationsWithColumnCDeleted();
|
||||||
|
boolean res = table.checkAndMutate(ROWKEY, FAMILY).qualifier(Bytes.toBytes("A"))
|
||||||
|
.ifEquals(Bytes.toBytes("a")).thenMutate(rm);
|
||||||
|
assertTrue(res);
|
||||||
|
|
||||||
|
// get row back and assert the values
|
||||||
|
getOneRowAndAssertAllButCExist(table);
|
||||||
|
|
||||||
|
//Test that we get a region level exception
|
||||||
|
try {
|
||||||
|
rm = getBogusRowMutations();
|
||||||
|
table.checkAndMutate(ROWKEY, FAMILY).qualifier(Bytes.toBytes("A"))
|
||||||
|
.ifEquals(Bytes.toBytes("a")).thenMutate(rm);
|
||||||
fail("Expected NoSuchColumnFamilyException");
|
fail("Expected NoSuchColumnFamilyException");
|
||||||
} catch (RetriesExhaustedWithDetailsException e) {
|
} catch (RetriesExhaustedWithDetailsException e) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1296,19 +1296,19 @@ public class TestFromClientSide {
|
||||||
table.append(append);
|
table.append(append);
|
||||||
getTestNull(table, ROW, FAMILY, VALUE);
|
getTestNull(table, ROW, FAMILY, VALUE);
|
||||||
|
|
||||||
// Work for checkAndMutate, checkAndPut, checkAndDelete
|
// Work for checkAndMutate using thenPut, thenMutate and thenDelete
|
||||||
put = new Put(ROW);
|
put = new Put(ROW);
|
||||||
put.addColumn(FAMILY, null, Bytes.toBytes("checkAndPut"));
|
put.addColumn(FAMILY, null, Bytes.toBytes("checkAndPut"));
|
||||||
table.put(put);
|
table.put(put);
|
||||||
table.checkAndPut(ROW, FAMILY, null, VALUE, put);
|
table.checkAndMutate(ROW, FAMILY).ifEquals(VALUE).thenPut(put);
|
||||||
|
|
||||||
RowMutations mutate = new RowMutations(ROW);
|
RowMutations mutate = new RowMutations(ROW);
|
||||||
mutate.add(new Put(ROW).addColumn(FAMILY, null, Bytes.toBytes("checkAndMutate")));
|
mutate.add(new Put(ROW).addColumn(FAMILY, null, Bytes.toBytes("checkAndMutate")));
|
||||||
table.checkAndMutate(ROW, FAMILY, null, CompareOperator.EQUAL, Bytes.toBytes("checkAndPut"), mutate);
|
table.checkAndMutate(ROW, FAMILY).ifEquals(Bytes.toBytes("checkAndPut")).thenMutate(mutate);
|
||||||
|
|
||||||
delete = new Delete(ROW);
|
delete = new Delete(ROW);
|
||||||
delete.addColumns(FAMILY, null);
|
delete.addColumns(FAMILY, null);
|
||||||
table.checkAndDelete(ROW, FAMILY, null, Bytes.toBytes("checkAndMutate"), delete);
|
table.checkAndMutate(ROW, FAMILY).ifEquals(Bytes.toBytes("checkAndMutate")).thenDelete(delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4790,22 +4790,23 @@ public class TestFromClientSide {
|
||||||
put1.addColumn(FAMILY, QUALIFIER, VALUE);
|
put1.addColumn(FAMILY, QUALIFIER, VALUE);
|
||||||
|
|
||||||
// row doesn't exist, so using non-null value should be considered "not match".
|
// row doesn't exist, so using non-null value should be considered "not match".
|
||||||
boolean ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, VALUE, put1);
|
boolean ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifEquals(VALUE).thenPut(put1);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
|
|
||||||
// row doesn't exist, so using "null" to check for existence should be considered "match".
|
// row doesn't exist, so using "ifNotExists" should be considered "match".
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, null, put1);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifNotExists().thenPut(put1);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
|
|
||||||
// row now exists, so using "null" to check for existence should be considered "not match".
|
// row now exists, so using "ifNotExists" should be considered "not match".
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, null, put1);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifNotExists().thenPut(put1);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
|
|
||||||
Put put2 = new Put(ROW);
|
Put put2 = new Put(ROW);
|
||||||
put2.addColumn(FAMILY, QUALIFIER, value2);
|
put2.addColumn(FAMILY, QUALIFIER, value2);
|
||||||
|
|
||||||
// row now exists, use the matching value to check
|
// row now exists, use the matching value to check
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, VALUE, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifEquals(VALUE).thenPut(put2);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
|
|
||||||
Put put3 = new Put(anotherrow);
|
Put put3 = new Put(anotherrow);
|
||||||
|
@ -4813,7 +4814,7 @@ public class TestFromClientSide {
|
||||||
|
|
||||||
// try to do CheckAndPut on different rows
|
// try to do CheckAndPut on different rows
|
||||||
try {
|
try {
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, value2, put3);
|
table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifEquals(value2).thenPut(put3);
|
||||||
fail("trying to check and modify different rows should have failed.");
|
fail("trying to check and modify different rows should have failed.");
|
||||||
} catch(Exception e) {}
|
} catch(Exception e) {}
|
||||||
|
|
||||||
|
@ -4834,53 +4835,71 @@ public class TestFromClientSide {
|
||||||
Put put3 = new Put(ROW);
|
Put put3 = new Put(ROW);
|
||||||
put3.addColumn(FAMILY, QUALIFIER, value3);
|
put3.addColumn(FAMILY, QUALIFIER, value3);
|
||||||
|
|
||||||
// row doesn't exist, so using "null" to check for existence should be considered "match".
|
// row doesn't exist, so using "ifNotExists" should be considered "match".
|
||||||
boolean ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, null, put2);
|
boolean ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER).ifNotExists().thenPut(put2);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
|
|
||||||
// cell = "bbbb", using "aaaa" to compare only LESS/LESS_OR_EQUAL/NOT_EQUAL
|
// cell = "bbbb", using "aaaa" to compare only LESS/LESS_OR_EQUAL/NOT_EQUAL
|
||||||
// turns out "match"
|
// turns out "match"
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER, value1, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER, value1).thenPut(put2);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.EQUAL, value1, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.EQUAL, value1).thenPut(put2);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER_OR_EQUAL, value1, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER_OR_EQUAL, value1).thenPut(put2);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.LESS, value1, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS, value1).thenPut(put2);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.LESS_OR_EQUAL, value1, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS_OR_EQUAL, value1).thenPut(put2);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.NOT_EQUAL, value1, put3);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.NOT_EQUAL, value1).thenPut(put3);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
|
|
||||||
// cell = "cccc", using "dddd" to compare only LARGER/LARGER_OR_EQUAL/NOT_EQUAL
|
// cell = "cccc", using "dddd" to compare only LARGER/LARGER_OR_EQUAL/NOT_EQUAL
|
||||||
// turns out "match"
|
// turns out "match"
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.LESS, value4, put3);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS, value4).thenPut(put3);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.LESS_OR_EQUAL, value4, put3);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS_OR_EQUAL, value4).thenPut(put3);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.EQUAL, value4, put3);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.EQUAL, value4).thenPut(put3);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER, value4, put3);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER, value4).thenPut(put3);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER_OR_EQUAL, value4, put3);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER_OR_EQUAL, value4).thenPut(put3);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.NOT_EQUAL, value4, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.NOT_EQUAL, value4).thenPut(put2);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
|
|
||||||
// cell = "bbbb", using "bbbb" to compare only GREATER_OR_EQUAL/LESS_OR_EQUAL/EQUAL
|
// cell = "bbbb", using "bbbb" to compare only GREATER_OR_EQUAL/LESS_OR_EQUAL/EQUAL
|
||||||
// turns out "match"
|
// turns out "match"
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER, value2, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER, value2).thenPut(put2);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.NOT_EQUAL, value2, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.NOT_EQUAL, value2).thenPut(put2);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.LESS, value2, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS, value2).thenPut(put2);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER_OR_EQUAL, value2, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER_OR_EQUAL, value2).thenPut(put2);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.LESS_OR_EQUAL, value2, put2);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS_OR_EQUAL, value2).thenPut(put2);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
ok = table.checkAndPut(ROW, FAMILY, QUALIFIER, CompareOperator.EQUAL, value2, put3);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.EQUAL, value2).thenPut(put3);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4898,7 +4917,8 @@ public class TestFromClientSide {
|
||||||
Delete delete = new Delete(ROW);
|
Delete delete = new Delete(ROW);
|
||||||
delete.addColumns(FAMILY, QUALIFIER);
|
delete.addColumns(FAMILY, QUALIFIER);
|
||||||
|
|
||||||
boolean ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, value1, delete);
|
boolean ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifEquals(value1).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4924,55 +4944,73 @@ public class TestFromClientSide {
|
||||||
|
|
||||||
// cell = "bbbb", using "aaaa" to compare only LESS/LESS_OR_EQUAL/NOT_EQUAL
|
// cell = "bbbb", using "aaaa" to compare only LESS/LESS_OR_EQUAL/NOT_EQUAL
|
||||||
// turns out "match"
|
// turns out "match"
|
||||||
boolean ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER, value1, delete);
|
boolean ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER, value1).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.EQUAL, value1, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.EQUAL, value1).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER_OR_EQUAL, value1, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER_OR_EQUAL, value1).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.LESS, value1, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS, value1).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
table.put(put2);
|
table.put(put2);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.LESS_OR_EQUAL, value1, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS_OR_EQUAL, value1).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
table.put(put2);
|
table.put(put2);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.NOT_EQUAL, value1, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.NOT_EQUAL, value1).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
|
|
||||||
// cell = "cccc", using "dddd" to compare only LARGER/LARGER_OR_EQUAL/NOT_EQUAL
|
// cell = "cccc", using "dddd" to compare only LARGER/LARGER_OR_EQUAL/NOT_EQUAL
|
||||||
// turns out "match"
|
// turns out "match"
|
||||||
table.put(put3);
|
table.put(put3);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.LESS, value4, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS, value4).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.LESS_OR_EQUAL, value4, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS_OR_EQUAL, value4).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.EQUAL, value4, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.EQUAL, value4).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER, value4, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER, value4).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
table.put(put3);
|
table.put(put3);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER_OR_EQUAL, value4, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER_OR_EQUAL, value4).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
table.put(put3);
|
table.put(put3);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.NOT_EQUAL, value4, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.NOT_EQUAL, value4).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
|
|
||||||
// cell = "bbbb", using "bbbb" to compare only GREATER_OR_EQUAL/LESS_OR_EQUAL/EQUAL
|
// cell = "bbbb", using "bbbb" to compare only GREATER_OR_EQUAL/LESS_OR_EQUAL/EQUAL
|
||||||
// turns out "match"
|
// turns out "match"
|
||||||
table.put(put2);
|
table.put(put2);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER, value2, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER, value2).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.NOT_EQUAL, value2, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.NOT_EQUAL, value2).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.LESS, value2, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS, value2).thenDelete(delete);
|
||||||
assertEquals(ok, false);
|
assertEquals(ok, false);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.GREATER_OR_EQUAL, value2, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.GREATER_OR_EQUAL, value2).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
table.put(put2);
|
table.put(put2);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.LESS_OR_EQUAL, value2, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.LESS_OR_EQUAL, value2).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
table.put(put2);
|
table.put(put2);
|
||||||
ok = table.checkAndDelete(ROW, FAMILY, QUALIFIER, CompareOperator.EQUAL, value2, delete);
|
ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER)
|
||||||
|
.ifMatches(CompareOperator.EQUAL, value2).thenDelete(delete);
|
||||||
assertEquals(ok, true);
|
assertEquals(ok, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ public class TestRegionObserverInterface {
|
||||||
verifyMethodResult(SimpleRegionObserver.class,
|
verifyMethodResult(SimpleRegionObserver.class,
|
||||||
new String[] { "hadPreCheckAndPut", "hadPreCheckAndPutAfterRowLock", "hadPostCheckAndPut" },
|
new String[] { "hadPreCheckAndPut", "hadPreCheckAndPutAfterRowLock", "hadPostCheckAndPut" },
|
||||||
tableName, new Boolean[] { false, false, false });
|
tableName, new Boolean[] { false, false, false });
|
||||||
table.checkAndPut(Bytes.toBytes(0), A, A, A, p);
|
table.checkAndMutate(Bytes.toBytes(0), A).qualifier(A).ifEquals(A).thenPut(p);
|
||||||
verifyMethodResult(SimpleRegionObserver.class,
|
verifyMethodResult(SimpleRegionObserver.class,
|
||||||
new String[] { "hadPreCheckAndPut", "hadPreCheckAndPutAfterRowLock", "hadPostCheckAndPut" },
|
new String[] { "hadPreCheckAndPut", "hadPreCheckAndPutAfterRowLock", "hadPostCheckAndPut" },
|
||||||
tableName, new Boolean[] { true, true, true });
|
tableName, new Boolean[] { true, true, true });
|
||||||
|
@ -279,7 +279,7 @@ public class TestRegionObserverInterface {
|
||||||
SimpleRegionObserver.class, new String[] { "hadPreCheckAndDelete",
|
SimpleRegionObserver.class, new String[] { "hadPreCheckAndDelete",
|
||||||
"hadPreCheckAndDeleteAfterRowLock", "hadPostCheckAndDelete" },
|
"hadPreCheckAndDeleteAfterRowLock", "hadPostCheckAndDelete" },
|
||||||
tableName, new Boolean[] { false, false, false });
|
tableName, new Boolean[] { false, false, false });
|
||||||
table.checkAndDelete(Bytes.toBytes(0), A, A, A, d);
|
table.checkAndMutate(Bytes.toBytes(0), A).qualifier(A).ifEquals(A).thenDelete(d);
|
||||||
verifyMethodResult(
|
verifyMethodResult(
|
||||||
SimpleRegionObserver.class, new String[] { "hadPreCheckAndDelete",
|
SimpleRegionObserver.class, new String[] { "hadPreCheckAndDelete",
|
||||||
"hadPreCheckAndDeleteAfterRowLock", "hadPostCheckAndDelete" },
|
"hadPreCheckAndDeleteAfterRowLock", "hadPostCheckAndDelete" },
|
||||||
|
|
|
@ -214,6 +214,7 @@ public class RegionAsTable implements Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put)
|
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -228,6 +229,7 @@ public class RegionAsTable implements Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier,
|
||||||
CompareOperator compareOp, byte[] value, Put put)
|
CompareOperator compareOp, byte[] value, Put put)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -260,12 +262,18 @@ public class RegionAsTable implements Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier,
|
||||||
CompareOperator compareOp, byte[] value, Delete delete)
|
CompareOperator compareOp, byte[] value, Delete delete)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mutateRow(RowMutations rm) throws IOException {
|
public void mutateRow(RowMutations rm) throws IOException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -344,10 +352,9 @@ public class RegionAsTable implements Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
|
||||||
CompareOperator compareOp,
|
CompareOperator compareOp, byte[] value, RowMutations mutation) throws IOException {
|
||||||
byte[] value, RowMutations mutation)
|
|
||||||
throws IOException {
|
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -382,11 +382,11 @@ public class TestRegionServerMetrics {
|
||||||
|
|
||||||
Put pTwo = new Put(row);
|
Put pTwo = new Put(row);
|
||||||
pTwo.addColumn(cf, qualifier, valTwo);
|
pTwo.addColumn(cf, qualifier, valTwo);
|
||||||
table.checkAndPut(row, cf, qualifier, valOne, pTwo);
|
table.checkAndMutate(row, cf).qualifier(qualifier).ifEquals(valOne).thenPut(pTwo);
|
||||||
|
|
||||||
Put pThree = new Put(row);
|
Put pThree = new Put(row);
|
||||||
pThree.addColumn(cf, qualifier, valThree);
|
pThree.addColumn(cf, qualifier, valThree);
|
||||||
table.checkAndPut(row, cf, qualifier, valOne, pThree);
|
table.checkAndMutate(row, cf).qualifier(qualifier).ifEquals(valOne).thenPut(pThree);
|
||||||
|
|
||||||
metricsRegionServer.getRegionServerWrapper().forceRecompute();
|
metricsRegionServer.getRegionServerWrapper().forceRecompute();
|
||||||
assertCounter("checkMutateFailedCount", 1);
|
assertCounter("checkMutateFailedCount", 1);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.hbase.Cell;
|
import org.apache.hadoop.hbase.Cell;
|
||||||
import org.apache.hadoop.hbase.ClusterStatus.Option;
|
import org.apache.hadoop.hbase.ClusterStatus.Option;
|
||||||
import org.apache.hadoop.hbase.CompareOperator;
|
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.RegionLoad;
|
import org.apache.hadoop.hbase.RegionLoad;
|
||||||
import org.apache.hadoop.hbase.ServerLoad;
|
import org.apache.hadoop.hbase.ServerLoad;
|
||||||
|
@ -301,7 +300,7 @@ public class TestRegionServerReadRequestMetrics {
|
||||||
put = new Put(ROW1);
|
put = new Put(ROW1);
|
||||||
put.addColumn(CF1, COL2, VAL2);
|
put.addColumn(CF1, COL2, VAL2);
|
||||||
boolean checkAndPut =
|
boolean checkAndPut =
|
||||||
table.checkAndPut(ROW1, CF1, COL2, CompareOperator.EQUAL, VAL2, put);
|
table.checkAndMutate(ROW1, CF1).qualifier(COL2).ifEquals(VAL2).thenPut(put);
|
||||||
resultCount = checkAndPut ? 1 : 0;
|
resultCount = checkAndPut ? 1 : 0;
|
||||||
testReadRequests(resultCount, 1, 0);
|
testReadRequests(resultCount, 1, 0);
|
||||||
|
|
||||||
|
@ -318,7 +317,7 @@ public class TestRegionServerReadRequestMetrics {
|
||||||
RowMutations rm = new RowMutations(ROW1);
|
RowMutations rm = new RowMutations(ROW1);
|
||||||
rm.add(put);
|
rm.add(put);
|
||||||
boolean checkAndMutate =
|
boolean checkAndMutate =
|
||||||
table.checkAndMutate(ROW1, CF1, COL1, CompareOperator.EQUAL, VAL1, rm);
|
table.checkAndMutate(ROW1, CF1).qualifier(COL1).ifEquals(VAL1).thenMutate(rm);
|
||||||
resultCount = checkAndMutate ? 1 : 0;
|
resultCount = checkAndMutate ? 1 : 0;
|
||||||
testReadRequests(resultCount, 1, 0);
|
testReadRequests(resultCount, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -934,8 +934,8 @@ public class TestAccessController extends SecureTestUtil {
|
||||||
d.addFamily(TEST_FAMILY);
|
d.addFamily(TEST_FAMILY);
|
||||||
try(Connection conn = ConnectionFactory.createConnection(conf);
|
try(Connection conn = ConnectionFactory.createConnection(conf);
|
||||||
Table t = conn.getTable(TEST_TABLE);) {
|
Table t = conn.getTable(TEST_TABLE);) {
|
||||||
t.checkAndDelete(TEST_ROW, TEST_FAMILY, TEST_QUALIFIER,
|
t.checkAndMutate(TEST_ROW, TEST_FAMILY).qualifier(TEST_QUALIFIER)
|
||||||
Bytes.toBytes("test_value"), d);
|
.ifEquals(Bytes.toBytes("test_value")).thenDelete(d);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -949,9 +949,9 @@ public class TestAccessController extends SecureTestUtil {
|
||||||
Put p = new Put(TEST_ROW);
|
Put p = new Put(TEST_ROW);
|
||||||
p.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(1));
|
p.addColumn(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(1));
|
||||||
try(Connection conn = ConnectionFactory.createConnection(conf);
|
try(Connection conn = ConnectionFactory.createConnection(conf);
|
||||||
Table t = conn.getTable(TEST_TABLE);) {
|
Table t = conn.getTable(TEST_TABLE)) {
|
||||||
t.checkAndPut(TEST_ROW, TEST_FAMILY, TEST_QUALIFIER,
|
t.checkAndMutate(TEST_ROW, TEST_FAMILY).qualifier(TEST_QUALIFIER)
|
||||||
Bytes.toBytes("test_value"), p);
|
.ifEquals(Bytes.toBytes("test_value")).thenPut(p);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -905,7 +905,8 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
||||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||||
Delete d = new Delete(TEST_ROW1);
|
Delete d = new Delete(TEST_ROW1);
|
||||||
d.addColumns(TEST_FAMILY1, TEST_Q1, 120);
|
d.addColumns(TEST_FAMILY1, TEST_Q1, 120);
|
||||||
t.checkAndDelete(TEST_ROW1, TEST_FAMILY1, TEST_Q1, ZERO, d);
|
t.checkAndMutate(TEST_ROW1, TEST_FAMILY1).qualifier(TEST_Q1)
|
||||||
|
.ifEquals(ZERO).thenDelete(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -941,7 +942,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
||||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||||
Delete d = new Delete(row);
|
Delete d = new Delete(row);
|
||||||
d.addColumn(TEST_FAMILY1, q1, 120);
|
d.addColumn(TEST_FAMILY1, q1, 120);
|
||||||
t.checkAndDelete(row, TEST_FAMILY1, q1, value, d);
|
t.checkAndMutate(row, TEST_FAMILY1).qualifier(q1).ifEquals(value).thenDelete(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -958,7 +959,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
|
||||||
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
|
||||||
Delete d = new Delete(row);
|
Delete d = new Delete(row);
|
||||||
d.addColumns(TEST_FAMILY1, TEST_Q1);
|
d.addColumns(TEST_FAMILY1, TEST_Q1);
|
||||||
t.checkAndDelete(row, TEST_FAMILY1, TEST_Q1, value, d);
|
t.checkAndMutate(row, TEST_FAMILY1).qualifier(TEST_Q1).ifEquals(value).thenDelete(d);
|
||||||
fail(user.getShortName() + " should not be allowed to do checkAndDelete");
|
fail(user.getShortName() + " should not be allowed to do checkAndDelete");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -569,12 +569,12 @@ public abstract class TestVisibilityLabels {
|
||||||
Put put = new Put(row1);
|
Put put = new Put(row1);
|
||||||
put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, value);
|
put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, value);
|
||||||
put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL));
|
put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL));
|
||||||
table.checkAndPut(row1, fam, qual, null, put);
|
table.checkAndMutate(row1, fam).qualifier(qual).ifNotExists().thenPut(put);
|
||||||
byte[] row2 = Bytes.toBytes("row2");
|
byte[] row2 = Bytes.toBytes("row2");
|
||||||
put = new Put(row2);
|
put = new Put(row2);
|
||||||
put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, value);
|
put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, value);
|
||||||
put.setCellVisibility(new CellVisibility(SECRET));
|
put.setCellVisibility(new CellVisibility(SECRET));
|
||||||
table.checkAndPut(row2, fam, qual, null, put);
|
table.checkAndMutate(row2, fam).qualifier(qual).ifNotExists().thenPut(put);
|
||||||
|
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
scan.setAuthorizations(new Authorizations(SECRET));
|
scan.setAuthorizations(new Authorizations(SECRET));
|
||||||
|
|
|
@ -287,9 +287,9 @@ public class MultiThreadedUpdater extends MultiThreadedWriterBase {
|
||||||
} else if (m instanceof Append) {
|
} else if (m instanceof Append) {
|
||||||
table.append((Append)m);
|
table.append((Append)m);
|
||||||
} else if (m instanceof Put) {
|
} else if (m instanceof Put) {
|
||||||
table.checkAndPut(row, cf, q, v, (Put)m);
|
table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put)m);
|
||||||
} else if (m instanceof Delete) {
|
} else if (m instanceof Delete) {
|
||||||
table.checkAndDelete(row, cf, q, v, (Delete)m);
|
table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete)m);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"unsupported mutation " + m.getClass().getSimpleName());
|
"unsupported mutation " + m.getClass().getSimpleName());
|
||||||
|
@ -340,9 +340,9 @@ public class MultiThreadedUpdater extends MultiThreadedWriterBase {
|
||||||
} else if (m instanceof Append) {
|
} else if (m instanceof Append) {
|
||||||
table.append((Append)m);
|
table.append((Append)m);
|
||||||
} else if (m instanceof Put) {
|
} else if (m instanceof Put) {
|
||||||
table.checkAndPut(row, cf, q, v, (Put)m);
|
table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put)m);
|
||||||
} else if (m instanceof Delete) {
|
} else if (m instanceof Delete) {
|
||||||
table.checkAndDelete(row, cf, q, v, (Delete)m);
|
table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete)m);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"unsupported mutation " + m.getClass().getSimpleName());
|
"unsupported mutation " + m.getClass().getSimpleName());
|
||||||
|
|
|
@ -233,9 +233,9 @@ public class MultiThreadedUpdaterWithACL extends MultiThreadedUpdater {
|
||||||
} else if (m instanceof Append) {
|
} else if (m instanceof Append) {
|
||||||
table.append((Append) m);
|
table.append((Append) m);
|
||||||
} else if (m instanceof Put) {
|
} else if (m instanceof Put) {
|
||||||
table.checkAndPut(row, cf, q, v, (Put) m);
|
table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenPut((Put) m);
|
||||||
} else if (m instanceof Delete) {
|
} else if (m instanceof Delete) {
|
||||||
table.checkAndDelete(row, cf, q, v, (Delete) m);
|
table.checkAndMutate(row, cf).qualifier(q).ifEquals(v).thenDelete((Delete) m);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("unsupported mutation "
|
throw new IllegalArgumentException("unsupported mutation "
|
||||||
+ m.getClass().getSimpleName());
|
+ m.getClass().getSimpleName());
|
||||||
|
|
|
@ -1891,8 +1891,13 @@ public class ThriftServerRunner implements Runnable {
|
||||||
try {
|
try {
|
||||||
table = getTable(tableName);
|
table = getTable(tableName);
|
||||||
byte[][] famAndQf = CellUtil.parseColumn(getBytes(column));
|
byte[][] famAndQf = CellUtil.parseColumn(getBytes(column));
|
||||||
return table.checkAndPut(getBytes(row), famAndQf[0], famAndQf[1],
|
Table.CheckAndMutateBuilder mutateBuilder =
|
||||||
value != null ? getBytes(value) : HConstants.EMPTY_BYTE_ARRAY, put);
|
table.checkAndMutate(getBytes(row), famAndQf[0]).qualifier(famAndQf[1]);
|
||||||
|
if (value != null) {
|
||||||
|
return mutateBuilder.ifEquals(getBytes(value)).thenPut(put);
|
||||||
|
} else {
|
||||||
|
return mutateBuilder.ifNotExists().thenPut(put);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warn(e.getMessage(), e);
|
LOG.warn(e.getMessage(), e);
|
||||||
throw getIOError(e);
|
throw getIOError(e);
|
||||||
|
|
|
@ -317,9 +317,13 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
||||||
checkReadOnlyMode();
|
checkReadOnlyMode();
|
||||||
Table htable = getTable(table);
|
Table htable = getTable(table);
|
||||||
try {
|
try {
|
||||||
return htable.checkAndPut(byteBufferToByteArray(row), byteBufferToByteArray(family),
|
Table.CheckAndMutateBuilder builder = htable.checkAndMutate(byteBufferToByteArray(row),
|
||||||
byteBufferToByteArray(qualifier), (value == null) ? null : byteBufferToByteArray(value),
|
byteBufferToByteArray(family)).qualifier(byteBufferToByteArray(qualifier));
|
||||||
putFromThrift(put));
|
if (value == null) {
|
||||||
|
return builder.ifNotExists().thenPut(putFromThrift(put));
|
||||||
|
} else {
|
||||||
|
return builder.ifEquals(byteBufferToByteArray(value)).thenPut(putFromThrift(put));
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw getTIOError(e);
|
throw getTIOError(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -374,9 +378,10 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
||||||
throws TIOError, TException {
|
throws TIOError, TException {
|
||||||
checkReadOnlyMode();
|
checkReadOnlyMode();
|
||||||
try (final Table htable = getTable(table)) {
|
try (final Table htable = getTable(table)) {
|
||||||
return htable.checkAndMutate(byteBufferToByteArray(row), byteBufferToByteArray(family),
|
return htable.checkAndMutate(byteBufferToByteArray(row), byteBufferToByteArray(family))
|
||||||
byteBufferToByteArray(qualifier), compareOpFromThrift(compareOp),
|
.qualifier(byteBufferToByteArray(qualifier))
|
||||||
byteBufferToByteArray(value), rowMutationsFromThrift(rowMutations));
|
.ifMatches(compareOpFromThrift(compareOp), byteBufferToByteArray(value))
|
||||||
|
.thenMutate(rowMutationsFromThrift(rowMutations));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw getTIOError(e);
|
throw getTIOError(e);
|
||||||
}
|
}
|
||||||
|
@ -388,13 +393,14 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
||||||
checkReadOnlyMode();
|
checkReadOnlyMode();
|
||||||
Table htable = getTable(table);
|
Table htable = getTable(table);
|
||||||
try {
|
try {
|
||||||
|
Table.CheckAndMutateBuilder mutateBuilder =
|
||||||
|
htable.checkAndMutate(byteBufferToByteArray(row), byteBufferToByteArray(family))
|
||||||
|
.qualifier(byteBufferToByteArray(qualifier));
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family),
|
return mutateBuilder.ifNotExists().thenDelete(deleteFromThrift(deleteSingle));
|
||||||
byteBufferToByteArray(qualifier), null, deleteFromThrift(deleteSingle));
|
|
||||||
} else {
|
} else {
|
||||||
return htable.checkAndDelete(byteBufferToByteArray(row), byteBufferToByteArray(family),
|
return mutateBuilder.ifEquals(byteBufferToByteArray(value))
|
||||||
byteBufferToByteArray(qualifier), byteBufferToByteArray(value),
|
.thenDelete(deleteFromThrift(deleteSingle));
|
||||||
deleteFromThrift(deleteSingle));
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw getTIOError(e);
|
throw getTIOError(e);
|
||||||
|
|
Loading…
Reference in New Issue