Skip to content

Commit

Permalink
[hbase098] changes to use hbase connection and to be able to work wit…
Browse files Browse the repository at this point in the history
…h secured hbase cluster
  • Loading branch information
bijugs committed Jan 22, 2016
1 parent b7d2249 commit 025f3b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions hbase098/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ Following options can be configurable using `-p`.
* `hbase.usepagefilter` : If true, HBase
[PageFilter](https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/filter/PageFilter.html)s
are used to limit the number of records consumed in a scan operation. The default is true.
* `principal`: If testing need to be done against a secure HBase cluster using Kerberos Keytab,
this property can be used to pass the principal in the keytab file.
* `keytab`: The Kerberos keytab file name and location can be passed through this property.
33 changes: 29 additions & 4 deletions hbase098/src/main/java/com/yahoo/ycsb/db/HBaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
import com.yahoo.ycsb.Status;
import com.yahoo.ycsb.measurements.Measurements;

import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
Expand Down Expand Up @@ -59,7 +63,8 @@ public class HBaseClient extends com.yahoo.ycsb.DB
public boolean _debug=false;

public String _table="";
public HTable _hTable=null;
public HConnection _hConn=null;
public HTableInterface _hTable=null;
public String _columnFamily="";
public byte _columnFamilyBytes[];
public boolean _clientSideBuffering = false;
Expand Down Expand Up @@ -94,7 +99,24 @@ public void init() throws DBException
if ("false".equals(getProperties().getProperty("hbase.usepagefilter", "true"))) {
_usePageFilter = false;
}

if ("kerberos".equalsIgnoreCase(config.get("hbase.security.authentication"))) {
config.set("hadoop.security.authentication", "Kerberos");
UserGroupInformation.setConfiguration(config);
}
if ( (getProperties().getProperty("principal")!=null) && (getProperties().getProperty("keytab")!=null) ){
try {
UserGroupInformation.loginUserFromKeytab(getProperties().getProperty("principal"), getProperties().getProperty("keytab"));
} catch (IOException e) {
System.err.println("Keytab file is not readable or not found");
throw new DBException(e);
}
}
try {
_hConn = HConnectionManager.createConnection(config);
} catch (IOException e) {
System.err.println("Connection to HBase was not successful");
throw new DBException(e);
}
_columnFamily = getProperties().getProperty("columnfamily");
if (_columnFamily == null)
{
Expand All @@ -109,7 +131,7 @@ public void init() throws DBException
String table = com.yahoo.ycsb.workloads.CoreWorkload.table;
try
{
HTable ht = new HTable(config, table);
HTableInterface ht = _hConn.getTable(table);
ht.getTableDescriptor();
}
catch (IOException e)
Expand All @@ -132,6 +154,9 @@ public void cleanup() throws DBException
if (_hTable != null) {
_hTable.flushCommits();
}
if (_hConn != null) {
_hConn.close();
}
long en=System.nanoTime();
_measurements.measure("UPDATE", (int)((en-st)/1000));
} catch (IOException e) {
Expand All @@ -142,7 +167,7 @@ public void cleanup() throws DBException
public void getHTable(String table) throws IOException
{
synchronized (tableLock) {
_hTable = new HTable(config, table);
_hTable = _hConn.getTable(table);
//2 suggestions from http://ryantwopointoh.blogspot.com/2009/01/performance-of-hbase-importing.html
_hTable.setAutoFlush(!_clientSideBuffering, true);
_hTable.setWriteBufferSize(_writeBufferSize);
Expand Down

0 comments on commit 025f3b4

Please sign in to comment.