HBASE-14800 Expose checkAndMutate via Thrift2 (Josh Elser)

This commit is contained in:
tedyu 2015-12-25 17:41:37 -08:00
parent f53542c47d
commit b8e2e4a1e7
38 changed files with 1947 additions and 37 deletions

View File

@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
* An AlreadyExists exceptions signals that a table with the specified
* name already exists
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class AlreadyExists extends TException implements org.apache.thrift.TBase<AlreadyExists, AlreadyExists._Fields>, java.io.Serializable, Cloneable, Comparable<AlreadyExists> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("AlreadyExists");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* A BatchMutation object is used to apply a number of Mutations to a single row.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class BatchMutation implements org.apache.thrift.TBase<BatchMutation, BatchMutation._Fields>, java.io.Serializable, Cloneable, Comparable<BatchMutation> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("BatchMutation");

View File

@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
* such as the number of versions, compression settings, etc. It is
* used as input when creating a table or adding a column.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class ColumnDescriptor implements org.apache.thrift.TBase<ColumnDescriptor, ColumnDescriptor._Fields>, java.io.Serializable, Cloneable, Comparable<ColumnDescriptor> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ColumnDescriptor");

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class Hbase {
public interface Iface {

View File

@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
* to the Hbase master or an Hbase region server. Also used to return
* more general Hbase error conditions.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class IOError extends TException implements org.apache.thrift.TBase<IOError, IOError._Fields>, java.io.Serializable, Cloneable, Comparable<IOError> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("IOError");

View File

@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
* An IllegalArgument exception indicates an illegal or invalid
* argument was passed into a procedure.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class IllegalArgument extends TException implements org.apache.thrift.TBase<IllegalArgument, IllegalArgument._Fields>, java.io.Serializable, Cloneable, Comparable<IllegalArgument> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("IllegalArgument");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* A Mutation object is used to either update or delete a column-value.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class Mutation implements org.apache.thrift.TBase<Mutation, Mutation._Fields>, java.io.Serializable, Cloneable, Comparable<Mutation> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Mutation");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* An Append object is used to specify the parameters for performing the append operation.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TAppend implements org.apache.thrift.TBase<TAppend, TAppend._Fields>, java.io.Serializable, Cloneable, Comparable<TAppend> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TAppend");

View File

@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory;
* the timestamp of a cell to a first-class value, making it easy to take
* note of temporal data. Cell is used all the way from HStore up to HTable.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TCell implements org.apache.thrift.TBase<TCell, TCell._Fields>, java.io.Serializable, Cloneable, Comparable<TCell> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TCell");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* Holds column name and the cell.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TColumn implements org.apache.thrift.TBase<TColumn, TColumn._Fields>, java.io.Serializable, Cloneable, Comparable<TColumn> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TColumn");

View File

@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
* For increments that are not incrementColumnValue
* equivalents.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TIncrement implements org.apache.thrift.TBase<TIncrement, TIncrement._Fields>, java.io.Serializable, Cloneable, Comparable<TIncrement> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TIncrement");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* A TRegionInfo contains information about an HTable region.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TRegionInfo implements org.apache.thrift.TBase<TRegionInfo, TRegionInfo._Fields>, java.io.Serializable, Cloneable, Comparable<TRegionInfo> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TRegionInfo");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* Holds row name and then a map of columns to cells.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TRowResult implements org.apache.thrift.TBase<TRowResult, TRowResult._Fields>, java.io.Serializable, Cloneable, Comparable<TRowResult> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TRowResult");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* A Scan object is used to specify scanner parameters when opening a scanner.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TScan implements org.apache.thrift.TBase<TScan, TScan._Fields>, java.io.Serializable, Cloneable, Comparable<TScan> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TScan");

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.hbase.thrift2;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.appendFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.compareOpFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deleteFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deletesFromThrift;
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.getFromThrift;
@ -55,6 +56,7 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.thrift.ThriftMetrics;
import org.apache.hadoop.hbase.thrift2.generated.TAppend;
import org.apache.hadoop.hbase.thrift2.generated.TCompareOp;
import org.apache.hadoop.hbase.thrift2.generated.TDelete;
import org.apache.hadoop.hbase.thrift2.generated.TGet;
import org.apache.hadoop.hbase.thrift2.generated.THBaseService;
@ -299,6 +301,19 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
}
return Collections.emptyList();
}
@Override
public boolean checkAndMutate(ByteBuffer table, ByteBuffer row, ByteBuffer family,
ByteBuffer qualifier, TCompareOp compareOp, ByteBuffer value, TRowMutations rowMutations)
throws TIOError, TException {
try (final Table htable = getTable(table)) {
return htable.checkAndMutate(byteBufferToByteArray(row), byteBufferToByteArray(family),
byteBufferToByteArray(qualifier), compareOpFromThrift(compareOp),
byteBufferToByteArray(value), rowMutationsFromThrift(rowMutations));
} catch (IOException e) {
throw getTIOError(e);
}
}
@Override
public boolean checkAndDelete(ByteBuffer table, ByteBuffer row, ByteBuffer family,

View File

@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.RowMutations;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.filter.ParseFilter;
import org.apache.hadoop.hbase.security.visibility.Authorizations;
import org.apache.hadoop.hbase.security.visibility.CellVisibility;
@ -50,6 +51,7 @@ import org.apache.hadoop.hbase.thrift2.generated.TAppend;
import org.apache.hadoop.hbase.thrift2.generated.TColumn;
import org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement;
import org.apache.hadoop.hbase.thrift2.generated.TColumnValue;
import org.apache.hadoop.hbase.thrift2.generated.TCompareOp;
import org.apache.hadoop.hbase.thrift2.generated.TDelete;
import org.apache.hadoop.hbase.thrift2.generated.TDeleteType;
import org.apache.hadoop.hbase.thrift2.generated.TDurability;
@ -530,4 +532,17 @@ public class ThriftUtilities {
default: return null;
}
}
public static CompareOp compareOpFromThrift(TCompareOp tCompareOp) {
switch (tCompareOp.getValue()) {
case 0: return CompareOp.LESS;
case 1: return CompareOp.LESS_OR_EQUAL;
case 2: return CompareOp.EQUAL;
case 3: return CompareOp.NOT_EQUAL;
case 4: return CompareOp.GREATER_OR_EQUAL;
case 5: return CompareOp.GREATER;
case 6: return CompareOp.NO_OP;
default: return null;
}
}
}

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TAppend implements org.apache.thrift.TBase<TAppend, TAppend._Fields>, java.io.Serializable, Cloneable, Comparable<TAppend> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TAppend");

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TAuthorization implements org.apache.thrift.TBase<TAuthorization, TAuthorization._Fields>, java.io.Serializable, Cloneable, Comparable<TAuthorization> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TAuthorization");

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TCellVisibility implements org.apache.thrift.TBase<TCellVisibility, TCellVisibility._Fields>, java.io.Serializable, Cloneable, Comparable<TCellVisibility> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TCellVisibility");

View File

@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
* in a HBase table by column family and optionally
* a column qualifier and timestamp
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TColumn implements org.apache.thrift.TBase<TColumn, TColumn._Fields>, java.io.Serializable, Cloneable, Comparable<TColumn> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TColumn");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* Represents a single cell and the amount to increment it by
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TColumnIncrement implements org.apache.thrift.TBase<TColumnIncrement, TColumnIncrement._Fields>, java.io.Serializable, Cloneable, Comparable<TColumnIncrement> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TColumnIncrement");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* Represents a single cell and its value.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TColumnValue implements org.apache.thrift.TBase<TColumnValue, TColumnValue._Fields>, java.io.Serializable, Cloneable, Comparable<TColumnValue> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TColumnValue");

View File

@ -60,7 +60,7 @@ import org.slf4j.LoggerFactory;
* by changing the durability. If you don't provide durability, it defaults to
* column family's default setting for durability.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TDelete implements org.apache.thrift.TBase<TDelete, TDelete._Fields>, java.io.Serializable, Cloneable, Comparable<TDelete> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TDelete");

View File

@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
* If you specify a time range and a timestamp the range is ignored.
* Timestamps on TColumns are ignored.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TGet implements org.apache.thrift.TBase<TGet, TGet._Fields>, java.io.Serializable, Cloneable, Comparable<TGet> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TGet");

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class THRegionInfo implements org.apache.thrift.TBase<THRegionInfo, THRegionInfo._Fields>, java.io.Serializable, Cloneable, Comparable<THRegionInfo> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("THRegionInfo");

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class THRegionLocation implements org.apache.thrift.TBase<THRegionLocation, THRegionLocation._Fields>, java.io.Serializable, Cloneable, Comparable<THRegionLocation> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("THRegionLocation");

View File

@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
* to the HBase master or a HBase region server. Also used to return
* more general HBase error conditions.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TIOError extends TException implements org.apache.thrift.TBase<TIOError, TIOError._Fields>, java.io.Serializable, Cloneable, Comparable<TIOError> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TIOError");

View File

@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
* A TIllegalArgument exception indicates an illegal or invalid
* argument was passed into a procedure.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TIllegalArgument extends TException implements org.apache.thrift.TBase<TIllegalArgument, TIllegalArgument._Fields>, java.io.Serializable, Cloneable, Comparable<TIllegalArgument> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TIllegalArgument");

View File

@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
* by changing the durability. If you don't provide durability, it defaults to
* column family's default setting for durability.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TIncrement implements org.apache.thrift.TBase<TIncrement, TIncrement._Fields>, java.io.Serializable, Cloneable, Comparable<TIncrement> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TIncrement");

View File

@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory;
* by changing the durability. If you don't provide durability, it defaults to
* column family's default setting for durability.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TPut implements org.apache.thrift.TBase<TPut, TPut._Fields>, java.io.Serializable, Cloneable, Comparable<TPut> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TPut");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* if no Result is found, row and columnValues will not be set.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TResult implements org.apache.thrift.TBase<TResult, TResult._Fields>, java.io.Serializable, Cloneable, Comparable<TResult> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TResult");

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
/**
* A TRowMutations object is used to apply a number of Mutations to a single row.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TRowMutations implements org.apache.thrift.TBase<TRowMutations, TRowMutations._Fields>, java.io.Serializable, Cloneable, Comparable<TRowMutations> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TRowMutations");

View File

@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
* Any timestamps in the columns are ignored, use timeRange to select by timestamp.
* Max versions defaults to 1.
*/
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TScan implements org.apache.thrift.TBase<TScan, TScan._Fields>, java.io.Serializable, Cloneable, Comparable<TScan> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TScan");

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TServerName implements org.apache.thrift.TBase<TServerName, TServerName._Fields>, java.io.Serializable, Cloneable, Comparable<TServerName> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TServerName");

View File

@ -34,7 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"})
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-11-17")
@Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2015-12-13")
public class TTimeRange implements org.apache.thrift.TBase<TTimeRange, TTimeRange._Fields>, java.io.Serializable, Cloneable, Comparable<TTimeRange> {
private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TTimeRange");

View File

@ -263,6 +263,21 @@ struct THRegionLocation {
2: required THRegionInfo regionInfo
}
/**
* Thrift wrapper around
* org.apache.hadoop.hbase.filter.CompareFilter$CompareOp.
*/
enum TCompareOp {
LESS = 0,
LESS_OR_EQUAL = 1,
EQUAL = 2,
NOT_EQUAL = 3,
GREATER_OR_EQUAL = 4,
GREATER = 5,
NO_OP = 6
}
//
// Exceptions
//
@ -556,4 +571,34 @@ service THBaseService {
) throws (
1: TIOError io
)
/**
* Atomically checks if a row/family/qualifier value matches the expected
* value. If it does, it mutates the row.
*
* @return true if the row was mutated, false otherwise
*/
bool checkAndMutate(
/** to check in and delete from */
1: required binary table,
/** row to check */
2: required binary row,
/** column family to check */
3: required binary family,
/** column qualifier to check */
4: required binary qualifier,
/** comparison to make on the value */
5: required TCompareOp compareOp,
/** the expected value to be compared against, if not provided the
check is for the non-existence of the column in question */
6: binary value,
/** row mutations to execute if the value matches */
7: required TRowMutations rowMutations
) throws (1: TIOError io)
}

View File

@ -43,6 +43,7 @@ import org.apache.hadoop.hbase.thrift2.generated.TAppend;
import org.apache.hadoop.hbase.thrift2.generated.TColumn;
import org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement;
import org.apache.hadoop.hbase.thrift2.generated.TColumnValue;
import org.apache.hadoop.hbase.thrift2.generated.TCompareOp;
import org.apache.hadoop.hbase.thrift2.generated.TDelete;
import org.apache.hadoop.hbase.thrift2.generated.TDeleteType;
import org.apache.hadoop.hbase.thrift2.generated.TGet;
@ -67,6 +68,7 @@ import org.junit.experimental.categories.Category;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@ -125,12 +127,16 @@ public class TestThriftHBaseServiceHandler {
for (int i = 0; i < columnValuesA.size(); i++) {
TColumnValue a = columnValuesA.get(i);
TColumnValue b = columnValuesB.get(i);
assertArrayEquals(a.getFamily(), b.getFamily());
assertArrayEquals(a.getQualifier(), b.getQualifier());
assertArrayEquals(a.getValue(), b.getValue());
assertTColumnValueEqual(a, b);
}
}
public void assertTColumnValueEqual(TColumnValue a, TColumnValue b) {
assertArrayEquals(a.getFamily(), b.getFamily());
assertArrayEquals(a.getQualifier(), b.getQualifier());
assertArrayEquals(a.getValue(), b.getValue());
}
@BeforeClass
public static void beforeClass() throws Exception {
UTIL.startMiniCluster();
@ -1087,5 +1093,56 @@ public class TestThriftHBaseServiceHandler {
increment = incrementFromThrift(tIncrement);
assertEquals(increment.getDurability(), Durability.FSYNC_WAL);
}
@Test
public void testCheckAndMutate() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
ByteBuffer row = wrap("row".getBytes());
ByteBuffer family = wrap(familyAname);
ByteBuffer qualifier = wrap(qualifierAname);
ByteBuffer value = wrap(valueAname);
// Create a mutation to write to 'B', our "mutate" of "checkAndMutate"
List<TColumnValue> columnValuesB = new ArrayList<TColumnValue>();
TColumnValue columnValueB = new TColumnValue(family, wrap(qualifierBname), wrap(valueBname));
columnValuesB.add(columnValueB);
TPut putB = new TPut(row, columnValuesB);
putB.setColumnValues(columnValuesB);
TRowMutations tRowMutations = new TRowMutations(row,
Arrays.<TMutation> asList(TMutation.put(putB)));
// Empty table when we begin
TResult result = handler.get(table, new TGet(row));
assertEquals(0, result.getColumnValuesSize());
// checkAndMutate -- condition should fail because the value doesn't exist.
assertFalse("Expected condition to not pass",
handler.checkAndMutate(table, row, family, qualifier, TCompareOp.EQUAL, value,
tRowMutations));
List<TColumnValue> columnValuesA = new ArrayList<TColumnValue>();
TColumnValue columnValueA = new TColumnValue(family, qualifier, value);
columnValuesA.add(columnValueA);
// Put an update 'A'
handler.put(table, new TPut(row, columnValuesA));
// Verify that the update is there
result = handler.get(table, new TGet(row));
assertEquals(1, result.getColumnValuesSize());
assertTColumnValueEqual(columnValueA, result.getColumnValues().get(0));
// checkAndMutate -- condition should pass since we added the value
assertTrue("Expected condition to pass",
handler.checkAndMutate(table, row, family, qualifier, TCompareOp.EQUAL, value,
tRowMutations));
result = handler.get(table, new TGet(row));
assertEquals(2, result.getColumnValuesSize());
assertTColumnValueEqual(columnValueA, result.getColumnValues().get(0));
assertTColumnValueEqual(columnValueB, result.getColumnValues().get(1));
}
}