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

Getting Started

dgomezferro edited this page May 14, 2012 · 17 revisions

Here we explain all the steps needed to get a transactional HBase working assuming you already have a (pseudo-)distributed HBase cluster.

Installation

To install Omid, just download an unpack the repository. Under the main directory, run this

$ mvn install

Now you can add a dependency on Omid-0.0.1-SNAPSHOT on your project if you are using maven.

Configuration

Omid's clients use the usual hbase-site.xml for configuration, it needs two additional parameters

<property>
 <name>tso.host</name>
 <value>tso.your.cluster.com</value>
</property>
<property>
  <name>tso.port</name>
  <value>1234</value>
</property>

Usage

To use HBase transactional support the relevant interfaces are TransactionManager and TransactionalTable, both in com.yahoo.omid.client. The common use case is to start a new transaction with TransactionState txn1 = transactionManager.beginTransaction(), then use this transaction to perform different HBase operations, like transactionalTable.put(txn1, putOperation) and finally commit it transactionManager.tryCommit(txn1).

Example

     Configuration conf = HBaseConfiguration.create();
     TransactionManager tm = new TransactionManager(conf);
     TransactionalTable tt = new TransactionalTable(conf, TEST_TABLE);
     
     TransactionState t1 = tm.beginTransaction();

     Put put = new Put(row);
     putt.add(fam, col, data);
     tt.put(t1, p);
     
     ResultScanner rs = tt.getScanner(t1, new Scan().setStartRow(startrow).setStopRow(stoprow));
     Result r = rs.next();
     while (r != null) {
        ...
        r = rs.next();
     }
     tm.tryCommit(t1);

Garbage Collection

If you know the maximum number of concurrent transactions that could be modifying a data item at the same time, you could set the maximum number of versions HBase will store to that number (plus some threshold), because Omid needs to have access to that many versions to guarantee Snapshot Isolation.

If this number is not bounded or you don't want risk it, we provide a custom compacter that uses HBase's Coprocessors. You should set the maximum number of versions to infinity (Long.MAX_VALUE) and our compactertakes care of deleting the versions not needed anymore.

Configuration

You must make sure the Omid jar is available to all region servers and add this to your hbase-site.xml (to the one the HBase servers use):

<property>
  <name>hbase.coprocessor.region.classes</name>
  <value>com.yahoo.omid.client.regionserver.Compacter</value>
</property>