SlideShare a Scribd company logo
1 of 35
Download to read offline
HBase Client API
 (for webapps?)
         Nick Dimiduk
   Seattle Scalability Meetup
          2013-03-27




                                1
2
3
What are my choices?
   switch (technology) {

       case ‘    ’:
         ...

       case ‘    ’:
         ...

       case ‘    ’:
         ...
   }

                           4
Apache HBase




               5
Java client Interfaces
•   Configuration holds details where to find the cluster and tunable
    settings. Roughly equivalent to JDBC connection string.

•   HConnection represents connections to to the cluster.

•   HBaseAdmin handles DDL operations (create, list, drop, alter, &c.)

•   HTablePool connection pool for table handles.

•   HTable (HTableInterface) is a handle on a single HBase table.
    Send "commands" to the table (Put, Get, Scan, Delete, Increment)

                                                                         6
Java client Example
public static final byte[] TABLE_NAME = Bytes.toBytes("twits");
public static final byte[] TWITS_FAM = Bytes.toBytes("twits");

public static final byte[] USER_COL                                 = Bytes.toBytes("user");
public static final byte[] TWIT_COL                                 = Bytes.toBytes("twit");

private HTablePool pool = new HTablePool();




 https://github.com/hbaseinaction/twitbase/blob/master/src/main/java/HBaseIA/TwitBase/hbase/TwitsDAO.java#L23-L30

                                                                                                                    7
Java client Example
private static class Twit {

   private Twit(Result r) {
     this(
           r.getColumnLatest(TWITS_FAM, USER_COL).getValue(),
           Arrays.copyOfRange(r.getRow(), Md5Utils.MD5_LENGTH,
             Md5Utils.MD5_LENGTH + longLength),
           r.getColumnLatest(TWITS_FAM, TWIT_COL).getValue());
   }

   private Twit(byte[] user, byte[] dt, byte[] text) {
     this(
           Bytes.toString(user),
           new DateTime(-1 * Bytes.toLong(dt)),
           Bytes.toString(text));
   }
https://github.com/hbaseinaction/twitbase/blob/master/src/main/java/HBaseIA/TwitBase/hbase/TwitsDAO.java#L129-L143

                                                                                                                     8
Java client Example

       private static Get mkGet(String user, DateTime dt) {
         Get g = new Get(mkRowKey(user, dt));
         g.addColumn(TWITS_FAM, USER_COL);
         g.addColumn(TWITS_FAM, TWIT_COL);
         return g;
       }




https://github.com/hbaseinaction/twitbase/blob/master/src/main/java/HBaseIA/TwitBase/hbase/TwitsDAO.java#L60-L65

                                                                                                                   9
Ruby, Python client Interface




                                10
Ruby, Python client Interface
        Jyth on
JRu by,

             : '(




                                11
Thrift client Interface


1. Generate bindings

2. Run a “Gateway” between clients and cluster

3. ... profit? code!
        w rite




                                                 12
HBase Cluster

 HBase Clients




Sidebar: Architecture Recap
                                 13
Thrift
                    Gateway     HBase Cluster

Thrift Clients




                 Thrift Architecture
                                                14
Thrift client Interface


•   Thrift gateway exposes a client to RegionServers

•   stateless :D

•   ... except for scanners :'(




                                                       15
Thrift client Example

transport = TSocket.TSocket(host, port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()




      https://github.com/hbaseinaction/twitbase.py/blob/master/TwitBase.py#L17-L21

                                                                                     16
Thrift client Example
columns = ['info:user','info:name','info:email']
scanner = client.scannerOpen('users', '', columns)
row = client.scannerGet(scanner)
while row:
    yield user_from_row(row[0])
    row = scannerGet(scanner)
client.scannerClose(scanner)




     https://github.com/hbaseinaction/twitbase.py/blob/master/TwitBase.py#L33-L39

                                                                                    17
Thrift client Example

def user_from_row(row):
    user = {}
    for col,cell in row.columns.items():
        user[col[5:]] = cell.value
    return "<User: {user}, {name}, {email}>".format(**user)




         https://github.com/hbaseinaction/twitbase.py/blob/master/TwitBase.py#L26-L30

                                                                                        18
REST client Interface


1. Stand up a "REST Gateway" between your application and the cluster

2. HTTP verbs translate (roughly) into table commands

3. decent support for basic DDL, HTable operations




                                                                        19
HBase Cluster
                   REST
REST Clients
                  Gateway




               REST Architecture
                                            20
REST client Interface


•   REST gateway exposes a client to RegionServers

•   stateless :D

•   ... except for scanners :'(




                                                     21
REST client Example

$ curl -H "Accept: application/json" http://host:port/
{
  "table": [ {
               "name": "followers"
             }, {
               "name": "twits"
             }, {
               "name": "users"
             }
           ]
}




                                                         22
REST client Example
$ curl -H ... http://host:port/table/row [/family:qualifier]
{
    "Row": [
        {
             "key": "VGhlUmVhbE1U",
             "Cell": [
                 {
                     "$": "c2FtdWVsQGNsZW1lbnMub3Jn",
                     "column": "aW5mbzplbWFpbA==",
                     "timestamp": 1338701491422
                 },
                 {
                     "$": "TWFyayBUd2Fpbg==",
                     "column": "aW5mbzpuYW1l",
                     "timestamp": 1338701491422
                 },
             ]
        } ] }

                                                               23
REST client Example

<Rows>
  <Row key="VGhlUmVhbE1U">
    <Cells>
       <Cell column="aW5mbzplbWFpbA==" timestamp="1338701491422">
         c2FtdWVsQGNsZW1lbnMub3Jn
       </Cell>
       <Cell ...>
       ...
    </Cells>
  </Row>
</Rows>




                                                                    24
Beyond Apache




                25
asynchbase
•   Asynchronous non-blocking interface.

•   Inspired by Twisted Python.

•   Partial implementation of HTableInterface.

•   HBaseClient provides entry-point to data.



                                   https://github.com/OpenTSDB/asynchbase
                  http://tsunanet.net/~tsuna/asynchbase/api/org/hbase/async/HBaseClient.html


                                                                                               26
asynchbase
                                                                UpdateResult
                                                                   object



                                 output to
                            => [next state]               3
                        /
                                                               Interpret
input => [this state]                                         response
                        
                            => [error state]
                                 Exception
                                                 Boolean
                                               Put response
                                                                UpdateFailed
                                                                 Exception




                                                                               27
asynchbase Example
       final Scanner scanner = client.newScanner(TABLE_NAME);
       scanner.setFamily(INFO_FAM);
       scanner.setQualifier(PASSWORD_COL);

       ArrayList<ArrayList<KeyValue>> rows = null;
       ArrayList<Deferred<Boolean>> workers = new ArrayList<Deferred<Boolean>>();
       while ((rows = scanner.nextRows(1).joinUninterruptibly()) != null) {
         for (ArrayList<KeyValue> row : rows) {
           KeyValue kv = row.get(0);
           byte[] expected = kv.value();
           String userId = new String(kv.key());
           PutRequest put = new PutRequest(
               TABLE_NAME, kv.key(), kv.family(),
               kv.qualifier(), mkNewPassword(expected));
           Deferred<Boolean> d = client.compareAndSet(put, expected)
             .addCallback(new InterpretResponse(userId))
             .addCallbacks(new ResultToMessage(), new FailureToMessage())
             .addCallback(new SendMessage());
           workers.add(d);
         }
       }

https://github.com/hbaseinaction/twitbase-async/blob/master/src/main/java/HBaseIA/TwitBase/AsyncUsersTool.java#L151-L173

                                                                                                                           28
Others
Reduce day-to-day                                                        Full-blown schema
 developer pain                                                             management


      [Orderly]

                                                               Phoenix




                    Spring-Data
                      Hadoop                                                Kiji.org

                               https://github.com/ndimiduk/orderly
                            http://www.springsource.org/spring-data/
                            https://github.com/forcedotcom/phoenix
                                         http://www.kiji.org/
                                                                                             29
Apache Futures


•   Protobuf wire messages (0.96)

•   C client (TBD, HBASE-1015)

•   HBase Types (TBD, HBASE-8089)




                                     30
So, Webapps?




http://www.amazon.com/Back-Point-Rapiers/dp/B0000271GC

                                                         31
Software Architecture


•   Isolate DAO from app logic, separation of concerns, &c.

•   Separate environment configs from code.

•   Watch out for resource contention.




                                                              32
Deployment Architecture


•   Cache everywhere.

•   Know your component layers.




                                   33
HBase Warts

•   Know thy (HBase) version 0.{92,94,96} !

•   long-running client bug (HBASE-4805).

•   Gateway APIs only as up to date as the people before you require.

•   REST API particularly unpleasant for “Web2.0” folk.



                                                                        34
Thanks!

                                         Nick Dimiduk
                                              github.com/ndimiduk
                                              @xefyr
Nick Dimiduk
Amandeep Khurana
                                              n10k.com
                      FOREWORD BY
                   Michael Stack




                   MANNING




hbaseinaction.com


                                                                    35

More Related Content

What's hot

Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a RideBruce Snyder
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Juriy Zaytsev
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныTimur Safin
 
Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012
Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012
Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012Treasure Data, Inc.
 
Oracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesOracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesKim Berg Hansen
 
BlockChain implementation by python
BlockChain implementation by pythonBlockChain implementation by python
BlockChain implementation by pythonwonyong hwang
 
T-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIMLT-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIMLmniemi
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationsourabh aggarwal
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Zianed Hou
 
Session 40 : SAGA Overview and Introduction
Session 40 : SAGA Overview and Introduction Session 40 : SAGA Overview and Introduction
Session 40 : SAGA Overview and Introduction ISSGC Summer School
 
Bring your infrastructure under control with Infrastructor
Bring your infrastructure under control with InfrastructorBring your infrastructure under control with Infrastructor
Bring your infrastructure under control with InfrastructorStanislav Tiurikov
 
Introduction to PHP 5.3
Introduction to PHP 5.3Introduction to PHP 5.3
Introduction to PHP 5.3guestcc91d4
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Luca Lusso
 
Spring data iii
Spring data iiiSpring data iii
Spring data iii명철 강
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 

What's hot (20)

Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a Ride
 
Say Hello To Ecmascript 5
Say Hello To Ecmascript 5Say Hello To Ecmascript 5
Say Hello To Ecmascript 5
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012
Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012
Fluentd loves MongoDB, at MongoDB SV User Group, July 17, 2012
 
Oracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web ServicesOracle database - Get external data via HTTP, FTP and Web Services
Oracle database - Get external data via HTTP, FTP and Web Services
 
BlockChain implementation by python
BlockChain implementation by pythonBlockChain implementation by python
BlockChain implementation by python
 
T-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIMLT-121-5300 (2008) User Interface Design 10 - UIML
T-121-5300 (2008) User Interface Design 10 - UIML
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentation
 
Nancy + rest mow2012
Nancy + rest   mow2012Nancy + rest   mow2012
Nancy + rest mow2012
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Aimaf
AimafAimaf
Aimaf
 
Qt Network Explained (Portuguese)
Qt Network Explained (Portuguese)Qt Network Explained (Portuguese)
Qt Network Explained (Portuguese)
 
Session 40 : SAGA Overview and Introduction
Session 40 : SAGA Overview and Introduction Session 40 : SAGA Overview and Introduction
Session 40 : SAGA Overview and Introduction
 
Bring your infrastructure under control with Infrastructor
Bring your infrastructure under control with InfrastructorBring your infrastructure under control with Infrastructor
Bring your infrastructure under control with Infrastructor
 
Introduction to PHP 5.3
Introduction to PHP 5.3Introduction to PHP 5.3
Introduction to PHP 5.3
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!
 
Spring data iii
Spring data iiiSpring data iii
Spring data iii
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 

Viewers also liked

HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...
HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...
HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...Cloudera, Inc.
 
Apache HBase for Architects
Apache HBase for ArchitectsApache HBase for Architects
Apache HBase for ArchitectsNick Dimiduk
 
Apache HBase Low Latency
Apache HBase Low LatencyApache HBase Low Latency
Apache HBase Low LatencyNick Dimiduk
 
Introduction to Hadoop, HBase, and NoSQL
Introduction to Hadoop, HBase, and NoSQLIntroduction to Hadoop, HBase, and NoSQL
Introduction to Hadoop, HBase, and NoSQLNick Dimiduk
 
HBase Low Latency, StrataNYC 2014
HBase Low Latency, StrataNYC 2014HBase Low Latency, StrataNYC 2014
HBase Low Latency, StrataNYC 2014Nick Dimiduk
 
Bring Cartography to the Cloud
Bring Cartography to the CloudBring Cartography to the Cloud
Bring Cartography to the CloudNick Dimiduk
 
HBase Data Types (WIP)
HBase Data Types (WIP)HBase Data Types (WIP)
HBase Data Types (WIP)Nick Dimiduk
 
Strata + Hadoop World 2012: Apache HBase Features for the Enterprise
Strata + Hadoop World 2012: Apache HBase Features for the EnterpriseStrata + Hadoop World 2012: Apache HBase Features for the Enterprise
Strata + Hadoop World 2012: Apache HBase Features for the EnterpriseCloudera, Inc.
 
Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
 Let Spark Fly: Advantages and Use Cases for Spark on Hadoop Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
Let Spark Fly: Advantages and Use Cases for Spark on HadoopMapR Technologies
 
Introduction to HBase - Phoenix HUG 5/14
Introduction to HBase - Phoenix HUG 5/14Introduction to HBase - Phoenix HUG 5/14
Introduction to HBase - Phoenix HUG 5/14Jeremy Walsh
 
Apache Big Data EU 2015 - HBase
Apache Big Data EU 2015 - HBaseApache Big Data EU 2015 - HBase
Apache Big Data EU 2015 - HBaseNick Dimiduk
 
HBase from the Trenches - Phoenix Data Conference 2015
HBase from the Trenches - Phoenix Data Conference 2015HBase from the Trenches - Phoenix Data Conference 2015
HBase from the Trenches - Phoenix Data Conference 2015Avinash Ramineni
 
Intro to HBase - Lars George
Intro to HBase - Lars GeorgeIntro to HBase - Lars George
Intro to HBase - Lars GeorgeJAX London
 
HBaseConEast2016: HBase and Spark, State of the Art
HBaseConEast2016: HBase and Spark, State of the ArtHBaseConEast2016: HBase and Spark, State of the Art
HBaseConEast2016: HBase and Spark, State of the ArtMichael Stack
 
[Spark meetup] Spark Streaming Overview
[Spark meetup] Spark Streaming Overview[Spark meetup] Spark Streaming Overview
[Spark meetup] Spark Streaming OverviewStratio
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars GeorgeJAX London
 
Spark architecture
Spark architectureSpark architecture
Spark architecturedatamantra
 
Apache Big Data EU 2015 - Phoenix
Apache Big Data EU 2015 - PhoenixApache Big Data EU 2015 - Phoenix
Apache Big Data EU 2015 - PhoenixNick Dimiduk
 

Viewers also liked (20)

HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...
HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...
HBaseCon 2012 | Gap Inc Direct: Serving Apparel Catalog from HBase for Live W...
 
Apache HBase for Architects
Apache HBase for ArchitectsApache HBase for Architects
Apache HBase for Architects
 
Apache HBase Low Latency
Apache HBase Low LatencyApache HBase Low Latency
Apache HBase Low Latency
 
Introduction to Hadoop, HBase, and NoSQL
Introduction to Hadoop, HBase, and NoSQLIntroduction to Hadoop, HBase, and NoSQL
Introduction to Hadoop, HBase, and NoSQL
 
Apache Spark Overview
Apache Spark OverviewApache Spark Overview
Apache Spark Overview
 
HBase Low Latency, StrataNYC 2014
HBase Low Latency, StrataNYC 2014HBase Low Latency, StrataNYC 2014
HBase Low Latency, StrataNYC 2014
 
Bring Cartography to the Cloud
Bring Cartography to the CloudBring Cartography to the Cloud
Bring Cartography to the Cloud
 
HBase Data Types (WIP)
HBase Data Types (WIP)HBase Data Types (WIP)
HBase Data Types (WIP)
 
Strata + Hadoop World 2012: Apache HBase Features for the Enterprise
Strata + Hadoop World 2012: Apache HBase Features for the EnterpriseStrata + Hadoop World 2012: Apache HBase Features for the Enterprise
Strata + Hadoop World 2012: Apache HBase Features for the Enterprise
 
HBase Data Types
HBase Data TypesHBase Data Types
HBase Data Types
 
Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
 Let Spark Fly: Advantages and Use Cases for Spark on Hadoop Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
Let Spark Fly: Advantages and Use Cases for Spark on Hadoop
 
Introduction to HBase - Phoenix HUG 5/14
Introduction to HBase - Phoenix HUG 5/14Introduction to HBase - Phoenix HUG 5/14
Introduction to HBase - Phoenix HUG 5/14
 
Apache Big Data EU 2015 - HBase
Apache Big Data EU 2015 - HBaseApache Big Data EU 2015 - HBase
Apache Big Data EU 2015 - HBase
 
HBase from the Trenches - Phoenix Data Conference 2015
HBase from the Trenches - Phoenix Data Conference 2015HBase from the Trenches - Phoenix Data Conference 2015
HBase from the Trenches - Phoenix Data Conference 2015
 
Intro to HBase - Lars George
Intro to HBase - Lars GeorgeIntro to HBase - Lars George
Intro to HBase - Lars George
 
HBaseConEast2016: HBase and Spark, State of the Art
HBaseConEast2016: HBase and Spark, State of the ArtHBaseConEast2016: HBase and Spark, State of the Art
HBaseConEast2016: HBase and Spark, State of the Art
 
[Spark meetup] Spark Streaming Overview
[Spark meetup] Spark Streaming Overview[Spark meetup] Spark Streaming Overview
[Spark meetup] Spark Streaming Overview
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars George
 
Spark architecture
Spark architectureSpark architecture
Spark architecture
 
Apache Big Data EU 2015 - Phoenix
Apache Big Data EU 2015 - PhoenixApache Big Data EU 2015 - Phoenix
Apache Big Data EU 2015 - Phoenix
 

Similar to HBase Client API Options

RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueGleicon Moraes
 
Camel one v3-6
Camel one v3-6Camel one v3-6
Camel one v3-6wxdydx
 
Introduction To Apache Mesos
Introduction To Apache MesosIntroduction To Apache Mesos
Introduction To Apache MesosJoe Stein
 
Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19confluent
 
002 hbase clientapi
002 hbase clientapi002 hbase clientapi
002 hbase clientapiScott Miao
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Mathias Herberts
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012hwilming
 
Data Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache HadoopData Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache HadoopHikmat Dhamee
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemdelagoya
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門Tsuyoshi Yamamoto
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestPavan Chitumalla
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwrdeimos
 
#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)Ghadeer AlHasan
 
Mastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveMastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveVMware Tanzu
 
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...InfluxData
 
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...ScyllaDB
 

Similar to HBase Client API Options (20)

RestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message QueueRestMQ - HTTP/Redis based Message Queue
RestMQ - HTTP/Redis based Message Queue
 
Camel one v3-6
Camel one v3-6Camel one v3-6
Camel one v3-6
 
Introduction To Apache Mesos
Introduction To Apache MesosIntroduction To Apache Mesos
Introduction To Apache Mesos
 
Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19Kick your database_to_the_curb_reston_08_27_19
Kick your database_to_the_curb_reston_08_27_19
 
002 hbase clientapi
002 hbase clientapi002 hbase clientapi
002 hbase clientapi
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012
 
Data Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache HadoopData Processing with Cascading Java API on Apache Hadoop
Data Processing with Cascading Java API on Apache Hadoop
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problem
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 
Joe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand DwrJoe Walker Interactivewebsites Cometand Dwr
Joe Walker Interactivewebsites Cometand Dwr
 
#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)
 
Mastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveMastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura Bhave
 
Network
NetworkNetwork
Network
 
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...
Extending Flux to Support Other Databases and Data Stores | Adam Anthony | In...
 
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
Scylla Summit 2018: Introducing ValuStor, A Memcached Alternative Made to Run...
 

HBase Client API Options

  • 1. HBase Client API (for webapps?) Nick Dimiduk Seattle Scalability Meetup 2013-03-27 1
  • 2. 2
  • 3. 3
  • 4. What are my choices? switch (technology) { case ‘ ’: ... case ‘ ’: ... case ‘ ’: ... } 4
  • 6. Java client Interfaces • Configuration holds details where to find the cluster and tunable settings. Roughly equivalent to JDBC connection string. • HConnection represents connections to to the cluster. • HBaseAdmin handles DDL operations (create, list, drop, alter, &c.) • HTablePool connection pool for table handles. • HTable (HTableInterface) is a handle on a single HBase table. Send "commands" to the table (Put, Get, Scan, Delete, Increment) 6
  • 7. Java client Example public static final byte[] TABLE_NAME = Bytes.toBytes("twits"); public static final byte[] TWITS_FAM = Bytes.toBytes("twits"); public static final byte[] USER_COL = Bytes.toBytes("user"); public static final byte[] TWIT_COL = Bytes.toBytes("twit"); private HTablePool pool = new HTablePool(); https://github.com/hbaseinaction/twitbase/blob/master/src/main/java/HBaseIA/TwitBase/hbase/TwitsDAO.java#L23-L30 7
  • 8. Java client Example private static class Twit { private Twit(Result r) { this( r.getColumnLatest(TWITS_FAM, USER_COL).getValue(), Arrays.copyOfRange(r.getRow(), Md5Utils.MD5_LENGTH, Md5Utils.MD5_LENGTH + longLength), r.getColumnLatest(TWITS_FAM, TWIT_COL).getValue()); } private Twit(byte[] user, byte[] dt, byte[] text) { this( Bytes.toString(user), new DateTime(-1 * Bytes.toLong(dt)), Bytes.toString(text)); } https://github.com/hbaseinaction/twitbase/blob/master/src/main/java/HBaseIA/TwitBase/hbase/TwitsDAO.java#L129-L143 8
  • 9. Java client Example private static Get mkGet(String user, DateTime dt) { Get g = new Get(mkRowKey(user, dt)); g.addColumn(TWITS_FAM, USER_COL); g.addColumn(TWITS_FAM, TWIT_COL); return g; } https://github.com/hbaseinaction/twitbase/blob/master/src/main/java/HBaseIA/TwitBase/hbase/TwitsDAO.java#L60-L65 9
  • 10. Ruby, Python client Interface 10
  • 11. Ruby, Python client Interface Jyth on JRu by, : '( 11
  • 12. Thrift client Interface 1. Generate bindings 2. Run a “Gateway” between clients and cluster 3. ... profit? code! w rite 12
  • 13. HBase Cluster HBase Clients Sidebar: Architecture Recap 13
  • 14. Thrift Gateway HBase Cluster Thrift Clients Thrift Architecture 14
  • 15. Thrift client Interface • Thrift gateway exposes a client to RegionServers • stateless :D • ... except for scanners :'( 15
  • 16. Thrift client Example transport = TSocket.TSocket(host, port) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Hbase.Client(protocol) transport.open() https://github.com/hbaseinaction/twitbase.py/blob/master/TwitBase.py#L17-L21 16
  • 17. Thrift client Example columns = ['info:user','info:name','info:email'] scanner = client.scannerOpen('users', '', columns) row = client.scannerGet(scanner) while row: yield user_from_row(row[0]) row = scannerGet(scanner) client.scannerClose(scanner) https://github.com/hbaseinaction/twitbase.py/blob/master/TwitBase.py#L33-L39 17
  • 18. Thrift client Example def user_from_row(row): user = {} for col,cell in row.columns.items(): user[col[5:]] = cell.value return "<User: {user}, {name}, {email}>".format(**user) https://github.com/hbaseinaction/twitbase.py/blob/master/TwitBase.py#L26-L30 18
  • 19. REST client Interface 1. Stand up a "REST Gateway" between your application and the cluster 2. HTTP verbs translate (roughly) into table commands 3. decent support for basic DDL, HTable operations 19
  • 20. HBase Cluster REST REST Clients Gateway REST Architecture 20
  • 21. REST client Interface • REST gateway exposes a client to RegionServers • stateless :D • ... except for scanners :'( 21
  • 22. REST client Example $ curl -H "Accept: application/json" http://host:port/ { "table": [ { "name": "followers" }, { "name": "twits" }, { "name": "users" } ] } 22
  • 23. REST client Example $ curl -H ... http://host:port/table/row [/family:qualifier] { "Row": [ { "key": "VGhlUmVhbE1U", "Cell": [ { "$": "c2FtdWVsQGNsZW1lbnMub3Jn", "column": "aW5mbzplbWFpbA==", "timestamp": 1338701491422 }, { "$": "TWFyayBUd2Fpbg==", "column": "aW5mbzpuYW1l", "timestamp": 1338701491422 }, ] } ] } 23
  • 24. REST client Example <Rows> <Row key="VGhlUmVhbE1U"> <Cells> <Cell column="aW5mbzplbWFpbA==" timestamp="1338701491422"> c2FtdWVsQGNsZW1lbnMub3Jn </Cell> <Cell ...> ... </Cells> </Row> </Rows> 24
  • 26. asynchbase • Asynchronous non-blocking interface. • Inspired by Twisted Python. • Partial implementation of HTableInterface. • HBaseClient provides entry-point to data. https://github.com/OpenTSDB/asynchbase http://tsunanet.net/~tsuna/asynchbase/api/org/hbase/async/HBaseClient.html 26
  • 27. asynchbase UpdateResult object output to => [next state] 3 / Interpret input => [this state] response => [error state] Exception Boolean Put response UpdateFailed Exception 27
  • 28. asynchbase Example final Scanner scanner = client.newScanner(TABLE_NAME); scanner.setFamily(INFO_FAM); scanner.setQualifier(PASSWORD_COL); ArrayList<ArrayList<KeyValue>> rows = null; ArrayList<Deferred<Boolean>> workers = new ArrayList<Deferred<Boolean>>(); while ((rows = scanner.nextRows(1).joinUninterruptibly()) != null) { for (ArrayList<KeyValue> row : rows) { KeyValue kv = row.get(0); byte[] expected = kv.value(); String userId = new String(kv.key()); PutRequest put = new PutRequest( TABLE_NAME, kv.key(), kv.family(), kv.qualifier(), mkNewPassword(expected)); Deferred<Boolean> d = client.compareAndSet(put, expected) .addCallback(new InterpretResponse(userId)) .addCallbacks(new ResultToMessage(), new FailureToMessage()) .addCallback(new SendMessage()); workers.add(d); } } https://github.com/hbaseinaction/twitbase-async/blob/master/src/main/java/HBaseIA/TwitBase/AsyncUsersTool.java#L151-L173 28
  • 29. Others Reduce day-to-day Full-blown schema developer pain management [Orderly] Phoenix Spring-Data Hadoop Kiji.org https://github.com/ndimiduk/orderly http://www.springsource.org/spring-data/ https://github.com/forcedotcom/phoenix http://www.kiji.org/ 29
  • 30. Apache Futures • Protobuf wire messages (0.96) • C client (TBD, HBASE-1015) • HBase Types (TBD, HBASE-8089) 30
  • 32. Software Architecture • Isolate DAO from app logic, separation of concerns, &c. • Separate environment configs from code. • Watch out for resource contention. 32
  • 33. Deployment Architecture • Cache everywhere. • Know your component layers. 33
  • 34. HBase Warts • Know thy (HBase) version 0.{92,94,96} ! • long-running client bug (HBASE-4805). • Gateway APIs only as up to date as the people before you require. • REST API particularly unpleasant for “Web2.0” folk. 34
  • 35. Thanks! Nick Dimiduk github.com/ndimiduk @xefyr Nick Dimiduk Amandeep Khurana n10k.com FOREWORD BY Michael Stack MANNING hbaseinaction.com 35