Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Merge branch 'api' into cache
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/com/yahoo/omid/tso/CommitHashMap.java
  • Loading branch information
Daniel Gómez Ferro committed Feb 20, 2013
2 parents 7c68e55 + 2c7ec93 commit 2623530
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 362 deletions.
221 changes: 164 additions & 57 deletions src/main/java/com/yahoo/omid/transaction/TTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@

/**
* 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 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
* Identifier of the transaction
* @see HTable#get(Get)
* @param get
* The object that specifies what data to fetch and from which
* 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
* if a remote or network exception occurs.
*/
public Result get(Transaction transaction, final Get get) throws IOException {
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
* Identifier of the transaction
* @see HTable#delete(Delete)
* @param delete
* The object that specifies what to delete.
* @throws IOException
* if a remote or network exception occurs.
*/
public void delete(Transaction transaction, Delete delete) throws IOException {
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
* Identifier of the transaction
* @see HTable#put(Put)
* @param put
* The data to put.
* @throws IOException
* if a remote or network exception occurs.
* @since 0.20.0
*/
public void put(Transaction transaction, Put put) throws IOException, IllegalArgumentException {
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
* Identifier of the transaction
* @see HTable#getScanner(Scan)
* @param scan
* A configured {@link Scan} object.
* @return A scanner.
* @throws IOException
* if a remote or network exception occurs.
*/
public ResultScanner getScanner(Transaction transaction, Scan scan) throws IOException {
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() {
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() {
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 {
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 {
Result result = get(transaction, get);
return !result.isEmpty();
}

/*
@Override
public void batch(Transaction transaction, List<? extends Row> actions, Object[] results) throws IOException,
InterruptedException {
// TODO Auto-generated method stub
}
@Override
public Object[] batch(Transaction transaction, List<? extends Row> actions) throws IOException,
InterruptedException {
// TODO Auto-generated method stub
return null;
}
@Override
public <R> void batchCallback(Transaction transaction, List<? extends Row> actions, Object[] results,
Callback<R> callback) throws IOException, InterruptedException {
// TODO Auto-generated method stub
}
@Override
public <R> Object[] batchCallback(List<? extends Row> actions, Callback<R> callback) throws IOException,
InterruptedException {
// TODO Auto-generated method stub
return null;
}
*/
* @Override public void batch(Transaction transaction, List<? extends Row>
* actions, Object[] results) throws IOException, InterruptedException { //
* TODO Auto-generated method stub
*
* }
*
* @Override public Object[] batch(Transaction transaction, List<? extends
* Row> actions) throws IOException, InterruptedException { // TODO
* Auto-generated method stub return null; }
*
* @Override public <R> void batchCallback(Transaction transaction, List<?
* extends Row> actions, Object[] results, Callback<R> callback) throws
* IOException, InterruptedException { // TODO Auto-generated method stub
*
* }
*
* @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 {
Result[] results = new Result[gets.size()];
int i = 0;
Expand All @@ -414,40 +463,98 @@ public Result[] get(Transaction transaction, List<Get> gets) throws IOException
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 {
Scan scan = new Scan();
scan.addFamily(family);
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 {
Scan scan = new Scan();
scan.addColumn(family, qualifier);
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 {
for (Put put : puts) {
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 {
for (Delete delete : deletes) {
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() {
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 {
table.close();
}
Expand Down
Loading

0 comments on commit 2623530

Please sign in to comment.