From d7d320d372962a9938f9fa25c1b611d2e40b3760 Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Tue, 18 Dec 2018 10:31:33 -0800 Subject: [PATCH] un-threadlocal the HConnection realized that we're leaking zookeeper connections, and it might be because the HConnection has been thread local, which probably means that at shutdown only one of the possibly many connections is cleaned up zookeeper by default allows 60 connections per client and it looks likely that we start having trouble when we hit that limit --- .../modules/recrawl/hbase/HBaseTable.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/contrib/src/main/java/org/archive/modules/recrawl/hbase/HBaseTable.java b/contrib/src/main/java/org/archive/modules/recrawl/hbase/HBaseTable.java index eb33b2c8..3032c2df 100644 --- a/contrib/src/main/java/org/archive/modules/recrawl/hbase/HBaseTable.java +++ b/contrib/src/main/java/org/archive/modules/recrawl/hbase/HBaseTable.java @@ -42,7 +42,7 @@ public class HBaseTable extends HBaseTableBean { Logger.getLogger(HBaseTable.class.getName()); protected boolean create = false; - protected ThreadLocal hconn = new ThreadLocal(); + protected HConnection hconn = null; protected ThreadLocal htable = new ThreadLocal(); public boolean getCreate() { @@ -56,11 +56,11 @@ public class HBaseTable extends HBaseTableBean { public HBaseTable() { } - protected HConnection hconnection() throws IOException { - if (hconn.get() == null) { - hconn.set(HConnectionManager.createConnection(hbase.configuration())); + protected synchronized HConnection hconnection() throws IOException { + if (hconn == null) { + hconn = HConnectionManager.createConnection(hbase.configuration()); } - return hconn.get(); + return hconn; } protected HTableInterface htable() throws IOException { @@ -138,13 +138,14 @@ public class HBaseTable extends HBaseTableBean { htable.remove(); } - if (hconn.get() != null) { + if (hconn != null) { try { - hconn.get().close(); + hconn.close(); } catch (IOException e) { logger.log(Level.WARNING, "hconn.close() threw " + e, e); } - hconn.remove(); + // HConnectionManager.deleteStaleConnection(hconn); + hconn = null; } hbase.reset();