Database Reference
In-Depth Information
The
HTable
class is not thread-safe as concurrent modiications are not safe. Hence,
a single instance of
HTable
for each thread should be used in any application.
For multiple
HTable
instances with the same coniguration reference, the same
underlying
HConnection
instance can be used.
Creating
HTable
instances also comes at a cost. Creating an
HTable
instance is a slow
process as the creation of each
HTable
instance involves the scanning of the
.META
table to check whether the table actually exists, which makes the operation very
costly. Hence, it is not recommended that you use a new
HTable
instance for each
request where the number of concurrent requests are very high.
Whenever there is a requirement of multiple instances of
HTable
, consider using
the
HTablePool
class. The following constructor can be used to create an instance
of
HTablePool
:
HTablePool()
HTablePool(Configuration config, int maxSize)
HTablePool(Configuration config, int maxSize,
HTableInterfaceFactory tableFactory)
The
HTablePool
class creates a pool with the
HTable
class instances with the
coniguration object, and setting the
maxSize
parameter deining the
HTable
instances to count a pool. Here is the code for getting the
HTable
instance from
HTablePool
:
HTableInterface usersTable = pool.getTable("Costumers");
CRUD operations
A rowkey primarily represents each row uniquely in the HBase table, whereas other
keys such as column family, timestamp, and so on are used to locate a piece of data
in an HBase table. The HBase API provides the following methods to support the
CRUD operations:
•
Put
•
Get
•
Delete
•
Scan
•
Increment
Let's discuss the irst three methods in detail and the rest will be covered in the
coming chapters.