-
Notifications
You must be signed in to change notification settings - Fork 42
How to Use
James Lee edited this page Oct 9, 2013
·
1 revision
Home ▸ How it Use
Haeinsa needs HBase 0.94.3 or later and Java 1.7 or later.
Add lock column family to all of tables on your HBase cluster. This lock column is used by Haeinsa internally. Default name of the column familmy is "!lock!".
You can manually include Haeinsa into your project by adding jar files to classpath. Or you can simply add maven dependency on your pom.xml if your project is maven project. Haeinsa JARs are available from Maven central repository.
<dependency>
<groupId>kr.co.vcnc.haeinsa</groupId>
<artifactId>haeinsa</artifactId>
<version>1.0.0</version>
</dependency>
Here is sample codes. You can see more sample codes on the API Usage page.
HaeinsaTransactionManager tm = new HaeinsaTransactionManager(tablePool);
HaeinsaTableIface table = tablePool.getTable("test");
byte[] family = Bytes.toBytes("data");
byte[] qualifier = Bytes.toBytes("status");
HaeinsaTransaction tx = tm.begin(); // start transaction
HaeinsaPut put1 = new HaeinsaPut(Bytes.toBytes("user1"));
put1.add(family, qualifier, Bytes.toBytes("Hello World!"));
table.put(tx, put1);
HaeinsaPut put2 = new HaeinsaPut(Bytes.toBytes("user2"));
put2.add(family, qualifier, Bytes.toBytes("Linearly Scalable!"));
table.put(tx, put2);
tx.commit(); // commit transaction to HBase
Here is what you need to know before using Haeinsa:
- Haeinsa is designed for low-conflict environment. If many transactions concurrently access to same row, performance of Haeinsa can be degraded.
- Haeinsa is targeted for transactions across handful of rows ( from 1 to 100s of rows ), not for transaction against thousands of rows.
- If transaction take more than 5 second, it might be aborted by other ongoing transaction frequently which can cause poor performance.
- It is highly recommended to synchronize clock of each client which use Haeinsa within reasonable time skew. (eg. ntpd)
- User application can't explicitly control timestamp in Haeinsa. Timestamp is managed by Haeinsa transaction manager to implement safe rollback.
- Dedicated lock column family ("!lock!" by default) has to be the first column family on every table when sorting names of all column family lexicographically.
- Most of the case, this requirement can be met easily because '!' is the first printable character in ascii code.
- HBase version higher than 0.94.3 required
- This is because consistency bug on previous version of HBase.
- Strongly recommended to use version which apply issue HBASE-7051