Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

HConnectionManager in CDH 4.7

HConnectionManager in CDH 4.7

Expert Contributor

Hi, does it works: HConnectionManager?

What are the usecases for concurrent access.

I have a servlet and I want to have some kind of pooling for HBase connections. I see that in docs:

 

The simplest way to use this class is by using createConnection(Configuration). This creates a new HConnection to the cluster that is managed by the caller. From this HConnection HTableInterface implementations are retrieved with HConnection.getTable(byte[]). Example:

 HConnection connection = HConnectionManager.createConnection(config);
 HTableInterface table = connection.getTable("table1");
 try {
   // Use the table as needed, for a single operation and a single thread
 } finally {
   table.close();
   connection.close();
 }

 

 

Do I really have to close ALL connections? What is the reason for that?

2 REPLIES 2

Re: HConnectionManager in CDH 4.7

Explorer

Wouldnt it be better if you would use HTablePool for your usecase?

 

The poolsize would be at maximum the number of handler threads in your servlet container. This Pool will take care not to close connections if you call table.close(). The returned proxy which wraps the HTable instance will simply return it to the pool but keep it opened. 

 

We have used the HConnectionManager and to be honest i have to think 3 times everytime i have to review this code. Its a bit strange. The reason to do this, was because we observed that sometimes HConnections kept hanging (e.g. if you try a kernel panic on your RegionServer). But today i would think the better solution in such situations would be to simply force a close on the pool and let it reopen new HTable instances.

Re: HConnectionManager in CDH 4.7

Expert Contributor

HTablePool is deprecated and not recommedned to use. That is why I'm trying to deal wth HConnectionManager.