ArtemStorozhuk
ArtemStorozhuk

Reputation: 8725

Analogue of the transaction in HBase

I have a small problem - I can't understand how to create transaction (or analogue of it) in HBase. For example, there are two tables, and I want to insert value in the first and update value in the second table. I've found that HTable has method:

void batch(List<Row> actions, Object[] results)
//Method that does a batch call on Deletes, Gets and Puts.

But it works only with one table. Googling, I found class MultiAction:

Container for Actions (i.e. Get, Delete, or Put), which are grouped by regionName. Intended to be used with HConnectionManager.processBatch()

Is it that what I'm looking for? If yes, then I can't understand what is region. Thanks for any help.

Upvotes: 3

Views: 1788

Answers (2)

There are some projects aimed at providing a transactional layer on top of HBase, like Omid, which I contribute to.

Upvotes: 2

Arnon Rotem-Gal-Oz
Arnon Rotem-Gal-Oz

Reputation: 25939

HBase does not support transaction. While you have something around atomicity on single table you've got noting like transaction if you need to update more than one. Transactions means 4 things that go by the acronym ACID. in a nutshell

  • Atomicity - changes in a transaction occur together ("all or nothing").
  • Consistency - state should remain valid
  • Isolation - operations outside the transaction cannot see half-changes (intermediate inconsistent states)
  • Durability - changes should persist

You'd have to change HBase code to get Isolation but if you can relax that requirement you can implement a transaction coordinator that would roughly do something like

  • save what needs to be done in the transaction in a special table (transaction log)
  • perform first change
  • perform second change
  • verify that the steps where done and mark the transaction as completed
  • when recovering go to the transaction log and complete/rollback changes

Note that because you don't have isolation sometimes rolling back is not an option so you'd need to implement compensation logic (also take a look at the saga pattern)

Upvotes: 4

Related Questions