Browse files

Added tests, fixed a couple of issues

  • Loading branch information...
1 parent 5de3fdb commit 1a72d4cee8c1b9c466c566fd2d5f2bd07d6ee03c Daniel Gómez Ferro committed Nov 28, 2012
View
29 src/main/java/com/yahoo/omid/thrift/ThriftServerHandler.java
@@ -1,6 +1,5 @@
package com.yahoo.omid.thrift;
-import static com.yahoo.omid.thrift.ThriftUtilities.deletesFromHBase;
import static com.yahoo.omid.thrift.ThriftUtilities.deletesFromThrift;
import static com.yahoo.omid.thrift.ThriftUtilities.getFromThrift;
import static com.yahoo.omid.thrift.ThriftUtilities.putsFromThrift;
@@ -12,17 +11,14 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
@@ -36,15 +32,13 @@
import com.yahoo.omid.client.TransactionState;
import com.yahoo.omid.client.TransactionalTable;
import com.yahoo.omid.thrift.generated.TCell;
-import com.yahoo.omid.thrift.generated.TColumnValue;
import com.yahoo.omid.thrift.generated.TDelete;
import com.yahoo.omid.thrift.generated.TGet;
import com.yahoo.omid.thrift.generated.TIOError;
import com.yahoo.omid.thrift.generated.TIllegalArgument;
import com.yahoo.omid.thrift.generated.TOmidService;
import com.yahoo.omid.thrift.generated.TPut;
import com.yahoo.omid.thrift.generated.TResult;
-import com.yahoo.omid.thrift.generated.TResultDelete;
import com.yahoo.omid.thrift.generated.TResultExists;
import com.yahoo.omid.thrift.generated.TResultGet;
import com.yahoo.omid.thrift.generated.TResultScanner;
@@ -121,9 +115,11 @@ private ResultScanner getScanner(int id) {
private TransactionState transactionFromThrift(TTransaction transaction) {
List<Cell> cells = new ArrayList<Cell>();
- for (TCell tcell : transaction.getCells()) {
- Cell cell = new Cell(tcell.getTable(), tcell.getRow(), tcell.getFamily(), tcell.getQualifier());
- cells.add(cell);
+ if (transaction.getCells() != null) {
+ for (TCell tcell : transaction.getCells()) {
+ Cell cell = new Cell(tcell.getTable(), tcell.getRow(), tcell.getFamily(), tcell.getQualifier());
+ cells.add(cell);
+ }
}
return transactionManager.createTransactionState(transaction.getId(), cells);
}
@@ -225,18 +221,20 @@ public TTransaction putMultiple(ByteBuffer table, List<TPut> puts, TTransaction
}
@Override
- public TResultDelete deleteMultiple(ByteBuffer table, List<TDelete> deletes, TTransaction transaction) throws TIOError, TException {
- List<Delete> tempDeletes = deletesFromThrift(deletes);
+ public TTransaction deleteMultiple(ByteBuffer table, List<TDelete> deletes, TTransaction transaction) throws TIOError, TException {
TransactionalTable htable = null;
try {
htable = getTable(table.array());
- htable.delete(tempDeletes);
+ TransactionState ts = transactionFromThrift(transaction);
+ for (Delete delete : deletesFromThrift(deletes)) {
+ htable.delete(ts, delete);
+ }
+ return transactionFromOmid(ts);
} catch (IOException e) {
throw getTIOError(e);
} finally {
closeTable(htable);
}
- return new TResultDelete(deletesFromHBase(tempDeletes), transaction);
}
@Override
@@ -245,7 +243,8 @@ public TResultScanner openScanner(ByteBuffer table, TScan scan, TTransaction tra
TransactionalTable htable = null;
try {
htable = getTable(table.array());
- resultScanner = htable.getScanner(scanFromThrift(scan));
+ TransactionState ts = transactionFromThrift(transaction);
+ resultScanner = htable.getScanner(ts, scanFromThrift(scan));
} catch (IOException e) {
closeTable(htable);
throw getTIOError(e);
@@ -291,7 +290,7 @@ public TTransaction startTransaction() throws TIOError, TException {
@Override
public boolean commitTransaction(TTransaction transaction) throws TIOError, TException {
try {
- TransactionState ts = transactionManager.beginTransaction();
+ TransactionState ts = transactionFromThrift(transaction);
transactionManager.tryCommit(ts);
return true;
} catch (CommitUnsuccessfulException e) {
View
170 src/main/java/com/yahoo/omid/thrift/generated/TOmidService.java
@@ -91,7 +91,7 @@
*
* @param transaction the transaction
*/
- public TResultDelete deleteMultiple(ByteBuffer table, List<TDelete> deletes, TTransaction transaction) throws TIOError, org.apache.thrift.TException;
+ public TTransaction deleteMultiple(ByteBuffer table, List<TDelete> deletes, TTransaction transaction) throws TIOError, org.apache.thrift.TException;
/**
* Get a Scanner for the provided TScan object.
@@ -309,7 +309,7 @@ public TTransaction recv_putMultiple() throws TIOError, org.apache.thrift.TExcep
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "putMultiple failed: unknown result");
}
- public TResultDelete deleteMultiple(ByteBuffer table, List<TDelete> deletes, TTransaction transaction) throws TIOError, org.apache.thrift.TException
+ public TTransaction deleteMultiple(ByteBuffer table, List<TDelete> deletes, TTransaction transaction) throws TIOError, org.apache.thrift.TException
{
send_deleteMultiple(table, deletes, transaction);
return recv_deleteMultiple();
@@ -324,7 +324,7 @@ public void send_deleteMultiple(ByteBuffer table, List<TDelete> deletes, TTransa
sendBase("deleteMultiple", args);
}
- public TResultDelete recv_deleteMultiple() throws TIOError, org.apache.thrift.TException
+ public TTransaction recv_deleteMultiple() throws TIOError, org.apache.thrift.TException
{
deleteMultiple_result result = new deleteMultiple_result();
receiveBase(result, "deleteMultiple");
@@ -642,7 +642,7 @@ public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apa
prot.writeMessageEnd();
}
- public TResultDelete getResult() throws TIOError, org.apache.thrift.TException {
+ public TTransaction getResult() throws TIOError, org.apache.thrift.TException {
if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
throw new IllegalStateException("Method call not finished!");
}
@@ -4169,14 +4169,14 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, getMultiple_args st
case 2: // GETS
if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
{
- org.apache.thrift.protocol.TList _list72 = iprot.readListBegin();
- struct.gets = new ArrayList<TGet>(_list72.size);
- for (int _i73 = 0; _i73 < _list72.size; ++_i73)
+ org.apache.thrift.protocol.TList _list64 = iprot.readListBegin();
+ struct.gets = new ArrayList<TGet>(_list64.size);
+ for (int _i65 = 0; _i65 < _list64.size; ++_i65)
{
- TGet _elem74; // required
- _elem74 = new TGet();
- _elem74.read(iprot);
- struct.gets.add(_elem74);
+ TGet _elem66; // required
+ _elem66 = new TGet();
+ _elem66.read(iprot);
+ struct.gets.add(_elem66);
}
iprot.readListEnd();
}
@@ -4218,9 +4218,9 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, getMultiple_args s
oprot.writeFieldBegin(GETS_FIELD_DESC);
{
oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.gets.size()));
- for (TGet _iter75 : struct.gets)
+ for (TGet _iter67 : struct.gets)
{
- _iter75.write(oprot);
+ _iter67.write(oprot);
}
oprot.writeListEnd();
}
@@ -4251,9 +4251,9 @@ public void write(org.apache.thrift.protocol.TProtocol prot, getMultiple_args st
oprot.writeBinary(struct.table);
{
oprot.writeI32(struct.gets.size());
- for (TGet _iter76 : struct.gets)
+ for (TGet _iter68 : struct.gets)
{
- _iter76.write(oprot);
+ _iter68.write(oprot);
}
}
struct.transaction.write(oprot);
@@ -4265,14 +4265,14 @@ public void read(org.apache.thrift.protocol.TProtocol prot, getMultiple_args str
struct.table = iprot.readBinary();
struct.setTableIsSet(true);
{
- org.apache.thrift.protocol.TList _list77 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
- struct.gets = new ArrayList<TGet>(_list77.size);
- for (int _i78 = 0; _i78 < _list77.size; ++_i78)
+ org.apache.thrift.protocol.TList _list69 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
+ struct.gets = new ArrayList<TGet>(_list69.size);
+ for (int _i70 = 0; _i70 < _list69.size; ++_i70)
{
- TGet _elem79; // required
- _elem79 = new TGet();
- _elem79.read(iprot);
- struct.gets.add(_elem79);
+ TGet _elem71; // required
+ _elem71 = new TGet();
+ _elem71.read(iprot);
+ struct.gets.add(_elem71);
}
}
struct.setGetsIsSet(true);
@@ -5267,14 +5267,14 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, putMultiple_args st
case 2: // PUTS
if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
{
- org.apache.thrift.protocol.TList _list80 = iprot.readListBegin();
- struct.puts = new ArrayList<TPut>(_list80.size);
- for (int _i81 = 0; _i81 < _list80.size; ++_i81)
+ org.apache.thrift.protocol.TList _list72 = iprot.readListBegin();
+ struct.puts = new ArrayList<TPut>(_list72.size);
+ for (int _i73 = 0; _i73 < _list72.size; ++_i73)
{
- TPut _elem82; // required
- _elem82 = new TPut();
- _elem82.read(iprot);
- struct.puts.add(_elem82);
+ TPut _elem74; // required
+ _elem74 = new TPut();
+ _elem74.read(iprot);
+ struct.puts.add(_elem74);
}
iprot.readListEnd();
}
@@ -5316,9 +5316,9 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, putMultiple_args s
oprot.writeFieldBegin(PUTS_FIELD_DESC);
{
oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.puts.size()));
- for (TPut _iter83 : struct.puts)
+ for (TPut _iter75 : struct.puts)
{
- _iter83.write(oprot);
+ _iter75.write(oprot);
}
oprot.writeListEnd();
}
@@ -5349,9 +5349,9 @@ public void write(org.apache.thrift.protocol.TProtocol prot, putMultiple_args st
oprot.writeBinary(struct.table);
{
oprot.writeI32(struct.puts.size());
- for (TPut _iter84 : struct.puts)
+ for (TPut _iter76 : struct.puts)
{
- _iter84.write(oprot);
+ _iter76.write(oprot);
}
}
struct.transaction.write(oprot);
@@ -5363,14 +5363,14 @@ public void read(org.apache.thrift.protocol.TProtocol prot, putMultiple_args str
struct.table = iprot.readBinary();
struct.setTableIsSet(true);
{
- org.apache.thrift.protocol.TList _list85 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
- struct.puts = new ArrayList<TPut>(_list85.size);
- for (int _i86 = 0; _i86 < _list85.size; ++_i86)
+ org.apache.thrift.protocol.TList _list77 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
+ struct.puts = new ArrayList<TPut>(_list77.size);
+ for (int _i78 = 0; _i78 < _list77.size; ++_i78)
{
- TPut _elem87; // required
- _elem87 = new TPut();
- _elem87.read(iprot);
- struct.puts.add(_elem87);
+ TPut _elem79; // required
+ _elem79 = new TPut();
+ _elem79.read(iprot);
+ struct.puts.add(_elem79);
}
}
struct.setPutsIsSet(true);
@@ -6365,14 +6365,14 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, deleteMultiple_args
case 2: // DELETES
if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
{
- org.apache.thrift.protocol.TList _list88 = iprot.readListBegin();
- struct.deletes = new ArrayList<TDelete>(_list88.size);
- for (int _i89 = 0; _i89 < _list88.size; ++_i89)
+ org.apache.thrift.protocol.TList _list80 = iprot.readListBegin();
+ struct.deletes = new ArrayList<TDelete>(_list80.size);
+ for (int _i81 = 0; _i81 < _list80.size; ++_i81)
{
- TDelete _elem90; // required
- _elem90 = new TDelete();
- _elem90.read(iprot);
- struct.deletes.add(_elem90);
+ TDelete _elem82; // required
+ _elem82 = new TDelete();
+ _elem82.read(iprot);
+ struct.deletes.add(_elem82);
}
iprot.readListEnd();
}
@@ -6414,9 +6414,9 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, deleteMultiple_arg
oprot.writeFieldBegin(DELETES_FIELD_DESC);
{
oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.deletes.size()));
- for (TDelete _iter91 : struct.deletes)
+ for (TDelete _iter83 : struct.deletes)
{
- _iter91.write(oprot);
+ _iter83.write(oprot);
}
oprot.writeListEnd();
}
@@ -6447,9 +6447,9 @@ public void write(org.apache.thrift.protocol.TProtocol prot, deleteMultiple_args
oprot.writeBinary(struct.table);
{
oprot.writeI32(struct.deletes.size());
- for (TDelete _iter92 : struct.deletes)
+ for (TDelete _iter84 : struct.deletes)
{
- _iter92.write(oprot);
+ _iter84.write(oprot);
}
}
struct.transaction.write(oprot);
@@ -6461,14 +6461,14 @@ public void read(org.apache.thrift.protocol.TProtocol prot, deleteMultiple_args
struct.table = iprot.readBinary();
struct.setTableIsSet(true);
{
- org.apache.thrift.protocol.TList _list93 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
- struct.deletes = new ArrayList<TDelete>(_list93.size);
- for (int _i94 = 0; _i94 < _list93.size; ++_i94)
+ org.apache.thrift.protocol.TList _list85 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
+ struct.deletes = new ArrayList<TDelete>(_list85.size);
+ for (int _i86 = 0; _i86 < _list85.size; ++_i86)
{
- TDelete _elem95; // required
- _elem95 = new TDelete();
- _elem95.read(iprot);
- struct.deletes.add(_elem95);
+ TDelete _elem87; // required
+ _elem87 = new TDelete();
+ _elem87.read(iprot);
+ struct.deletes.add(_elem87);
}
}
struct.setDeletesIsSet(true);
@@ -6492,7 +6492,7 @@ public void read(org.apache.thrift.protocol.TProtocol prot, deleteMultiple_args
schemes.put(TupleScheme.class, new deleteMultiple_resultTupleSchemeFactory());
}
- public TResultDelete success; // required
+ public TTransaction success; // required
public TIOError io; // required
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
@@ -6561,7 +6561,7 @@ public String getFieldName() {
static {
Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT,
- new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TResultDelete.class)));
+ new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TTransaction.class)));
tmpMap.put(_Fields.IO, new org.apache.thrift.meta_data.FieldMetaData("io", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
@@ -6572,7 +6572,7 @@ public deleteMultiple_result() {
}
public deleteMultiple_result(
- TResultDelete success,
+ TTransaction success,
TIOError io)
{
this();
@@ -6585,7 +6585,7 @@ public deleteMultiple_result(
*/
public deleteMultiple_result(deleteMultiple_result other) {
if (other.isSetSuccess()) {
- this.success = new TResultDelete(other.success);
+ this.success = new TTransaction(other.success);
}
if (other.isSetIo()) {
this.io = new TIOError(other.io);
@@ -6602,11 +6602,11 @@ public void clear() {
this.io = null;
}
- public TResultDelete getSuccess() {
+ public TTransaction getSuccess() {
return this.success;
}
- public deleteMultiple_result setSuccess(TResultDelete success) {
+ public deleteMultiple_result setSuccess(TTransaction success) {
this.success = success;
return this;
}
@@ -6656,7 +6656,7 @@ public void setFieldValue(_Fields field, Object value) {
if (value == null) {
unsetSuccess();
} else {
- setSuccess((TResultDelete)value);
+ setSuccess((TTransaction)value);
}
break;
@@ -6844,7 +6844,7 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, deleteMultiple_resu
switch (schemeField.id) {
case 0: // SUCCESS
if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
- struct.success = new TResultDelete();
+ struct.success = new TTransaction();
struct.success.read(iprot);
struct.setSuccessIsSet(true);
} else {
@@ -6923,7 +6923,7 @@ public void read(org.apache.thrift.protocol.TProtocol prot, deleteMultiple_resul
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
- struct.success = new TResultDelete();
+ struct.success = new TTransaction();
struct.success.read(iprot);
struct.setSuccessIsSet(true);
}
@@ -8926,14 +8926,14 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, getScannerRows_resu
case 0: // SUCCESS
if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
{
- org.apache.thrift.protocol.TList _list96 = iprot.readListBegin();
- struct.success = new ArrayList<TResult>(_list96.size);
- for (int _i97 = 0; _i97 < _list96.size; ++_i97)
+ org.apache.thrift.protocol.TList _list88 = iprot.readListBegin();
+ struct.success = new ArrayList<TResult>(_list88.size);
+ for (int _i89 = 0; _i89 < _list88.size; ++_i89)
{
- TResult _elem98; // required
- _elem98 = new TResult();
- _elem98.read(iprot);
- struct.success.add(_elem98);
+ TResult _elem90; // required
+ _elem90 = new TResult();
+ _elem90.read(iprot);
+ struct.success.add(_elem90);
}
iprot.readListEnd();
}
@@ -8979,9 +8979,9 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, getScannerRows_res
oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
{
oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.success.size()));
- for (TResult _iter99 : struct.success)
+ for (TResult _iter91 : struct.success)
{
- _iter99.write(oprot);
+ _iter91.write(oprot);
}
oprot.writeListEnd();
}
@@ -9028,9 +9028,9 @@ public void write(org.apache.thrift.protocol.TProtocol prot, getScannerRows_resu
if (struct.isSetSuccess()) {
{
oprot.writeI32(struct.success.size());
- for (TResult _iter100 : struct.success)
+ for (TResult _iter92 : struct.success)
{
- _iter100.write(oprot);
+ _iter92.write(oprot);
}
}
}
@@ -9048,14 +9048,14 @@ public void read(org.apache.thrift.protocol.TProtocol prot, getScannerRows_resul
BitSet incoming = iprot.readBitSet(3);
if (incoming.get(0)) {
{
- org.apache.thrift.protocol.TList _list101 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
- struct.success = new ArrayList<TResult>(_list101.size);
- for (int _i102 = 0; _i102 < _list101.size; ++_i102)
+ org.apache.thrift.protocol.TList _list93 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
+ struct.success = new ArrayList<TResult>(_list93.size);
+ for (int _i94 = 0; _i94 < _list93.size; ++_i94)
{
- TResult _elem103; // required
- _elem103 = new TResult();
- _elem103.read(iprot);
- struct.success.add(_elem103);
+ TResult _elem95; // required
+ _elem95 = new TResult();
+ _elem95.read(iprot);
+ struct.success.add(_elem95);
}
}
struct.setSuccessIsSet(true);
View
527 src/main/java/com/yahoo/omid/thrift/generated/TResultDelete.java
@@ -1,527 +0,0 @@
-/**
- * Autogenerated by Thrift Compiler (0.8.0)
- *
- * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
- * @generated
- */
-package com.yahoo.omid.thrift.generated;
-
-import org.apache.thrift.scheme.IScheme;
-import org.apache.thrift.scheme.SchemeFactory;
-import org.apache.thrift.scheme.StandardScheme;
-
-import org.apache.thrift.scheme.TupleScheme;
-import org.apache.thrift.protocol.TTupleProtocol;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.EnumMap;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.EnumSet;
-import java.util.Collections;
-import java.util.BitSet;
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TResultDelete implements org.apache.thrift.TBase<TResultDelete, TResultDelete._Fields>, java.io.Serializable, Cloneable {
- private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TResultDelete");
-
- private static final org.apache.thrift.protocol.TField RESULTS_FIELD_DESC = new org.apache.thrift.protocol.TField("results", org.apache.thrift.protocol.TType.LIST, (short)1);
- private static final org.apache.thrift.protocol.TField TRANSACTION_FIELD_DESC = new org.apache.thrift.protocol.TField("transaction", org.apache.thrift.protocol.TType.STRUCT, (short)2);
-
- private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
- static {
- schemes.put(StandardScheme.class, new TResultDeleteStandardSchemeFactory());
- schemes.put(TupleScheme.class, new TResultDeleteTupleSchemeFactory());
- }
-
- public List<TDelete> results; // required
- public TTransaction transaction; // required
-
- /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
- public enum _Fields implements org.apache.thrift.TFieldIdEnum {
- RESULTS((short)1, "results"),
- TRANSACTION((short)2, "transaction");
-
- private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
-
- static {
- for (_Fields field : EnumSet.allOf(_Fields.class)) {
- byName.put(field.getFieldName(), field);
- }
- }
-
- /**
- * Find the _Fields constant that matches fieldId, or null if its not found.
- */
- public static _Fields findByThriftId(int fieldId) {
- switch(fieldId) {
- case 1: // RESULTS
- return RESULTS;
- case 2: // TRANSACTION
- return TRANSACTION;
- default:
- return null;
- }
- }
-
- /**
- * Find the _Fields constant that matches fieldId, throwing an exception
- * if it is not found.
- */
- public static _Fields findByThriftIdOrThrow(int fieldId) {
- _Fields fields = findByThriftId(fieldId);
- if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!");
- return fields;
- }
-
- /**
- * Find the _Fields constant that matches name, or null if its not found.
- */
- public static _Fields findByName(String name) {
- return byName.get(name);
- }
-
- private final short _thriftId;
- private final String _fieldName;
-
- _Fields(short thriftId, String fieldName) {
- _thriftId = thriftId;
- _fieldName = fieldName;
- }
-
- public short getThriftFieldId() {
- return _thriftId;
- }
-
- public String getFieldName() {
- return _fieldName;
- }
- }
-
- // isset id assignments
- public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap;
- static {
- Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class);
- tmpMap.put(_Fields.RESULTS, new org.apache.thrift.meta_data.FieldMetaData("results", org.apache.thrift.TFieldRequirementType.REQUIRED,
- new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST,
- new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TDelete.class))));
- tmpMap.put(_Fields.TRANSACTION, new org.apache.thrift.meta_data.FieldMetaData("transaction", org.apache.thrift.TFieldRequirementType.REQUIRED,
- new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TTransaction.class)));
- metaDataMap = Collections.unmodifiableMap(tmpMap);
- org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TResultDelete.class, metaDataMap);
- }
-
- public TResultDelete() {
- }
-
- public TResultDelete(
- List<TDelete> results,
- TTransaction transaction)
- {
- this();
- this.results = results;
- this.transaction = transaction;
- }
-
- /**
- * Performs a deep copy on <i>other</i>.
- */
- public TResultDelete(TResultDelete other) {
- if (other.isSetResults()) {
- List<TDelete> __this__results = new ArrayList<TDelete>();
- for (TDelete other_element : other.results) {
- __this__results.add(new TDelete(other_element));
- }
- this.results = __this__results;
- }
- if (other.isSetTransaction()) {
- this.transaction = new TTransaction(other.transaction);
- }
- }
-
- public TResultDelete deepCopy() {
- return new TResultDelete(this);
- }
-
- @Override
- public void clear() {
- this.results = null;
- this.transaction = null;
- }
-
- public int getResultsSize() {
- return (this.results == null) ? 0 : this.results.size();
- }
-
- public java.util.Iterator<TDelete> getResultsIterator() {
- return (this.results == null) ? null : this.results.iterator();
- }
-
- public void addToResults(TDelete elem) {
- if (this.results == null) {
- this.results = new ArrayList<TDelete>();
- }
- this.results.add(elem);
- }
-
- public List<TDelete> getResults() {
- return this.results;
- }
-
- public TResultDelete setResults(List<TDelete> results) {
- this.results = results;
- return this;
- }
-
- public void unsetResults() {
- this.results = null;
- }
-
- /** Returns true if field results is set (has been assigned a value) and false otherwise */
- public boolean isSetResults() {
- return this.results != null;
- }
-
- public void setResultsIsSet(boolean value) {
- if (!value) {
- this.results = null;
- }
- }
-
- public TTransaction getTransaction() {
- return this.transaction;
- }
-
- public TResultDelete setTransaction(TTransaction transaction) {
- this.transaction = transaction;
- return this;
- }
-
- public void unsetTransaction() {
- this.transaction = null;
- }
-
- /** Returns true if field transaction is set (has been assigned a value) and false otherwise */
- public boolean isSetTransaction() {
- return this.transaction != null;
- }
-
- public void setTransactionIsSet(boolean value) {
- if (!value) {
- this.transaction = null;
- }
- }
-
- public void setFieldValue(_Fields field, Object value) {
- switch (field) {
- case RESULTS:
- if (value == null) {
- unsetResults();
- } else {
- setResults((List<TDelete>)value);
- }
- break;
-
- case TRANSACTION:
- if (value == null) {
- unsetTransaction();
- } else {
- setTransaction((TTransaction)value);
- }
- break;
-
- }
- }
-
- public Object getFieldValue(_Fields field) {
- switch (field) {
- case RESULTS:
- return getResults();
-
- case TRANSACTION:
- return getTransaction();
-
- }
- throw new IllegalStateException();
- }
-
- /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */
- public boolean isSet(_Fields field) {
- if (field == null) {
- throw new IllegalArgumentException();
- }
-
- switch (field) {
- case RESULTS:
- return isSetResults();
- case TRANSACTION:
- return isSetTransaction();
- }
- throw new IllegalStateException();
- }
-
- @Override
- public boolean equals(Object that) {
- if (that == null)
- return false;
- if (that instanceof TResultDelete)
- return this.equals((TResultDelete)that);
- return false;
- }
-
- public boolean equals(TResultDelete that) {
- if (that == null)
- return false;
-
- boolean this_present_results = true && this.isSetResults();
- boolean that_present_results = true && that.isSetResults();
- if (this_present_results || that_present_results) {
- if (!(this_present_results && that_present_results))
- return false;
- if (!this.results.equals(that.results))
- return false;
- }
-
- boolean this_present_transaction = true && this.isSetTransaction();
- boolean that_present_transaction = true && that.isSetTransaction();
- if (this_present_transaction || that_present_transaction) {
- if (!(this_present_transaction && that_present_transaction))
- return false;
- if (!this.transaction.equals(that.transaction))
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- return 0;
- }
-
- public int compareTo(TResultDelete other) {
- if (!getClass().equals(other.getClass())) {
- return getClass().getName().compareTo(other.getClass().getName());
- }
-
- int lastComparison = 0;
- TResultDelete typedOther = (TResultDelete)other;
-
- lastComparison = Boolean.valueOf(isSetResults()).compareTo(typedOther.isSetResults());
- if (lastComparison != 0) {
- return lastComparison;
- }
- if (isSetResults()) {
- lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.results, typedOther.results);
- if (lastComparison != 0) {
- return lastComparison;
- }
- }
- lastComparison = Boolean.valueOf(isSetTransaction()).compareTo(typedOther.isSetTransaction());
- if (lastComparison != 0) {
- return lastComparison;
- }
- if (isSetTransaction()) {
- lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.transaction, typedOther.transaction);
- if (lastComparison != 0) {
- return lastComparison;
- }
- }
- return 0;
- }
-
- public _Fields fieldForId(int fieldId) {
- return _Fields.findByThriftId(fieldId);
- }
-
- public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
- schemes.get(iprot.getScheme()).getScheme().read(iprot, this);
- }
-
- public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException {
- schemes.get(oprot.getScheme()).getScheme().write(oprot, this);
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("TResultDelete(");
- boolean first = true;
-
- sb.append("results:");
- if (this.results == null) {
- sb.append("null");
- } else {
- sb.append(this.results);
- }
- first = false;
- if (!first) sb.append(", ");
- sb.append("transaction:");
- if (this.transaction == null) {
- sb.append("null");
- } else {
- sb.append(this.transaction);
- }
- first = false;
- sb.append(")");
- return sb.toString();
- }
-
- public void validate() throws org.apache.thrift.TException {
- // check for required fields
- if (results == null) {
- throw new org.apache.thrift.protocol.TProtocolException("Required field 'results' was not present! Struct: " + toString());
- }
- if (transaction == null) {
- throw new org.apache.thrift.protocol.TProtocolException("Required field 'transaction' was not present! Struct: " + toString());
- }
- }
-
- private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
- try {
- write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out)));
- } catch (org.apache.thrift.TException te) {
- throw new java.io.IOException(te);
- }
- }
-
- private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
- try {
- read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in)));
- } catch (org.apache.thrift.TException te) {
- throw new java.io.IOException(te);
- }
- }
-
- private static class TResultDeleteStandardSchemeFactory implements SchemeFactory {
- public TResultDeleteStandardScheme getScheme() {
- return new TResultDeleteStandardScheme();
- }
- }
-
- private static class TResultDeleteStandardScheme extends StandardScheme<TResultDelete> {
-
- public void read(org.apache.thrift.protocol.TProtocol iprot, TResultDelete struct) throws org.apache.thrift.TException {
- org.apache.thrift.protocol.TField schemeField;
- iprot.readStructBegin();
- while (true)
- {
- schemeField = iprot.readFieldBegin();
- if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
- break;
- }
- switch (schemeField.id) {
- case 1: // RESULTS
- if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
- {
- org.apache.thrift.protocol.TList _list64 = iprot.readListBegin();
- struct.results = new ArrayList<TDelete>(_list64.size);
- for (int _i65 = 0; _i65 < _list64.size; ++_i65)
- {
- TDelete _elem66; // required
- _elem66 = new TDelete();
- _elem66.read(iprot);
- struct.results.add(_elem66);
- }
- iprot.readListEnd();
- }
- struct.setResultsIsSet(true);
- } else {
- org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
- }
- break;
- case 2: // TRANSACTION
- if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) {
- struct.transaction = new TTransaction();
- struct.transaction.read(iprot);
- struct.setTransactionIsSet(true);
- } else {
- org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
- }
- break;
- default:
- org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
- }
- iprot.readFieldEnd();
- }
- iprot.readStructEnd();
-
- // check for required fields of primitive type, which can't be checked in the validate method
- struct.validate();
- }
-
- public void write(org.apache.thrift.protocol.TProtocol oprot, TResultDelete struct) throws org.apache.thrift.TException {
- struct.validate();
-
- oprot.writeStructBegin(STRUCT_DESC);
- if (struct.results != null) {
- oprot.writeFieldBegin(RESULTS_FIELD_DESC);
- {
- oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, struct.results.size()));
- for (TDelete _iter67 : struct.results)
- {
- _iter67.write(oprot);
- }
- oprot.writeListEnd();
- }
- oprot.writeFieldEnd();
- }
- if (struct.transaction != null) {
- oprot.writeFieldBegin(TRANSACTION_FIELD_DESC);
- struct.transaction.write(oprot);
- oprot.writeFieldEnd();
- }
- oprot.writeFieldStop();
- oprot.writeStructEnd();
- }
-
- }
-
- private static class TResultDeleteTupleSchemeFactory implements SchemeFactory {
- public TResultDeleteTupleScheme getScheme() {
- return new TResultDeleteTupleScheme();
- }
- }
-
- private static class TResultDeleteTupleScheme extends TupleScheme<TResultDelete> {
-
- @Override
- public void write(org.apache.thrift.protocol.TProtocol prot, TResultDelete struct) throws org.apache.thrift.TException {
- TTupleProtocol oprot = (TTupleProtocol) prot;
- {
- oprot.writeI32(struct.results.size());
- for (TDelete _iter68 : struct.results)
- {
- _iter68.write(oprot);
- }
- }
- struct.transaction.write(oprot);
- }
-
- @Override
- public void read(org.apache.thrift.protocol.TProtocol prot, TResultDelete struct) throws org.apache.thrift.TException {
- TTupleProtocol iprot = (TTupleProtocol) prot;
- {
- org.apache.thrift.protocol.TList _list69 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
- struct.results = new ArrayList<TDelete>(_list69.size);
- for (int _i70 = 0; _i70 < _list69.size; ++_i70)
- {
- TDelete _elem71; // required
- _elem71 = new TDelete();
- _elem71.read(iprot);
- struct.results.add(_elem71);
- }
- }
- struct.setResultsIsSet(true);
- struct.transaction = new TTransaction();
- struct.transaction.read(iprot);
- struct.setTransactionIsSet(true);
- }
- }
-
-}
-
View
7 src/main/resources/Omid.thrift
@@ -191,11 +191,6 @@ struct TResultGet {
2: required TTransaction transaction
}
-struct TResultDelete {
- 1: required list<TDelete> results,
- 2: required TTransaction transaction
-}
-
struct TResultScanner {
1: required i32 scannerId,
2: required TTransaction transaction
@@ -297,7 +292,7 @@ service TOmidService {
* executed. So if everything succeeds you'll
* receive an empty list.
*/
- TResultDelete deleteMultiple(
+ TTransaction deleteMultiple(
/** the table to delete from */
1: required binary table,
View
134 src/test/java/com/yahoo/omid/TestThrift.java
@@ -0,0 +1,134 @@
+/**
+ * Copyright (c) 2011 Yahoo! Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. See accompanying LICENSE file.
+ */
+
+package com.yahoo.omid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.Test;
+
+import com.yahoo.omid.thrift.ThriftServerHandler;
+import com.yahoo.omid.thrift.generated.TColumnValue;
+import com.yahoo.omid.thrift.generated.TDelete;
+import com.yahoo.omid.thrift.generated.TGet;
+import com.yahoo.omid.thrift.generated.TOmidService.Iface;
+import com.yahoo.omid.thrift.generated.TPut;
+import com.yahoo.omid.thrift.generated.TResult;
+import com.yahoo.omid.thrift.generated.TResultGet;
+import com.yahoo.omid.thrift.generated.TResultScanner;
+import com.yahoo.omid.thrift.generated.TScan;
+import com.yahoo.omid.thrift.generated.TTransaction;
+
+public class TestThrift extends OmidTestBase {
+ private static final Log LOG = LogFactory.getLog(TestThrift.class);
+
+ private static ByteBuffer table = ByteBuffer.wrap(Bytes.toBytes(TEST_TABLE));
+
+ @Test
+ public void runTestSimple() throws Exception {
+ Iface th = ThriftServerHandler.newInstance(conf);
+
+ TTransaction t1 = th.startTransaction();
+ LOG.info("Transaction created " + t1);
+
+ ByteBuffer row = ByteBuffer.wrap(Bytes.toBytes("test-simple"));
+ ByteBuffer fam = ByteBuffer.wrap(Bytes.toBytes(TEST_FAMILY));
+ ByteBuffer col = ByteBuffer.wrap(Bytes.toBytes("testdata"));
+ ByteBuffer data1 = ByteBuffer.wrap(Bytes.toBytes("testWrite-1"));
+ ByteBuffer data2 = ByteBuffer.wrap(Bytes.toBytes("testWrite-22"));
+
+ TPut p = new TPut(row, Arrays.asList(new TColumnValue(fam, col, data1)));
+ t1 = th.putMultiple(table, Arrays.asList(p), t1);
+ th.commitTransaction(t1);
+
+ TTransaction tread = th.startTransaction();
+ TTransaction t2 = th.startTransaction();
+ p = new TPut(row, Arrays.asList(new TColumnValue(fam, col, data2)));
+ t2 = th.putMultiple(table, Arrays.asList(p), t2);
+ th.commitTransaction(t2);
+
+ TGet g = new TGet(row);
+ TResultGet r = th.getMultiple(table, Arrays.asList(g), tread);
+ assertEquals("Unexpected value for SI read", data1,
+ ByteBuffer.wrap(r.getResults().get(0).getColumnValues().get(0).getValue()));
+ }
+
+ @Test
+ public void runTestDeleteRow() throws Exception {
+ Iface th = ThriftServerHandler.newInstance(conf);
+
+ TTransaction t1 = th.startTransaction();
+ LOG.info("Transaction created " + t1);
+
+ int rowcount = 10;
+ int count = 0;
+
+ ByteBuffer fam = ByteBuffer.wrap(Bytes.toBytes(TEST_FAMILY));
+ ByteBuffer col = ByteBuffer.wrap(Bytes.toBytes("testdata"));
+ ByteBuffer data1 = ByteBuffer.wrap(Bytes.toBytes("testWrite-1"));
+
+ ByteBuffer modrow = ByteBuffer.wrap(Bytes.toBytes("test-del" + 3));
+ for (int i = 0; i < rowcount; i++) {
+ ByteBuffer row = ByteBuffer.wrap(Bytes.toBytes("test-del" + i));
+
+ TPut p = new TPut(row, Arrays.asList(new TColumnValue(fam, col, data1)));
+ t1 = th.putMultiple(table, Arrays.asList(p), t1);
+ }
+ th.commitTransaction(t1);
+
+ TTransaction t2 = th.startTransaction();
+ TDelete d = new TDelete(modrow);
+ t2 = th.deleteMultiple(table, Arrays.asList(d), t2);
+
+ TTransaction tscan = th.startTransaction();
+ TResultScanner rs = th.openScanner(table, new TScan(), tscan);
+ tscan = rs.getTransaction();
+ int scannerId = rs.getScannerId();
+ List<TResult> results = th.getScannerRows(scannerId, 100);
+ count = 0;
+ for (TResult r : results) {
+ count++;
+ LOG.trace("row: " + Bytes.toString(r.getRow()) + " count: " + count);
+ }
+ assertTrue("Expected " + rowcount + " rows but " + count + " found", count == rowcount);
+ th.closeScanner(scannerId);
+
+ boolean committed = th.commitTransaction(t2);
+ assertTrue("Delete failed", committed);
+
+ tscan = th.startTransaction();
+ rs = th.openScanner(table, new TScan(), tscan);
+ tscan = rs.getTransaction();
+ scannerId = rs.getScannerId();
+ results = th.getScannerRows(scannerId, 100);
+ count = 0;
+ for (TResult r : results) {
+ System.out.println(r);
+ count++;
+ LOG.trace("row: " + Bytes.toString(r.getRow()) + " count: " + count);
+ }
+ th.closeScanner(scannerId);
+ assertTrue("Expected " + (rowcount - 1) + " rows but " + count + " found", count == (rowcount - 1));
+ }
+}

0 comments on commit 1a72d4c

Please sign in to comment.