9.3. Client

The HBase client HTable is responsible for finding RegionServers that are serving the particular row range of interest. It does this by querying the .META. and -ROOT- catalog tables (TODO: Explain). After locating the required region(s), the client directly contacts the RegionServer serving that region (i.e., it does not go through the master) and issues the read or write request. This information is cached in the client so that subsequent requests need not go through the lookup process. Should a region be reassigned either by the master load balancer or because a RegionServer has died, the client will requery the catalog tables to determine the new location of the user region.

See Section 9.5.2, “Runtime Impact” for more information about the impact of the Master on HBase Client communication.

Administrative functions are handled through HBaseAdmin

9.3.1. Connections

For connection configuration information, see Section 2.3.4, “Client configuration and dependencies connecting to an HBase cluster”.

HTable instances are not thread-safe. Only one thread use an instance of HTable at any given time. When creating HTable instances, it is advisable to use the same HBaseConfiguration instance. This will ensure sharing of ZooKeeper and socket instances to the RegionServers which is usually what you want. For example, this is preferred:

HBaseConfiguration conf = HBaseConfiguration.create();
HTable table1 = new HTable(conf, "myTable");
HTable table2 = new HTable(conf, "myTable");

as opposed to this:

HBaseConfiguration conf1 = HBaseConfiguration.create();
HTable table1 = new HTable(conf1, "myTable");
HBaseConfiguration conf2 = HBaseConfiguration.create();
HTable table2 = new HTable(conf2, "myTable");

For more information about how connections are handled in the HBase client, see HConnectionManager.

9.3.1.1. Connection Pooling

For applications which require high-end multithreaded access (e.g., web-servers or application servers that may serve many application threads in a single JVM), one solution is HTablePool. But as written currently, it is difficult to control client resource consumption when using HTablePool.

Another solution is to precreate an HConnection using

// Create a connection to the cluster.
HConnection connection = HConnectionManager.createConnection(Configuration);
HTableInterface table = connection.getTable("myTable");
// use table as needed, the table returned is lightweight
table.close();
// use the connection for other access to the cluster
connection.close();

Constructing HTableInterface implementation is very lightweight and resources are controlled/shared if you go this route.

9.3.2. WriteBuffer and Batch Methods

If Section 12.8.4, “HBase Client: AutoFlush” is turned off on HTable, Puts are sent to RegionServers when the writebuffer is filled. The writebuffer is 2MB by default. Before an HTable instance is discarded, either close() or flushCommits() should be invoked so Puts will not be lost.

Note: htable.delete(Delete); does not go in the writebuffer! This only applies to Puts.

For additional information on write durability, review the ACID semantics page.

For fine-grained control of batching of Puts or Deletes, see the batch methods on HTable.

9.3.3. External Clients

Information on non-Java clients and custom protocols is covered in Chapter 10, Apache HBase External APIs

9.3.4. RowLocks

RowLocks are still in the client API however they are discouraged because if not managed properly these can lock up the RegionServers.

There is an oustanding ticket HBASE-2332 to remove this feature from the client.

comments powered by Disqus