1

We are using a hbase table as a big queue. Many clients can insert into it, and many clients want to read data from it. Problem is mutual exclusion. At span that a client read data until delete it another client can read it too! But we want to make sure each row return to one and only one client.

I should mention we are using Java hbase client.

Is there a way like get and delete a row atomically or get and update in hbase, or some thing that could manage this situation?

I found RowLock mechanism but it's deprecated and does not exists anymore. Also there is a distribution lock using zookeeper but it does not seem efficient.

Thanks in advance.

vakarami
  • 576
  • 9
  • 22

1 Answers1

1

Try that approach

  1. get required row. Check in java code that it is not used by one one (specific column==0).
  2. check the row exists and not used by anyone. If yes, then mark it(ie. increment column value from 0 to 1) x. All that can be done by checkAndPut
  3. delete row using checkAndDelete.
Natalia
  • 4,362
  • 24
  • 25
  • Simple and excellent idea. but I just removed second step, but if I could successfully delete a row, I suppose row is mine and I return it, but if I can't delete it It means another client has already removed it (and owns it) and I'll query for next row. – vakarami Sep 17 '15 at 08:09
  • sounds reasonable. Just one point: if you delete a row and than something happens with thread that process it, you will lose the data. – Natalia Sep 17 '15 at 08:23
  • For some other reasons I have a backup table, if client says i'm done with data then I remove row from backup table too, otherwise I restore data from backup table. – vakarami Sep 17 '15 at 08:27