SlideShare a Scribd company logo
HBase Coprocessor Intro.

   Anty Rao, Schubert Zhang
         Aug. 29 2012
Motivation
• Distributed and parallel computation over data stored within HBase/Bigtable.

• Architecture: {HBase + MapReduce} vs. {HBase with Coprocessor}
    – {Loosely coupled} vs. {Built in}
    – E.g., simple additive or aggregating operations like summing, counting, and the like –
      pushing the computation down to the servers where it can operate on the data
      directly without communication overheads can give a dramatic performance
      improvement over HBase’s already good scanning performance.

• To be a framework for both flexible and generic extension, and of distributed
  computation directly within the HBase server processes.
    – Arbitrary code can run at each tablet in each HBase server.
    – Provides a very flexible model for building distributed services.
    – Automatic scaling, load balancing, request routing for applications.
Motivation (cont.)
• To be a Data-Driven distributed and parallel service platform.
    – Distributed parallel computation framework.
    – Distributed application service platform.

• High-level call interface for clients
    – Calls are addressed to rows or ranges of rows and the coprocessor client library
      resolves them to actual locations;
    – Calls across multiple rows are automatically split into multiple parallelized RPC.

• Origin
    – Inspired by Google’s Bigtable Coprocessors.
    – Jeff Dean gave a talk at LADIS’09
        • http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf, page 66-67
HBase vs. Google Bigtable
• It is a framework that provides a library and runtime
  environment for executing user code within the HBase
  region server and master processes.

• Google coprocessors in contrast run co-located with the
  tablet server but outside of its address space.
  – https://issues.apache.org/jira/browse/HBASE-4047
Google’s Bigtable Coprocessors
Overview of HBase Coprocessor
• Tow scopes
    – System : loaded globally on all tables and regions.
    – Per-table: loaded on all regions for a table.

• Two types
    – Observers
        • Like triggers in conventional databases.
        • The idea behind observers is that we can insert user code by overriding upcall methods provided by the
          coprocessor framework. The callback functions are executed from core HBase code when certain events occur.
    – Endpoints
        • Dynamic PRC endpoints that resemble stored procedures.
        • One can invoke an endpoint at any time from the client. The endpoint implementation will then be executed
          remotely at the target region or regions, and results from those executions will be returned to the client.

• Difference of the tow types
    – Only endpoints return result to client.
Observers
• Currently, three observers interfaces provided
   – RegionObserver
       • Provides hooks for data manipulation events, Get, Put, Delete, Scan, and so on. There is
         an instance of a RegionObserver coprocessor for every table region and the scope of
         the observations they can make is constrained to that region
   – WALObserver
       • Provides hooks for write-ahead log (WAL) related operations. This is a way to observe
         or intercept WAL writing and reconstruction events. A WALObserver runs in the context
         of WAL processing. There is one such context per region server.
   – MasterObserver
       • Provides hooks for DDL-type operation, i.e., create, delete, modify table, etc. The
         MasterObserver runs within the context of the HBase master.

• Multiple Observers are chained to execute sequentially by order of
  assigned priorities.
Observers: Example
Observers: Example Code
package org.apache.hadoop.hbase.coprocessor;

import java.util.List;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Get;

// Sample access-control coprocessor. It utilizes RegionObserver
// and intercept preXXX() method to check user privilege for the given table
// and column family.
public class AccessControlCoprocessor extends BaseRegionObserver {
  @Override
  public void preGet(final ObserverContext<RegionCoprocessorEnvironment> c,
final Get get, final List<KeyValue> result) throws IOException
    throws IOException {

        // check permissions..
        if (!permissionGranted()) {
           throw new AccessDeniedException("User is not allowed to access.");
        }
    }

    // override prePut(), preDelete(), etc.
}
Endpoint
• Resembling stored procedures
• Invoke an endpoint at any time from the client.
• The endpoint implementation will then be executed
  remotely at the target region or regions.
• Result from those executions will be returned to the client.

• Code implementation
   – Endpoint is an interface for dynamic RPC extension.
Endpoints:
   How to implement a custom Coprocessor?
• Have a new protocol interface which extends CoprocessorProtocol.
• Implement the Endpoint interface and the new protocol interface . The
  implementation will be loaded into and executed from the region
  context.
   – Extend the abstract class BaseEndpointCoprocessor. This convenience class
     hide some internal details that the implementer need not necessary be
     concerned about, such as coprocessor class loading.
• On the client side, the Endpoints can be invoked by two new HBase
  client APIs:
   – Executing against a single region:
       • HTableInterface.coprocessorProxy(Class<T> protocol, byte[] row)
   – Executing against a range of regions:
       • HTableInterface.coprocessorExec(Class<T> protocol, byte[] startKey, byte[]
         endKey, Batch.Call<T,R> callable)
Endpoints: Example
                                Client Code
                         new Batch.Call (on all regions)                                   Region Server 1
                                                                                                                            Endpoint
          Batch.Call<ColumnAggregationProtocol, Long>()                                      tableA, , 12345678
          {                                                                                                         ColumnAggregationProtocol




                                                                                      .)
                                                                                     (..
              public Long call(ColumnAggregationProtocol instance)




                                                                                   or
              throws IOException




                                                                                 ss
                                                                                                                            Endpoint




                                                                                  e
                                                                               oc
              {                                                                            tableA, bbbb, 12345678




                                                                            pr
                return instance.sum(FAMILY, QUALIFIER);




                                                                          Co
                                                                                                                    ColumnAggregationProtocol




                                                                      ec
              }




                                                                     ex
            }



                                     HTable                                                Region Server 2
                                                                                                                            Endpoint
          Map<byte[], Long> sumResults =                                                   tableA, cccc, 12345678
          table.coprocessorExec(ColumnAggregationProtocol.class,                                                    ColumnAggregationProtocol
          startRow, endRow)
                                                                                                                            Endpoint
                                                                                           tableA, dddd, 12345678
                                                                                                                    ColumnAggregationProtocol
                                  Batch Results

                         Map<byte[], Long> sumResults




•   Note that the HBase client has the responsibility for dispatching parallel endpoint invocations to the
    target regions, and for collecting the returned results to present to the application code.
•   Like a lightweight MapReduce job: The “map” is the endpoint execution performed in the region
    server on every target region, and the “reduce” is the final aggregation at the client.
•   The distributed systems programming details behind a clean API.
Step-1: Define protocol interface
/**
 * A sample protocol for performing aggregation at regions.
 */
public interface ColumnAggregationProtocol extends CoprocessorProtocol
{
   /**
    * Perform aggregation for a given column at the region. The aggregation
    * will include all the rows inside the region. It can be extended to allow
    * passing start and end rows for a fine-grained aggregation.
    *
    * @param family
    *        family
    * @param qualifier
    *        qualifier
    * @return Aggregation of the column.
    * @throws exception.
    */
   public long sum(byte[] family, byte[] qualifier) throws IOException;
}
Step-2: Implement endpoint and the interface
                                                            try
public class ColumnAggregationEndpoint extends                    {
BaseEndpointCoprocessor                                            List<KeyValue> curVals = new ArrayList<KeyValue>();
    implements ColumnAggregationProtocol                           boolean done = false;
{                                                                  do
  @Override                                                        {
  public long sum(byte[] family, byte[] qualifier) throws             curVals.clear();
IOException                                                           done = scanner.next(curVals);
  {                                                                   KeyValue kv = curVals.get(0);
    // aggregate at each region                                       sumResult +=
    Scan scan = new Scan();                                 Bytes.toLong(kv.getBuffer(), kv.getValueOffset());
    scan.addColumn(family, qualifier);                             } while (done);
    long sumResult = 0;                                         }
                                                                finally
    InternalScanner scanner =                                   {
         ((RegionCoprocessorEnvironment)                           scanner.close();
getEnvironment()).getRegion()                                   }
             .getScanner(scan);                                 return sumResult;
                                                              }
                                                            }
Step-3 Deployment
• Two chooses
  – Load from configuration (hbase-site.xml, restart HBase)
  – Load from table attribute (disable and enable table)
     • From shell
Step-4: Invoking
                   HTable table = new HTable(util.getConfiguration(), TEST_TABLE);

• On client            Map<byte[], Long> results;

                       // scan: for all regions
  side, invoking       results =
                            table.coprocessorExec(ColumnAggregationProtocol.class,

  the endpoint                   ROWS[rowSeperator1 - 1], ROWS[rowSeperator2 + 1],
                                 new Batch.Call<ColumnAggregationProtocol, Long>()
                                 {
                                     public Long call(ColumnAggregationProtocol instance)
                                          throws IOException
                                     {
                                       return instance
                                            .sum(TEST_FAMILY, TEST_QUALIFIER);
                                     }
                                 });
                       long sumResult = 0;
                       long expectedResult = 0;
                       for (Map.Entry<byte[], Long> e : results.entrySet())
                       {
                          sumResult += e.getValue();
                       }
Server side execution
• Region Server             public interface HRegionInterface
  provide                   extends VersionedProtocol,
  environment to            Stoppable,Abortable
  execute custom
  coprocessor in            {
  region context.           …
• Exec                       ExecResult execCoprocessor(byte[]
   – Custom protocol        regionName, Exec call) throws
     name                   IOException;
   – Method name
                            …
   – Method
     parameters             }
Coprocessor Manangement
• Build your own Coprocessor
   – Write server-side coprocessor code like above example, compiled and
     packaged as a jar file.
      • CoprocessorProtocol (e.g. ColumnAggregationProtocol)
      • Endpoint implementation (e.g. ColumnAggregationEndpoint)
• Coprocessor Deployment
   – Load from Configuration (hbase-site.xml, restart HBase)
      • The jar file must be in classpath of HBase servers.
      • Global for all regions of all tables (system coprocessors).
   – Load from table attribute (from shell)
      • per table basis
      • The jar file should be put into HDFS or HBase servers’ classpath firstly, and set in
        the table attribute.
Future Work based on Coprocessors
•   Parallel Computation Framework (our first goal!)                    • Others
     – Higher level of abstraction
     – E.g. MapReduce APIs similar.                                        – External Coprocessor Host
     – Integration and implementation Dremel and/or dremel                   (HBASE-4047)
       computation model into HBase.
                                                                               • separate processes

•   Distributed application service platform (our second                   – Code Weaving (HBASE-2058)
    goal !?)                                                                   • protect against malicious actions
     – Higher level of abstraction                                               or faults accidentally introduced
     – Data-driven distributed application architecture.                         by a coprocessor.
     – Avoid building similar distributed architecture repeatedly.
                                                                           – …

•   HBase system enhancements
     – HBase internal measurements and statistics for administration.
•   Support application like percolator
     – Observes and notifications.
Reference
• https://blogs.apache.org/hbase/entry/coprocessor_intr
  oduction

More Related Content

What's hot (20)

PDF
HBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon
 
PDF
Tuning Java for Big Data
Scott Seighman
 
PPTX
Nov. 4, 2011 o reilly webcast-hbase- lars george
O'Reilly Media
 
PDF
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Spark Summit
 
PPTX
Hadoop world g1_gc_forh_base_v4
YanpingWang
 
PDF
HBaseCon 2013: Scalable Network Designs for Apache HBase
Cloudera, Inc.
 
PPTX
HBaseCon 2015: OpenTSDB and AsyncHBase Update
HBaseCon
 
PDF
HBaseCon2017 Removable singularity: a story of HBase upgrade in Pinterest
HBaseCon
 
PDF
Hbase Nosql
elliando dias
 
PDF
[RakutenTechConf2014] [D-4] The next step of LeoFS and Introducing NewDB Project
Rakuten Group, Inc.
 
PPTX
HBase and HDFS: Understanding FileSystem Usage in HBase
enissoz
 
PPTX
Hadoop Query Performance Smackdown
DataWorks Summit
 
PDF
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Masao Fujii
 
PDF
HBase tales from the trenches
wchevreuil
 
PDF
Background Tasks in Node - Evan Tahler, TaskRabbit
Redis Labs
 
PDF
PostgreSQL Extensions: A deeper look
Jignesh Shah
 
PPTX
PostgreSQL Terminology
Showmax Engineering
 
PDF
003 admin featuresandclients
Scott Miao
 
PDF
PGPool-II Load testing
EDB
 
PPT
8a. How To Setup HBase with Docker
Fabio Fumarola
 
HBaseCon2017 Improving HBase availability in a multi tenant environment
HBaseCon
 
Tuning Java for Big Data
Scott Seighman
 
Nov. 4, 2011 o reilly webcast-hbase- lars george
O'Reilly Media
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Spark Summit
 
Hadoop world g1_gc_forh_base_v4
YanpingWang
 
HBaseCon 2013: Scalable Network Designs for Apache HBase
Cloudera, Inc.
 
HBaseCon 2015: OpenTSDB and AsyncHBase Update
HBaseCon
 
HBaseCon2017 Removable singularity: a story of HBase upgrade in Pinterest
HBaseCon
 
Hbase Nosql
elliando dias
 
[RakutenTechConf2014] [D-4] The next step of LeoFS and Introducing NewDB Project
Rakuten Group, Inc.
 
HBase and HDFS: Understanding FileSystem Usage in HBase
enissoz
 
Hadoop Query Performance Smackdown
DataWorks Summit
 
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Masao Fujii
 
HBase tales from the trenches
wchevreuil
 
Background Tasks in Node - Evan Tahler, TaskRabbit
Redis Labs
 
PostgreSQL Extensions: A deeper look
Jignesh Shah
 
PostgreSQL Terminology
Showmax Engineering
 
003 admin featuresandclients
Scott Miao
 
PGPool-II Load testing
EDB
 
8a. How To Setup HBase with Docker
Fabio Fumarola
 

Similar to HBase Coprocessor Introduction (20)

PDF
HBase Coprocessors @ HUG NYC
mlai
 
PDF
Beyond Map/Reduce: Getting Creative With Parallel Processing
Ed Kohlwey
 
PDF
Betting On Data Grids
gojkoadzic
 
PDF
Transactions Over Apache HBase
alexbaranau
 
PDF
Online Analytics with Hadoop and Cassandra
Robbie Strickland
 
PPT
Leveraging Hadoop in your PostgreSQL Environment
Jim Mlodgenski
 
PDF
Spark and shark
DataWorks Summit
 
PPTX
TriHUG January 2012 Talk by Chris Shain
trihug
 
PDF
HBase Client APIs (for webapps?)
Nick Dimiduk
 
PPTX
Hadoop and HBase experiences in perf log project
Mao Geng
 
PDF
HBaseCon 2012 | HBase Coprocessors – Deploy Shared Functionality Directly on ...
Cloudera, Inc.
 
PDF
HBase Advanced - Lars George
JAX London
 
PDF
Storing and manipulating graphs in HBase
Dan Lynn
 
PDF
HBaseCon 2012 | Storing and Manipulating Graphs in HBase
Cloudera, Inc.
 
PPTX
002 hbase clientapi
Scott Miao
 
PDF
Hbase schema design and sizing apache-con europe - nov 2012
Chris Huang
 
PDF
HBaseCon 2012 | HBase Security for the Enterprise - Andrew Purtell, Trend Micro
Cloudera, Inc.
 
PDF
Transactions Over Apache HBase
Cask Data
 
PDF
HBase 0.20.0 Performance Evaluation
Schubert Zhang
 
PDF
Making Big Data Analytics Interactive and Real-­Time
Seven Nguyen
 
HBase Coprocessors @ HUG NYC
mlai
 
Beyond Map/Reduce: Getting Creative With Parallel Processing
Ed Kohlwey
 
Betting On Data Grids
gojkoadzic
 
Transactions Over Apache HBase
alexbaranau
 
Online Analytics with Hadoop and Cassandra
Robbie Strickland
 
Leveraging Hadoop in your PostgreSQL Environment
Jim Mlodgenski
 
Spark and shark
DataWorks Summit
 
TriHUG January 2012 Talk by Chris Shain
trihug
 
HBase Client APIs (for webapps?)
Nick Dimiduk
 
Hadoop and HBase experiences in perf log project
Mao Geng
 
HBaseCon 2012 | HBase Coprocessors – Deploy Shared Functionality Directly on ...
Cloudera, Inc.
 
HBase Advanced - Lars George
JAX London
 
Storing and manipulating graphs in HBase
Dan Lynn
 
HBaseCon 2012 | Storing and Manipulating Graphs in HBase
Cloudera, Inc.
 
002 hbase clientapi
Scott Miao
 
Hbase schema design and sizing apache-con europe - nov 2012
Chris Huang
 
HBaseCon 2012 | HBase Security for the Enterprise - Andrew Purtell, Trend Micro
Cloudera, Inc.
 
Transactions Over Apache HBase
Cask Data
 
HBase 0.20.0 Performance Evaluation
Schubert Zhang
 
Making Big Data Analytics Interactive and Real-­Time
Seven Nguyen
 
Ad

More from Schubert Zhang (20)

PDF
Blockchain in Action
Schubert Zhang
 
PDF
科普区块链
Schubert Zhang
 
PDF
Engineering Culture and Infrastructure
Schubert Zhang
 
PDF
Simple practices in performance monitoring and evaluation
Schubert Zhang
 
PPTX
Scrum Agile Development
Schubert Zhang
 
PPTX
Career Advice
Schubert Zhang
 
PDF
Engineering practices in big data storage and processing
Schubert Zhang
 
PPTX
HiveServer2
Schubert Zhang
 
PPTX
Horizon for Big Data
Schubert Zhang
 
PDF
Bigtable数据模型解决CDR清单存储问题的资源估算
Schubert Zhang
 
PPTX
Big Data Engineering Team Meeting 20120223a
Schubert Zhang
 
PDF
Hadoop大数据实践经验
Schubert Zhang
 
PPTX
Wild Thinking of BigdataBase
Schubert Zhang
 
PDF
RockStor - A Cloud Object System based on Hadoop
Schubert Zhang
 
PPTX
Fans of running gump
Schubert Zhang
 
PDF
Hadoop compress-stream
Schubert Zhang
 
PDF
Ganglia轻度使用指南
Schubert Zhang
 
PDF
DaStor/Cassandra report for CDR solution
Schubert Zhang
 
PPTX
Big data and cloud
Schubert Zhang
 
PDF
Learning from google megastore (Part-1)
Schubert Zhang
 
Blockchain in Action
Schubert Zhang
 
科普区块链
Schubert Zhang
 
Engineering Culture and Infrastructure
Schubert Zhang
 
Simple practices in performance monitoring and evaluation
Schubert Zhang
 
Scrum Agile Development
Schubert Zhang
 
Career Advice
Schubert Zhang
 
Engineering practices in big data storage and processing
Schubert Zhang
 
HiveServer2
Schubert Zhang
 
Horizon for Big Data
Schubert Zhang
 
Bigtable数据模型解决CDR清单存储问题的资源估算
Schubert Zhang
 
Big Data Engineering Team Meeting 20120223a
Schubert Zhang
 
Hadoop大数据实践经验
Schubert Zhang
 
Wild Thinking of BigdataBase
Schubert Zhang
 
RockStor - A Cloud Object System based on Hadoop
Schubert Zhang
 
Fans of running gump
Schubert Zhang
 
Hadoop compress-stream
Schubert Zhang
 
Ganglia轻度使用指南
Schubert Zhang
 
DaStor/Cassandra report for CDR solution
Schubert Zhang
 
Big data and cloud
Schubert Zhang
 
Learning from google megastore (Part-1)
Schubert Zhang
 
Ad

Recently uploaded (20)

PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
July Patch Tuesday
Ivanti
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 

HBase Coprocessor Introduction

  • 1. HBase Coprocessor Intro. Anty Rao, Schubert Zhang Aug. 29 2012
  • 2. Motivation • Distributed and parallel computation over data stored within HBase/Bigtable. • Architecture: {HBase + MapReduce} vs. {HBase with Coprocessor} – {Loosely coupled} vs. {Built in} – E.g., simple additive or aggregating operations like summing, counting, and the like – pushing the computation down to the servers where it can operate on the data directly without communication overheads can give a dramatic performance improvement over HBase’s already good scanning performance. • To be a framework for both flexible and generic extension, and of distributed computation directly within the HBase server processes. – Arbitrary code can run at each tablet in each HBase server. – Provides a very flexible model for building distributed services. – Automatic scaling, load balancing, request routing for applications.
  • 3. Motivation (cont.) • To be a Data-Driven distributed and parallel service platform. – Distributed parallel computation framework. – Distributed application service platform. • High-level call interface for clients – Calls are addressed to rows or ranges of rows and the coprocessor client library resolves them to actual locations; – Calls across multiple rows are automatically split into multiple parallelized RPC. • Origin – Inspired by Google’s Bigtable Coprocessors. – Jeff Dean gave a talk at LADIS’09 • http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf, page 66-67
  • 4. HBase vs. Google Bigtable • It is a framework that provides a library and runtime environment for executing user code within the HBase region server and master processes. • Google coprocessors in contrast run co-located with the tablet server but outside of its address space. – https://issues.apache.org/jira/browse/HBASE-4047
  • 6. Overview of HBase Coprocessor • Tow scopes – System : loaded globally on all tables and regions. – Per-table: loaded on all regions for a table. • Two types – Observers • Like triggers in conventional databases. • The idea behind observers is that we can insert user code by overriding upcall methods provided by the coprocessor framework. The callback functions are executed from core HBase code when certain events occur. – Endpoints • Dynamic PRC endpoints that resemble stored procedures. • One can invoke an endpoint at any time from the client. The endpoint implementation will then be executed remotely at the target region or regions, and results from those executions will be returned to the client. • Difference of the tow types – Only endpoints return result to client.
  • 7. Observers • Currently, three observers interfaces provided – RegionObserver • Provides hooks for data manipulation events, Get, Put, Delete, Scan, and so on. There is an instance of a RegionObserver coprocessor for every table region and the scope of the observations they can make is constrained to that region – WALObserver • Provides hooks for write-ahead log (WAL) related operations. This is a way to observe or intercept WAL writing and reconstruction events. A WALObserver runs in the context of WAL processing. There is one such context per region server. – MasterObserver • Provides hooks for DDL-type operation, i.e., create, delete, modify table, etc. The MasterObserver runs within the context of the HBase master. • Multiple Observers are chained to execute sequentially by order of assigned priorities.
  • 9. Observers: Example Code package org.apache.hadoop.hbase.coprocessor; import java.util.List; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Get; // Sample access-control coprocessor. It utilizes RegionObserver // and intercept preXXX() method to check user privilege for the given table // and column family. public class AccessControlCoprocessor extends BaseRegionObserver { @Override public void preGet(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<KeyValue> result) throws IOException throws IOException { // check permissions.. if (!permissionGranted()) { throw new AccessDeniedException("User is not allowed to access."); } } // override prePut(), preDelete(), etc. }
  • 10. Endpoint • Resembling stored procedures • Invoke an endpoint at any time from the client. • The endpoint implementation will then be executed remotely at the target region or regions. • Result from those executions will be returned to the client. • Code implementation – Endpoint is an interface for dynamic RPC extension.
  • 11. Endpoints: How to implement a custom Coprocessor? • Have a new protocol interface which extends CoprocessorProtocol. • Implement the Endpoint interface and the new protocol interface . The implementation will be loaded into and executed from the region context. – Extend the abstract class BaseEndpointCoprocessor. This convenience class hide some internal details that the implementer need not necessary be concerned about, such as coprocessor class loading. • On the client side, the Endpoints can be invoked by two new HBase client APIs: – Executing against a single region: • HTableInterface.coprocessorProxy(Class<T> protocol, byte[] row) – Executing against a range of regions: • HTableInterface.coprocessorExec(Class<T> protocol, byte[] startKey, byte[] endKey, Batch.Call<T,R> callable)
  • 12. Endpoints: Example Client Code new Batch.Call (on all regions) Region Server 1 Endpoint Batch.Call<ColumnAggregationProtocol, Long>() tableA, , 12345678 { ColumnAggregationProtocol .) (.. public Long call(ColumnAggregationProtocol instance) or throws IOException ss Endpoint e oc { tableA, bbbb, 12345678 pr return instance.sum(FAMILY, QUALIFIER); Co ColumnAggregationProtocol ec } ex } HTable Region Server 2 Endpoint Map<byte[], Long> sumResults = tableA, cccc, 12345678 table.coprocessorExec(ColumnAggregationProtocol.class, ColumnAggregationProtocol startRow, endRow) Endpoint tableA, dddd, 12345678 ColumnAggregationProtocol Batch Results Map<byte[], Long> sumResults • Note that the HBase client has the responsibility for dispatching parallel endpoint invocations to the target regions, and for collecting the returned results to present to the application code. • Like a lightweight MapReduce job: The “map” is the endpoint execution performed in the region server on every target region, and the “reduce” is the final aggregation at the client. • The distributed systems programming details behind a clean API.
  • 13. Step-1: Define protocol interface /** * A sample protocol for performing aggregation at regions. */ public interface ColumnAggregationProtocol extends CoprocessorProtocol { /** * Perform aggregation for a given column at the region. The aggregation * will include all the rows inside the region. It can be extended to allow * passing start and end rows for a fine-grained aggregation. * * @param family * family * @param qualifier * qualifier * @return Aggregation of the column. * @throws exception. */ public long sum(byte[] family, byte[] qualifier) throws IOException; }
  • 14. Step-2: Implement endpoint and the interface try public class ColumnAggregationEndpoint extends { BaseEndpointCoprocessor List<KeyValue> curVals = new ArrayList<KeyValue>(); implements ColumnAggregationProtocol boolean done = false; { do @Override { public long sum(byte[] family, byte[] qualifier) throws curVals.clear(); IOException done = scanner.next(curVals); { KeyValue kv = curVals.get(0); // aggregate at each region sumResult += Scan scan = new Scan(); Bytes.toLong(kv.getBuffer(), kv.getValueOffset()); scan.addColumn(family, qualifier); } while (done); long sumResult = 0; } finally InternalScanner scanner = { ((RegionCoprocessorEnvironment) scanner.close(); getEnvironment()).getRegion() } .getScanner(scan); return sumResult; } }
  • 15. Step-3 Deployment • Two chooses – Load from configuration (hbase-site.xml, restart HBase) – Load from table attribute (disable and enable table) • From shell
  • 16. Step-4: Invoking HTable table = new HTable(util.getConfiguration(), TEST_TABLE); • On client Map<byte[], Long> results; // scan: for all regions side, invoking results = table.coprocessorExec(ColumnAggregationProtocol.class, the endpoint ROWS[rowSeperator1 - 1], ROWS[rowSeperator2 + 1], new Batch.Call<ColumnAggregationProtocol, Long>() { public Long call(ColumnAggregationProtocol instance) throws IOException { return instance .sum(TEST_FAMILY, TEST_QUALIFIER); } }); long sumResult = 0; long expectedResult = 0; for (Map.Entry<byte[], Long> e : results.entrySet()) { sumResult += e.getValue(); }
  • 17. Server side execution • Region Server public interface HRegionInterface provide extends VersionedProtocol, environment to Stoppable,Abortable execute custom coprocessor in { region context. … • Exec ExecResult execCoprocessor(byte[] – Custom protocol regionName, Exec call) throws name IOException; – Method name … – Method parameters }
  • 18. Coprocessor Manangement • Build your own Coprocessor – Write server-side coprocessor code like above example, compiled and packaged as a jar file. • CoprocessorProtocol (e.g. ColumnAggregationProtocol) • Endpoint implementation (e.g. ColumnAggregationEndpoint) • Coprocessor Deployment – Load from Configuration (hbase-site.xml, restart HBase) • The jar file must be in classpath of HBase servers. • Global for all regions of all tables (system coprocessors). – Load from table attribute (from shell) • per table basis • The jar file should be put into HDFS or HBase servers’ classpath firstly, and set in the table attribute.
  • 19. Future Work based on Coprocessors • Parallel Computation Framework (our first goal!) • Others – Higher level of abstraction – E.g. MapReduce APIs similar. – External Coprocessor Host – Integration and implementation Dremel and/or dremel (HBASE-4047) computation model into HBase. • separate processes • Distributed application service platform (our second – Code Weaving (HBASE-2058) goal !?) • protect against malicious actions – Higher level of abstraction or faults accidentally introduced – Data-driven distributed application architecture. by a coprocessor. – Avoid building similar distributed architecture repeatedly. – … • HBase system enhancements – HBase internal measurements and statistics for administration. • Support application like percolator – Observes and notifications.