VCNC / haeinsa

Haeinsa is linearly scalable multi-row, multi-table transaction library for HBase
Apache License 2.0
158 stars 42 forks source link

Check & put incerement or other #42

Closed ehudl closed 9 years ago

ehudl commented 9 years ago

Hi, We are using your great solution for Transaction operations over hbase. Some of our API uses check and put and increment counters. What will happened if I use the haeinsa API, and also check and put in the same rows ?

Is there a best practice for that ?

Or should I implement that my self.

BTW.

I compiled your code with cdh5 (removed the tests) you can see it in my fork, and it is working fine.

Thanks

Ehud

eincs commented 9 years ago

Sorry for replying late, and thanks for testing Haeinsa working on cdh5. Actually, we are also using Haeinsa on cdh4.4.

You must not use Haeinsa API and HBase API together. Integrity of Haeinsa may be broken: Haeinsa updates lock column of the row itself everytime when Haeinsa modifies the row. Haeinsa check if row is modified or not by checking modification of the lock column. But HBase API don't update lock column as you know.

For now, Haeinsa do not supports checkAndPut or increment APIs, since haeinsa already supports transaction.

See following HBase API:

Increment inc = new Increment(row);
inc.addColumn(family, qualifier, 1);
Result result1 = hbaseTable.increment(inc);

Following Haeinsa code runs atomically as Increment operation of HBase API:

HaeinsaTransaction tx = tm.begin();

HaeinsaGet get = new HaeinsaGet(row);
get.addColumn(family, qualifier);
HaeinsaResult result = haeinsaTable.get(tx, get);
byte[] value = result.getValue(row, family, qualifier);
int v = convertToInt(value);

HaeinsaGet put = new HaeinsaPut(row);
put.add(family, qualifier, toBytes(v+1));
haeinsaTable.put(tx, put);

tx.commit();

You can shorten codes by implementing utility method or there can be many other ways to shorten codes.

ehudl commented 9 years ago

Thanks