The HBase CheckAndMutate is atomic is it also consistent?

Viewed 133

I understand that HBase uses a Multi-version concurrency control, and the documentation for CheckAndMutate explains that it is an atomic operation. I am not sure what that means?

  • Does it mean that all the mutate operations execute in an atomic fashion?
  • Does it mean that the CHECK is also included under the same atomic umbrella?

Let's say I have:

  • a cell with value 5.
  • 2 workers simultaneously want to change the value of the cell (using checkAndMutate) if the value is 5
  • worker-1 checks if the cell value is 5 then set the value to 6
  • worker-2 checks if the cell value is 5 then set the value to 7

If the read is included under the same atomic umbrella then only one of the workers would succeed. If the read is not included under the atomic umbrella then both could succeed.

2 Answers

The way checkAndMutate works in HBase is that a write lock is taken on the row that needs to be updated BEFORE the read in the checkAndMutate operation. So, yes, the read is also included in the atomicity guarantee and only one worker will succeed in the scenario that you have posed.

I have not been able to test this, but based on this code base I think the Get happens after the lock, therefore only one of the workers in the above case would succeed.

Related