From d058bfcbf0d63a784b327d81b88c7dc3a56c24a8 Mon Sep 17 00:00:00 2001 From: Biju Nair <gs.biju@gmail.com> Date: Wed, 27 Jan 2016 11:47:28 -0500 Subject: [PATCH] [hbase10] Changes to use single HBase connection across all threads --- .../java/com/yahoo/ycsb/db/HBaseClient10.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java b/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java index 70843256..00fb615b 100644 --- a/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java +++ b/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java @@ -51,6 +51,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.Vector; +import java.util.concurrent.atomic.AtomicInteger; /** * HBase 1.0 client for YCSB framework. @@ -63,11 +64,12 @@ import java.util.Vector; */ public class HBaseClient10 extends com.yahoo.ycsb.DB { private Configuration config = HBaseConfiguration.create(); + private static final AtomicInteger THREAD_COUNT = new AtomicInteger(0); private boolean debug = false; private String tableName = ""; - private Connection connection = null; + private static Connection connection = null; // Depending on the value of clientSideBuffering, either bufferedMutator // (clientSideBuffering) or currentTable (!clientSideBuffering) will be used. @@ -130,7 +132,10 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB { } try { - connection = ConnectionFactory.createConnection(config); + THREAD_COUNT.getAndIncrement(); + synchronized(THREAD_COUNT) { + connection = ConnectionFactory.createConnection(config); + } } catch (java.io.IOException e) { throw new DBException(e); } @@ -185,7 +190,12 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB { long en = System.nanoTime(); final String type = clientSideBuffering ? "UPDATE" : "CLEANUP"; measurements.measure(type, (int) ((en - st) / 1000)); - connection.close(); + synchronized(THREAD_COUNT) { + int threadCount = THREAD_COUNT.decrementAndGet(); + if (threadCount <= 0 && connection != null) { + connection.close(); + } + } } catch (IOException e) { throw new DBException(e); } -- GitLab