Hookase Zookeeper Close

I am trying to create a simple web service that runs on Apache Tomcat and has only one operation that does an HBase table check. This is how I get the configuration:

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 the connection to Zookeeper remains open, and when I reach a certain number of connections, Zookeeper starts to drop.

How can I close my Zookeeper connection after performing a scan?

thanks

+4
source share
3 answers

Connections to HBase and ZooKeeper are controlled by you with a static HConnectionManager object. This object is a Configuration card (really HBaseConfiguration ) HConnection objects.

HConnectionManager allows you to clear connections for a configuration instance by calling the deleteConnection method.

So, if you want to force close your connections, you can simply add the following line at the end of your code segment:

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

But...

The HBase API is designed to multiplex client transactions on a single HConnection, and while multiple HTable instances use the same configuration object, they will use the same HConnection. This saves all connection settings and reduces overhead for repeat transactions.

What does it mean?

This means that whenever possible you really want to limit the number of HBaseConfiguration instances for each process, even if they are distributed across multiple threads. However, keep in mind that the HBaseConfiguration examples are not thread safe , therefore they cannot be modified by multiple threads.

+3
source

I had a similar problem. The way I decided was to make the configuration object static. Thus, there should be only one connection (per jvm).

+1
source

What version of ZooKeeper are you using? It is possible that you click question 846 .

Try updating ZooKeeper to version 3.3.2 or later.

0
source

Source: https://habr.com/ru/post/1343200/


All Articles