Hbase provides us a mechanism to treat columns as counters. Counters allow us to increment a column value with least possible overhead.
Advantage of using Counters
While trying to increment a value stored in a table, we would have to lock the row, read the value, increment it, write it back to the table, and finally remove the look from the row, so that it can be used by other clients. This could cause a row to be locked for a long period and may possibly cause a clash between the clients tying to access the same row. Counters help us to overcome this problem as Increments are done under a single row lock, so write operations to a row are synchronized.
**Older versions of Hbase supported calls which involved one RPC per counter update. But the newer versions allow us to bundle multiple counters in a single RPC call.
Counters are limited to a single row, though we can update multiple counters simultaneously. This means that we operate on one row at a time when working with counters.
Hbase API provide the Increment class to perform Increment operations.
**To increment columns of a row, instantiate an Increment object with the row to increment. At least one column to increment must be specified using the
addColumn(byte, byte, long)method.
Alternatively we can use the the incrementColumnValue(row, family, qualifier, amount) method through an instance of Htable class.