Skip to content
Snippets Groups Projects
Commit de0579e6 authored by Biju Nair's avatar Biju Nair
Browse files

[hbase098] Changes to use single HBase connection across all the threads

parent 6cd94e88
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,7 @@ import java.util.Properties; ...@@ -50,6 +50,7 @@ import java.util.Properties;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* HBase client for YCSB framework * HBase client for YCSB framework
...@@ -59,11 +60,12 @@ public class HBaseClient extends com.yahoo.ycsb.DB ...@@ -59,11 +60,12 @@ public class HBaseClient extends com.yahoo.ycsb.DB
// BFC: Change to fix broken build (with HBase 0.20.6) // BFC: Change to fix broken build (with HBase 0.20.6)
//private static final Configuration config = HBaseConfiguration.create(); //private static final Configuration config = HBaseConfiguration.create();
private static final Configuration config = HBaseConfiguration.create(); //new HBaseConfiguration(); private static final Configuration config = HBaseConfiguration.create(); //new HBaseConfiguration();
private static final AtomicInteger THREAD_COUNT = new AtomicInteger(0);
public boolean _debug=false; public boolean _debug=false;
public String _table=""; public String _table="";
public HConnection _hConn=null; private static HConnection _hConn=null;
public HTableInterface _hTable=null; public HTableInterface _hTable=null;
public String _columnFamily=""; public String _columnFamily="";
public byte _columnFamilyBytes[]; public byte _columnFamilyBytes[];
...@@ -112,7 +114,12 @@ public class HBaseClient extends com.yahoo.ycsb.DB ...@@ -112,7 +114,12 @@ public class HBaseClient extends com.yahoo.ycsb.DB
} }
} }
try { try {
_hConn = HConnectionManager.createConnection(config); THREAD_COUNT.getAndIncrement();
synchronized(THREAD_COUNT) {
if (_hConn == null){
_hConn = HConnectionManager.createConnection(config);
}
}
} catch (IOException e) { } catch (IOException e) {
System.err.println("Connection to HBase was not successful"); System.err.println("Connection to HBase was not successful");
throw new DBException(e); throw new DBException(e);
...@@ -154,8 +161,11 @@ public class HBaseClient extends com.yahoo.ycsb.DB ...@@ -154,8 +161,11 @@ public class HBaseClient extends com.yahoo.ycsb.DB
if (_hTable != null) { if (_hTable != null) {
_hTable.flushCommits(); _hTable.flushCommits();
} }
if (_hConn != null) { synchronized(THREAD_COUNT) {
_hConn.close(); int threadCount = THREAD_COUNT.decrementAndGet();
if (threadCount <= 0 && _hConn != null) {
_hConn.close();
}
} }
long en=System.nanoTime(); long en=System.nanoTime();
_measurements.measure("UPDATE", (int)((en-st)/1000)); _measurements.measure("UPDATE", (int)((en-st)/1000));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment