-
Notifications
You must be signed in to change notification settings - Fork 106
Getting Started
Here we explain all the steps needed to get a transactional HBase working assuming you already have a (pseudo-)distributed HBase cluster.
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, otherwise just point to the jar created in target
from your application's classpath.
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>
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)
.
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);
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.
You must make sure the Omid jar is available to all region servers and add this to your hbase-site.xml (the one the HBase servers use):
<property>
<name>hbase.coprocessor.region.classes</name>
<value>com.yahoo.omid.client.regionserver.Compacter</value>
</property>
Omid
Copyright 2011-2015 Yahoo Inc. Licensed under the Apache License, Version 2.0