开发者

HBase Zookeeper Close Connection

开发者 https://www.devze.com 2023-02-15 21:20 出处:网络
I\'m trying to make a simple Web Service that runs on Apache Tomcat and has only one operation thate makes a HBase table scan.

I'm trying to make a simple Web Service that runs on Apache Tomcat and has only one operation thate makes a HBase table scan. Here is how i get the config:

Configuration config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", "hdp-node");

Htable table = new HTable(config, "myTable");       

... scanner ...

scanner.close()
table.close()

The problem is that a connection to Zookeeper stays open and when i reach to a certain number of connedtions , Zookeeper b开发者_Python百科egins to discard.

How can I close my Zookeeper connection after i make the scan?

Thanks


Connections to HBase and ZooKeeper are managed for you by the static HConnectionManager object. This object is a map of Configuration (really HBaseConfiguration) objects to HConnection objects.

The HConnectionManager allows you to clean up connections for a configuration instance by calling its deleteConnection method.

So, if you want to force close your connections, you can just add the following line to the bottom of your code segment:

//free resources and close connections
HConnectionManager.deleteConnection(config,true);

However...

The HBase API is designed to multiplex client transactions over a single HConnection, and as long as multiple instances of HTable share the same Configuration object, they will use the same HConnection. This saves all of the connection setup and tear down overhead for repeated transactions.

What does this mean?

It means that if possible, you really want to limit the number of instances of HBaseConfiguration per process, even if they are shared among multiple threads. However, keep in mind that instances of HBaseConfiguration are not thread safe, so they shouldn't be modified by multiple threads.


I had a similar problem. The way I solved it was to make the Configuration object static. By that way there should only be one connection (per jvm).


What version of ZooKeeper are you running? It could well be that you are hitting issue 846.

Try upgrading ZooKeeper to 3.3.2 or later.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号