Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed TTableInterface, added documentation

  • Loading branch information...
commit 2c7ec9377ff9520433071da07d60a2ce94eed335 1 parent 03c676e
Daniel Gómez Ferro authored
View
221 src/main/java/com/yahoo/omid/transaction/TTable.java
@@ -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;
@@ -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)) {
@@ -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)) {
@@ -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)) {
@@ -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)) {
@@ -353,58 +365,95 @@ public Result next() 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;
@@ -414,40 +463,98 @@ public void batch(Transaction transaction, List<? extends Row> actions, Object[]
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();
}
View
290 src/main/java/com/yahoo/omid/transaction/TTableInterface.java
@@ -1,290 +0,0 @@
-/**
- * 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.transaction;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.client.Delete;
-import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTableInterface;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
-import org.apache.hadoop.hbase.client.ResultScanner;
-import org.apache.hadoop.hbase.client.Scan;
-
-/**
- * Provides transactional methods for accessing and modifying a given snapshot
- * of data identified by an opaque {@link TransactionState} object.
- *
- */
-public interface TTableInterface extends Closeable {
-
- /**
- * Gets the name of this table.
- *
- * @return the table name.
- */
- byte[] getTableName();
-
- /**
- * 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.
- */
- Configuration getConfiguration();
-
- /**
- * Gets the {@link HTableDescriptor table descriptor} for this table.
- *
- * @throws IOException
- * if a remote or network exception occurs.
- */
- HTableDescriptor getTableDescriptor() throws IOException;
-
- /**
- * 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
- */
- boolean exists(Transaction transaction, Get get) throws IOException;
-
- // /**
- // * Method that does a batch call on Deletes, Gets and Puts. The ordering
- // of
- // * execution of the actions is not defined. Meaning if you do a Put and a
- // * Get in the same {@link #batch} call, you will not necessarily be
- // * guaranteed that the Get returns what the Put had put.
- // *
- // * @param actions
- // * list of Get, Put, Delete objects
- // * @param results
- // * Empty Object[], same size as actions. Provides access to
- // * partial results, in case an exception is thrown. A null in the
- // * result array means that the call for that action failed, even
- // * after retries
- // * @throws IOException
- // * @since 0.90.0
- // */
- // void batch(Transaction transaction, final List<? extends Row> actions,
- // final Object[] results) throws IOException,
- // InterruptedException;
- //
- // /**
- // * Same as {@link #batch(List, Object[])}, but returns an array of results
- // * instead of using a results parameter reference.
- // *
- // * @param actions
- // * list of Get, Put, Delete objects
- // * @return the results from the actions. A null in the return array means
- // * that the call for that action failed, even after retries
- // * @throws IOException
- // * @since 0.90.0
- // */
- // Object[] batch(Transaction transaction, final List<? extends Row>
- // actions) throws IOException, InterruptedException;
- //
- // /**
- // * Same as {@link #batch(List, Object[])}, but with a callback.
- // *
- // * @since 0.96.0
- // */
- // public <R> void batchCallback(Transaction transaction, final List<?
- // extends Row> actions, final Object[] results,
- // final Batch.Callback<R> callback) throws IOException,
- // InterruptedException;
- //
- // /**
- // * Same as {@link #batch(List)}, but with a callback.
- // *
- // * @since 0.96.0
- // */
- // public <R> Object[] batchCallback(List<? extends Row> actions,
- // Batch.Callback<R> callback) throws IOException,
- // InterruptedException;
-
- /**
- * Extracts certain cells from a given row.
- *
- * @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.
- * @since 0.20.0
- */
- Result get(Transaction transaction, Get get) throws IOException;
-
- /**
- * 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.
- *
- * @since 0.90.0
- */
- Result[] get(Transaction transaction, List<Get> gets) throws IOException;
-
- /**
- * 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 scan
- * A configured {@link Scan} object.
- * @return A scanner.
- * @throws IOException
- * if a remote or network exception occurs.
- * @since 0.20.0
- */
- ResultScanner getScanner(Transaction transaction, Scan scan) throws IOException;
-
- /**
- * 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.
- * @since 0.20.0
- */
- ResultScanner getScanner(Transaction transaction, byte[] family) throws IOException;
-
- /**
- * 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.
- * @since 0.20.0
- */
- ResultScanner getScanner(Transaction transaction, byte[] family, byte[] qualifier) throws IOException;
-
- /**
- * Puts some data in the table.
- * <p>
- * If {@link #isAutoFlush isAutoFlush} is false, the update is buffered
- * until the internal buffer is full.
- *
- * @param put
- * The data to put.
- * @throws IOException
- * if a remote or network exception occurs.
- * @since 0.20.0
- */
- void put(Transaction transaction, Put put) throws IOException;
-
- /**
- * 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.
- * @since 0.20.0
- */
- void put(Transaction transaction, List<Put> puts) throws IOException;
-
- /**
- * Deletes the specified cells/row.
- *
- * @param delete
- * The object that specifies what to delete.
- * @throws IOException
- * if a remote or network exception occurs.
- * @since 0.20.0
- */
- void delete(Transaction transaction, Delete delete) throws IOException;
-
- /**
- * 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.
- * @since 0.20.1
- */
- void delete(Transaction transaction, List<Delete> deletes) throws IOException;
-
- /**
- * Releases any resources held or pending changes in internal buffers.
- *
- * @throws IOException
- * if a remote or network exception occurs.
- */
- void close() throws IOException;
-
- /**
- * 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();
-}
View
44 src/main/java/com/yahoo/omid/tso/CommitHashMap.java
@@ -23,12 +23,23 @@
import org.jboss.netty.util.internal.ConcurrentHashMap;
/**
- * A hash map that uses byte[] for the key rather than longs.
+ * This class stores the mapping between start a commit timestamps and between
+ * modified row and commit timestamp.
*
- * Change it to lazyly clean the old entries, i.e., upon a hit This would reduce
- * the mem access benefiting from cache locality
+ * Both mappings are respresented as a long->long mapping, each of them
+ * implemented using a single long []
*
- * @author maysam
+ * For a map of size N we create an array of size 2*N and store the keys on even
+ * indexes and values on odd indexes.
+ *
+ * Each time an entry is removed, we update the largestDeletedTimestamp if the
+ * entry's commit timestamp is greater than this value.
+ *
+ * Rationale: we want queries to be fast and touch as least memory regions as
+ * possible
+ *
+ * TODO: improve garbage collection, right now an entry is picked at random (by
+ * hash) which could cause the eviction of a very recent timestamp
*/
class CommitHashMap {
@@ -46,13 +57,12 @@ public CommitHashMap() {
}
/**
- * Constructs a new, empty hashtable with the specified initial capacity and
- * default load factor, which is <code>0.75</code>.
+ * Constructs a new, empty hashtable with the specified size
*
- * @param initialCapacity
- * the initial capacity of the hashtable.
+ * @param size
+ * the initial size of the hashtable.
* @throws IllegalArgumentException
- * if the initial capacity is less than zero.
+ * if the size is less than zero.
*/
public CommitHashMap(int size) {
if (size < 0) {
@@ -81,14 +91,13 @@ public void putLatestWriteForRow(long hash, long commitTimestamp) {
return;
rowsCommitMapping[index] = commitTimestamp;
- largestDeletedTimestamp = Math
- .max(oldCommitTS, largestDeletedTimestamp);
+ largestDeletedTimestamp = Math.max(oldCommitTS, largestDeletedTimestamp);
}
public long getCommittedTimestamp(long startTimestamp) {
int indexStart = 2 * index(startTimestamp);
int indexCommit = indexStart + 1;
-
+
if (startCommitMapping[indexStart] == startTimestamp) {
return startCommitMapping[indexCommit];
} else {
@@ -106,15 +115,13 @@ public void setCommittedTimestamp(long startTimestamp, long commitTimestamp) {
startCommitMapping[indexStart] = startTimestamp;
startCommitMapping[indexCommit] = commitTimestamp;
- largestDeletedTimestamp = Math
- .max(oldCommitTS, largestDeletedTimestamp);
+ largestDeletedTimestamp = Math.max(oldCommitTS, largestDeletedTimestamp);
}
// set of half aborted transactions
// TODO: set the initial capacity in a smarter way
- Set<AbortedTransaction> halfAborted = Collections
- .newSetFromMap(new ConcurrentHashMap<AbortedTransaction, Boolean>(
- 10000));
+ Set<AbortedTransaction> halfAborted = Collections.newSetFromMap(new ConcurrentHashMap<AbortedTransaction, Boolean>(
+ 10000));
private AtomicLong abortedSnapshot = new AtomicLong();
@@ -124,8 +131,7 @@ long getAndIncrementAbortedSnapshot() {
// add a new half aborted transaction
void setHalfAborted(long startTimestamp) {
- halfAborted.add(new AbortedTransaction(startTimestamp, abortedSnapshot
- .get()));
+ halfAborted.add(new AbortedTransaction(startTimestamp, abortedSnapshot.get()));
}
// call when a half aborted transaction is fully aborted
View
2  src/main/java/com/yahoo/omid/tso/RowKey.java
@@ -48,7 +48,7 @@ public RowKey(byte[] r, byte[] t) {
}
public String toString() {
- return new String(tableId) + ":" + new String(rowId);
+ return Bytes.toString(tableId) + ":" + Bytes.toString(rowId);
}
public static RowKey readObject(ChannelBuffer aInputStream) {
Please sign in to comment.
Something went wrong with that request. Please try again.