Skip to content

Commit

Permalink
Removed TTableInterface, added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Gómez Ferro committed Feb 18, 2013
1 parent 03c676e commit 2c7ec93
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 367 deletions.
221 changes: 164 additions & 57 deletions src/main/java/com/yahoo/omid/transaction/TTable.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@


/** /**
* Provides transactional methods for accessing and modifying a given snapshot * Provides transactional methods for accessing and modifying a given snapshot
* of data identified by an opaque {@link TransactionState} object. * of data identified by an opaque {@link Transaction} object.
* *
*/ */
public class TTable implements TTableInterface { public class TTable {


public static long getsPerformed = 0; public static long getsPerformed = 0;
public static long elementsGotten = 0; public static long elementsGotten = 0;
Expand All @@ -75,12 +75,17 @@ public TTable(Configuration conf, String tableName) throws IOException {
} }


/** /**
* Transactional version of {@link HTable#get(Get)} * Extracts certain cells from a given row.
* *
* @param transactionState * @param get
* Identifier of the transaction * The object that specifies what data to fetch and from which
* @see HTable#get(Get) * row.
* @return The data coming from the specified row, if it exists. If the row
* specified doesn't exist, the {@link Result} instance returned
* won't contain any {@link KeyValue}, as indicated by
* {@link Result#isEmpty()}.
* @throws IOException * @throws IOException
* if a remote or network exception occurs.
*/ */
public Result get(Transaction transaction, final Get get) throws IOException { public Result get(Transaction transaction, final Get get) throws IOException {
if (!(transaction instanceof TransactionState)) { if (!(transaction instanceof TransactionState)) {
Expand Down Expand Up @@ -114,12 +119,12 @@ public Result get(Transaction transaction, final Get get) throws IOException {
} }


/** /**
* Transactional version of {@link HTable#delete(Delete)} * Deletes the specified cells/row.
* *
* @param transactionState * @param delete
* Identifier of the transaction * The object that specifies what to delete.
* @see HTable#delete(Delete)
* @throws IOException * @throws IOException
* if a remote or network exception occurs.
*/ */
public void delete(Transaction transaction, Delete delete) throws IOException { public void delete(Transaction transaction, Delete delete) throws IOException {
if (!(transaction instanceof TransactionState)) { if (!(transaction instanceof TransactionState)) {
Expand Down Expand Up @@ -176,12 +181,16 @@ public void delete(Transaction transaction, Delete delete) throws IOException {
} }


/** /**
* Transactional version of {@link HTable#put(Put)} * Puts some data in the table.
* <p>
* If {@link #isAutoFlush isAutoFlush} is false, the update is buffered
* until the internal buffer is full.
* *
* @param transactionState * @param put
* Identifier of the transaction * The data to put.
* @see HTable#put(Put)
* @throws IOException * @throws IOException
* if a remote or network exception occurs.
* @since 0.20.0
*/ */
public void put(Transaction transaction, Put put) throws IOException, IllegalArgumentException { public void put(Transaction transaction, Put put) throws IOException, IllegalArgumentException {
if (!(transaction instanceof TransactionState)) { if (!(transaction instanceof TransactionState)) {
Expand All @@ -206,12 +215,15 @@ public void put(Transaction transaction, Put put) throws IOException, IllegalArg
} }


/** /**
* Transactional version of {@link HTable#getScanner(Scan)} * Returns a scanner on the current table as specified by the {@link Scan}
* object. Note that the passed {@link Scan}'s start row and caching
* properties maybe changed.
* *
* @param transactionState * @param scan
* Identifier of the transaction * A configured {@link Scan} object.
* @see HTable#getScanner(Scan) * @return A scanner.
* @throws IOException * @throws IOException
* if a remote or network exception occurs.
*/ */
public ResultScanner getScanner(Transaction transaction, Scan scan) throws IOException { public ResultScanner getScanner(Transaction transaction, Scan scan) throws IOException {
if (!(transaction instanceof TransactionState)) { if (!(transaction instanceof TransactionState)) {
Expand Down Expand Up @@ -353,58 +365,95 @@ public Result[] next(int nbRows) throws IOException {


} }


@Override /**
* Gets the name of this table.
*
* @return the table name.
*/
public byte[] getTableName() { public byte[] getTableName() {
return table.getTableName(); return table.getTableName();
} }


@Override /**
* Returns the {@link Configuration} object used by this instance.
* <p>
* The reference returned is not a copy, so any change made to it will
* affect this instance.
*/
public Configuration getConfiguration() { public Configuration getConfiguration() {
return table.getConfiguration(); return table.getConfiguration();
} }


@Override /**
* Gets the {@link HTableDescriptor table descriptor} for this table.
*
* @throws IOException
* if a remote or network exception occurs.
*/
public HTableDescriptor getTableDescriptor() throws IOException { public HTableDescriptor getTableDescriptor() throws IOException {
return table.getTableDescriptor(); return table.getTableDescriptor();
} }


@Override /**
* Test for the existence of columns in the table, as specified in the Get.
* <p>
*
* This will return true if the Get matches one or more keys, false if not.
* <p>
*
* This is a server-side call so it prevents any data from being transfered
* to the client.
*
* @param get
* the Get
* @return true if the specified Get matches one or more keys, false if not
* @throws IOException
* e
*/
public boolean exists(Transaction transaction, Get get) throws IOException { public boolean exists(Transaction transaction, Get get) throws IOException {
Result result = get(transaction, get); Result result = get(transaction, get);
return !result.isEmpty(); return !result.isEmpty();
} }


/* /*
@Override * @Override public void batch(Transaction transaction, List<? extends Row>
public void batch(Transaction transaction, List<? extends Row> actions, Object[] results) throws IOException, * actions, Object[] results) throws IOException, InterruptedException { //
InterruptedException { * TODO Auto-generated method stub
// TODO Auto-generated method stub *
* }
} *
* @Override public Object[] batch(Transaction transaction, List<? extends
@Override * Row> actions) throws IOException, InterruptedException { // TODO
public Object[] batch(Transaction transaction, List<? extends Row> actions) throws IOException, * Auto-generated method stub return null; }
InterruptedException { *
// TODO Auto-generated method stub * @Override public <R> void batchCallback(Transaction transaction, List<?
return null; * extends Row> actions, Object[] results, Callback<R> callback) throws
} * IOException, InterruptedException { // TODO Auto-generated method stub
*
@Override * }
public <R> void batchCallback(Transaction transaction, List<? extends Row> actions, Object[] results, *
Callback<R> callback) throws IOException, InterruptedException { * @Override public <R> Object[] batchCallback(List<? extends Row> actions,
// TODO Auto-generated method stub * Callback<R> callback) throws IOException, InterruptedException { // TODO
* Auto-generated method stub return null; }
} */
@Override
public <R> Object[] batchCallback(List<? extends Row> actions, Callback<R> callback) throws IOException,
InterruptedException {
// TODO Auto-generated method stub
return null;
}
*/


@Override /**
* Extracts certain cells from the given rows, in batch.
*
* @param gets
* The objects that specify what data to fetch and from which
* rows.
*
* @return The data coming from the specified rows, if it exists. If the row
* specified doesn't exist, the {@link Result} instance returned
* won't contain any {@link KeyValue}, as indicated by
* {@link Result#isEmpty()}. If there are any failures even after
* retries, there will be a null in the results array for those
* Gets, AND an exception will be thrown.
* @throws IOException
* if a remote or network exception occurs.
*
*/
public Result[] get(Transaction transaction, List<Get> gets) throws IOException { public Result[] get(Transaction transaction, List<Get> gets) throws IOException {
Result[] results = new Result[gets.size()]; Result[] results = new Result[gets.size()];
int i = 0; int i = 0;
Expand All @@ -414,40 +463,98 @@ public Result[] get(Transaction transaction, List<Get> gets) throws IOException
return results; return results;
} }


@Override /**
* Gets a scanner on the current table for the given family.
*
* @param family
* The column family to scan.
* @return A scanner.
* @throws IOException
* if a remote or network exception occurs.
*/
public ResultScanner getScanner(Transaction transaction, byte[] family) throws IOException { public ResultScanner getScanner(Transaction transaction, byte[] family) throws IOException {
Scan scan = new Scan(); Scan scan = new Scan();
scan.addFamily(family); scan.addFamily(family);
return getScanner(transaction, scan); return getScanner(transaction, scan);
} }


@Override /**
* Gets a scanner on the current table for the given family and qualifier.
*
* @param family
* The column family to scan.
* @param qualifier
* The column qualifier to scan.
* @return A scanner.
* @throws IOException
* if a remote or network exception occurs.
*/
public ResultScanner getScanner(Transaction transaction, byte[] family, byte[] qualifier) throws IOException { public ResultScanner getScanner(Transaction transaction, byte[] family, byte[] qualifier) throws IOException {
Scan scan = new Scan(); Scan scan = new Scan();
scan.addColumn(family, qualifier); scan.addColumn(family, qualifier);
return getScanner(transaction, scan); return getScanner(transaction, scan);
} }


@Override /**
* Puts some data in the table, in batch.
* <p>
* If {@link #isAutoFlush isAutoFlush} is false, the update is buffered
* until the internal buffer is full.
* <p>
* This can be used for group commit, or for submitting user defined
* batches. The writeBuffer will be periodically inspected while the List is
* processed, so depending on the List size the writeBuffer may flush not at
* all, or more than once.
*
* @param puts
* The list of mutations to apply. The batch put is done by
* aggregating the iteration of the Puts over the write buffer at
* the client-side for a single RPC call.
* @throws IOException
* if a remote or network exception occurs.
*/
public void put(Transaction transaction, List<Put> puts) throws IOException { public void put(Transaction transaction, List<Put> puts) throws IOException {
for (Put put : puts) { for (Put put : puts) {
put(transaction, put); put(transaction, put);
} }
} }


@Override /**
* Deletes the specified cells/rows in bulk.
*
* @param deletes
* List of things to delete. List gets modified by this method
* (in particular it gets re-ordered, so the order in which the
* elements are inserted in the list gives no guarantee as to the
* order in which the {@link Delete}s are executed).
* @throws IOException
* if a remote or network exception occurs. In that case the
* {@code deletes} argument will contain the {@link Delete}
* instances that have not be successfully applied.
*/
public void delete(Transaction transaction, List<Delete> deletes) throws IOException { public void delete(Transaction transaction, List<Delete> deletes) throws IOException {
for (Delete delete : deletes) { for (Delete delete : deletes) {
delete(transaction, delete); delete(transaction, delete);
} }
} }


@Override /**
* Provides access to the underliying HTable in order to configure it or to
* perform unsafe (non-transactional) operations. The latter would break the
* transactional guarantees of the whole system.
*
* @return The underlying HTable object
*/
public HTableInterface getHTable() { public HTableInterface getHTable() {
return table; return table;
} }


@Override /**
* Releases any resources held or pending changes in internal buffers.
*
* @throws IOException
* if a remote or network exception occurs.
*/
public void close() throws IOException { public void close() throws IOException {
table.close(); table.close();
} }
Expand Down
Loading

0 comments on commit 2c7ec93

Please sign in to comment.