The HBase Java API allows application developers to specify the desired data
consistency for a query using the setConsistency()
method, as shown in
the following example. A new enum, CONSISTENCY
, specifies two levels of
data consistency: TIMELINE
and STRONG
.
Get get = new Get(row); get.setConsistency(CONSISTENCY.TIMELINE); ... Result result = table.get(get);
HBase application developers can also pass multiple gets:
Get get1 = new Get(row); get1.setConsistency(Consistency.TIMELINE); ... ArrayList<Get> gets = new ArrayList<Get>(); ... Result[] results = table.get(gets);
The setConsistency()
method is also available for Scan
objects:
Scan scan = new Scan(); scan.setConsistency(CONSISTENCY.TIMELINE); ... ResultScanner scanner = table.getScanner(scan);
In addition, use the Result.isStale()
method to determine whether the
query results arrived from the primary or a secondary region:
Result result = table.get(get); if (result.isStale()) { ... }