HBase Zookeeper 关闭连接

发布于 2024-10-21 17:44:15 字数 455 浏览 7 评论 0原文

我正在尝试创建一个在 Apache Tomcat 上运行的简单 Web 服务,并且只有一个操作来进行 HBase 表扫描。 以下是我获取配置的方式:

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

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

... scanner ...

scanner.close()
table.close()

问题是与 Zookeeper 的连接保持打开状态,当我达到一定数量的连接时,Zookeeper 开始丢弃。

扫描后如何关闭我的 Zookeeper 连接?

谢谢

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 begins to discard.

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓦然回首 2024-10-28 17:44:15

与 HBase 和 ZooKeeper 的连接由静态 HConnectionManager 为您管理 对象。该对象是配置的映射 (实际上是HBaseConfiguration)对象到HConnection 对象。

HConnectionManager 允许您通过调用其 deleteConnection 方法。

因此,如果您想强制关闭连接,只需将以下行添加到代码段的底部即可:

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

但是...

HBase API 旨在通过单个 HConnection 复用客户端事务,并且只要多个实例HTable 共享相同的 Configuration 对象,它们将使用相同的 HConnection。这节省了重复事务的所有连接设置和拆除开销。

这意味着什么?

这意味着如果可能的话,您确实希望限制每个进程的 HBaseConfiguration 实例数量,即使它们在多个线程之间共享。但是,请记住 HBaseConfiguration 不是线程安全的,因此不应由多个线程修改它们。

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.

年少掌心 2024-10-28 17:44:15

我有类似的问题。我解决这个问题的方法是使 Configuration 对象静态。这样一来,应该只有一个连接(每个 jvm)。

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).

少女七分熟 2024-10-28 17:44:15

您运行的是哪个版本的 ZooKeeper?您很可能正在点击 问题 846

尝试将 ZooKeeper 升级到 3.3.2 或更高版本。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文