Database Reference
In-Depth Information
HBase provides two types of counters, namely:
• Single counters
• Multiple counters
Single counters
Under this type, a single RPC call is made to increment the value for a single counter
only. The following are the methods provided by HTable for single counter handling:
long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
long amount)
long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
long amount, Durability durability)
The preceding methods increment the column value as an atomic operation. For
these atomic operations, durability can be set as ASYNC_WAL, FSYNC_WAL , SKIP_WAL ,
SYNC_WAL , or USE_DEFAULT . Each value guarantees different levels of durability for
the table. For example, Durability.SKIP_WAL means that in a fail scenario, any
increments that have not been lushed will be lost. The following code samples show
the usage of the methods:
HTable table = new HTable(conf, "counters");
long cnt1 = table.incrementColumnValue(Bytes.toBytes("Jan14"),Bytes.
toBytes("monthly"), Bytes.toBytes("hits"), 100, Durability.SKIP_WAL);
long cnt2 = table.incrementColumnValue(Bytes.toBytes("Feb14"),Bytes.
toBytes("monthly"), Bytes.toBytes("hits"), 1500, Durability.SKIP_WAL);
Multiple counters
In the case of multiple counters, a single RPC call is made to increment the value
of multiple counters. HTable deines a method, increment() , which is used to
increment the value of multiple counters:
Result increment(Increment increment)
This method increments one or more column values within a single row. These
increments are done within a single row lock by making the write operations to a
row as synchronized. While reading the values from HBase columns, clients do not
take row locks; therefore, the get and scan operations might return the partially
completed values. This method requires instances of the Increment class with all
the appropriate details as follows:
 
Search WWH ::




Custom Search