Hadoop High Availability
Also available as:
PDF
loading table of contents...

Querying Secondary Regions

This section describes how to query HA-enabled HBase tables.

Querying HBase with the Java API

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, you can use the Result.isStale() method to determine whether the query results arrived from the primary or a secondary replica:

Result result = table.get(get); 
if (result.isStale()) {
   ...
}

Querying HBase Interactively

To specify the desired data consistency for each query, use the HBase shell:

hbase(main):001:0> get 't1', 'r6', {CONSISTENCY => "TIMELINE"}

Interactive scans also accept this syntax:

hbase(main):001:0> scan 't1', {CONSISTENCY => 'TIMELINE'}

[Note]Note

This release of HBase does not provide a mechanism to determine if the results from an interactive query arrived from the primary or a secondary replica.

You can also request a specific region replica for debugging:

hbase> get 't1', 'r6', {REGION_REPLICA_ID=>0, CONSISTENCY=>'TIMELINE'}
hbase> get 't1', 'r6', {REGION_REPLICA_ID=>2, CONSISTENCY=>'TIMELINE'}