`
zhangxiong0301
  • 浏览: 357202 次
社区版块
存档分类
最新评论

How-to: Use HBase Bulk Loading, and Why

 
阅读更多

 

 

Hbase对外提供随机、实时的读写访问大数据,但问题是首先需要高效的把数据导入HBASE。通常我们通过mapreduce任务以及设置TableOutputFormat来调用hbase API导入数据。但是这样需要经过hbasewritepath:写数据到memstore,写WALflush数据,以及splitcompact。因此更好的方式是即将介绍的BULKLOAD

 

当我们在hbase使用中碰到以下特征时,可以考虑使用BULKLOAD:

·  You needed to tweak your MemStores to use most of the memory.
·  You needed to either use bigger WALs or bypass them entirely.
·  Your compaction and flush queues are in the hundreds.
·  Your GC is out of control because your inserts range in the MBs.
·  Your latency goes out of your SLA when you import data.

 

 

BULKLOAD就是生成HFILE,直接加载HFILEregionserver的过程,从而绕过writepath

 

bulk loading is the process of preparing and loading HFiles (HBase’s own file format) directly into the RegionServers, thus bypassing the write path and obviating those issues entirely. 

 

 

BULKLOAD的步骤

 

1.  Extract the data from a source, typically text files or another database(准备数据).这个步骤叫准备数据,hbase不会参与其中,需要我们自己用mysqldump等工具将待导入数据提取出来,并上传到HDFS,为后续步骤做好准备。

 

2.   Transform the data into Hfiles(生成HFile.这个步骤是BULKLOAD的核心,通常由一个mapreduce任务为每个region生成一个Hfile。这个mapreduce很多场景下需要我们自己实现map。当然如果默认的map能满足条件的话就不需要自定义mapper,这种情况主要对应tsv文件中的每行的各个字段跟hbase中列完全对应(包括rowkey)。Mapreduce任务的输出键必须是rowkey,值必须是KeyValue, Put, orDelete之一。Reducer是完全由HBASE控制的,主要通过HFileOutputFormat.configureIncrementalLoad() 来完成,这个方法做了很多事:

 

·  Inspects the table to configure a total order partitioner
·  Uploads the partitions file to the cluster and adds it to the    DistributedCache
·  Sets the number of reduce tasks to match the current number of    regions
·  Sets the output key/value class to match HFileOutputFormat’s requirements
·  Sets the reducer up to perform the appropriate sorting (either KeyValueSortReducer or PutSortReducer)

 

3. Load the files into HBase by telling the RegionServers where to find them(加载HFile)。很简单,只需使用LoadIncrementalHFiles (通常叫做 completebulkload)。只需要指定刚生成的Hfile所在的文件夹,就可以直接把各个文件加载到对应的region。有一种情况是,当我们生成好Hfile但还没有导入进Hbase时,目标表发生了split,我们的工具也能在加载Hfile到表的时候自动将Hfile拆分到对应的region,只是不太高效,所以如果在我们的BULKLOAD过程中有其他进程在写目标表,则应该尽快将Hfile加载到hbase

 

 

 

使用场景

1.  原始数据导入(Original dataset load)。这种场景主要是从其他存储系统迁移数据到hbase。我们先要创建好表,并进行预分区,预分区的splitKey需要考虑rowkey的分布和region的数量。

2. 增量导入(Incremental load)。当hbase中某张表已经在对外提供服务,但是我们需要再导入一部分数据到这张表时,就是这种场景

 

 

使用案例

1.    直接导入假如有一个wordcountTSV文件需要导入hbase,每一行的格式为[wordcount]Hbase表则设计为:wordrowkeycount为唯一的一列。则操作步骤如下:

 上传CSVTSV文件:

                    hdfs dfs-put word_count.csv

 

预分区方式创建好表:

     create'wordcount',{NAME=>'f'},   {SPLITS=>['g','m','r','w']}

 

生成Hfile,需要注意的是如果不指定importtsv.bulk.output则会直接将数据写入hbaseHBASE_ROW_KEY代表rowkey,是约定好的。如果想了解这个命令的用法,则输入命令不加参数,然后回车。

./bin/hbase org.apache.hadoop.hbase.mapreduce.Driver importtsv -Dimporttsv.separator=, -Dimporttsv.bulk.output=/user/hadoop/wordcount/ -Dimporttsv.columns=HBASE_ROW_KEY,f:count wordcount /user/hadoop/word_count.csv

 

执行完命令,则会看见目标目录下已经生成对应分区的Hfile

Found 5 items
-rw-r--r--   3 hadoop supergroup      10201 2015-06-26 10:36 /user/hadoop/wordcount/f/558cfca392a945e9acf7abb5851d50c9
-rw-r--r--   3 hadoop supergroup       7468 2015-06-26 10:36 /user/hadoop/wordcount/f/61e199926f2347a9a444d2a7ad1ffeb3
-rw-r--r--   3 hadoop supergroup       6311 2015-06-26 10:36 /user/hadoop/wordcount/f/b559aa29e7074a5fb79c2ffa746f1717
-rw-r--r--   3 hadoop supergroup       5529 2015-06-26 10:36 /user/hadoop/wordcount/f/d34d5903715e423f99eef210cc3c5123
-rw-r--r--   3 hadoop supergroup       2383 2015-06-26 10:36 /user/hadoop/wordcount/f/d570e72200114d39896632808095b6c9

 

 

加载数据到hbase

./bin/hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles /user/hadoop/wordcount/ wordcount

 

 

 

2自定义Mapreduce的导入。这种导入也很简单,只要自己实现一个mapper以及Driver就                行,reduce可通过上文所述的调HFileOutputFormat.configureIncrementalLoad(job,hTable)       方法,由hbase实现。所以HFileOutputFormat.configureIncrementalLoad实际上实现了                  除mapper之外的shufflereducer逻辑。因此,执行hadoop jar命令完成mareduce任务即生         成额Hfile。假如以FACEBOOK 2010NBA决赛消息为TSV,则过程如下:

 

   1.上传TSV以及建表,同[直接导入]的步骤12

 

   2.mapreduce任务,实际上[直接导入]方式的步骤3也是跑的mapreduce。参数只需要csv数         据文件路径,输出路径以及hbase对应的表名。

 

       hadoop jar my_map_reduce.jar com.my.mapreduce.Driver data.csvoutput_dir NBAFinal2010_tableName

 

   3.加载数据

 

  Hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles output_dirNBAFinal2010_tableName

   

   附件是自定义的mapreduce代码

 

 

分享到:
评论

相关推荐

    hbase-annotations-1.1.2-API文档-中文版.zip

    赠送jar包:hbase-annotations-1.1.2.jar; 赠送原API文档:hbase-annotations-1.1.2-javadoc.jar; 赠送源代码:hbase-annotations-1.1.2-sources.jar; 赠送Maven依赖信息文件:hbase-annotations-1.1.2.pom; ...

    phoenix-core-4.7.0-HBase-1.1-API文档-中文版.zip

    赠送jar包:phoenix-core-4.7.0-HBase-1.1.jar; 赠送原API文档:phoenix-core-4.7.0-HBase-1.1-javadoc.jar; 赠送源代码:phoenix-core-4.7.0-HBase-1.1-sources.jar; 赠送Maven依赖信息文件:phoenix-core-4.7.0...

    hbase-operator-tools:Apache HBase操作员工具

    hbase-operator-tools 操作员工具的主机,包括: ,hbase-2.x修复工具,是hbase-1的hbck (AKA hbck1 )的后继者。 ,一种用于生成有关Table列数和行大小的基本报告的工具; 在没有可用的分布式执行时使用。

    hbase-cdh5:Hbase-cloudera Docker

    CDH版本:cdh5.1 java:jdk7u67(64位) HBase模式:伪分布式裸露端口动物园管理员服务器:2181 hbase-master:65000 hbase-master Web UI:65010 hbase-regionserver:65020 hbase-regionserver Web UI:65030如何...

    spring-boot-starter-hbase:Spring Boot Starter HBase的

    自定义的spring-boot的hbase starter,为hbase的query和更新等操作提供简易的api并集成spring-boot的auto configuration 版本 本项目版本 hbase版本 1.0.0 hbase1.1.2 打包 修改相关的maven私服地址 gradle clean ...

    apache-phoenix-5.0.0-HBase-2.0-bin.tar.gz

    Apache Phoenix是构建在HBase之上的关系型数据库层,作为内嵌的客户端JDBC驱动用以对HBase中的数据进行低延迟访问。Apache Phoenix会将用户编写的sql查询编译为一系列的scan操作,最终产生通用的JDBC结果集返回给...

    HBase-SparkStreaming:从HBase表读取并写入HBase表的简单Spark Streaming项目

    HBase-SparkStreaming 从HBase表读取并写入HBase表的简单Spark Streaming项目 #Prereqs运行 创建一个要写入的hbase表:a)启动hbase shell $ hbase shell b)创建表create'/ user / chanumolu / sensor',{NAME =>'...

    hbase-connectors:Apache HBase连接器

    "hbase-connectors"项目则提供了与HBase交互的不同方式,使得开发者可以方便地将HBase集成到各种应用程序中。以下是关于HBase连接器的一些关键知识点: 1. **HBase连接器的作用**: - HBase连接器是连接应用程序和...

    hbase-common-1.4.3-API文档-中文版.zip

    赠送jar包:hbase-common-1.4.3.jar; 赠送原API文档:hbase-common-1.4.3-javadoc.jar; 赠送源代码:hbase-common-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-common-1.4.3.pom; 包含翻译后的API文档:...

    hbase-exporter:HBase Prometheus导出器

    hbase-exporterHBase Prometheus导出器收集指标并中继JMX指标以供Prometheus使用由于JMX中一些重要的指标缺失或为空,因此我们另外分析了HBase主界面,例如“过渡中的过时区域” 解析“ hbase hbck”命令的输出以...

    AMWU-大数据一:hello HBase (HBase1.03伪单机版本安装,Windows7 JAVA远程调用

    HBase AMWU-大数据一:hello HBase (HBase1.03伪单机版本安装,Windows7 JAVA远程调用)

    hbase-packet-inspector:分析HBase RegionServers的网络流量

    hbase-packet-inspector hbase-packet-inspector (HPI)是用于分析HBase RegionServers网络流量的命令行工具。 HPI读取tcpdump文件或捕获网络接口的实时数据包流,以提取有关客户端请求和响应的信息。 您可以对其...

    大数据安全-kerberos技术-hbase安装包,hbase版本:hbase-2.2.6-bin.tar.gz

    2. **配置HBase**:修改HBase的配置文件(如`hbase-site.xml`),设置`hbase.security.authentication`为`kerberos`,并提供Kerberos相关属性,如`hbase.kerberos.keytab.file`和`hbase.kerberos.principal`。...

    spark-sql-hbase:Spark SQL HBase 连接器

    #Spark SQL HBase Connector##----------------Note: This Project is Deprecated---------------##--------------And This Project is Not Maintained---------------Spark SQL HBase Connector aim to query HBase...

    phoenix-core-4.7.0-HBase-1.1-API文档-中英对照版.zip

    赠送jar包:phoenix-core-4.7.0-HBase-1.1.jar; 赠送原API文档:phoenix-core-4.7.0-HBase-1.1-javadoc.jar; 赠送源代码:phoenix-core-4.7.0-HBase-1.1-sources.jar; 赠送Maven依赖信息文件:phoenix-core-4.7.0...

    Bigram-Counting-with-HBase:使用 HBase 进行 Bigram 计数

    根据提供的压缩包文件名“Bigram-Counting-with-HBase-master”,项目可能包含以下部分: 1. `src/main/java`: 存放Java源代码,包括HBase连接、Bigram处理和计数逻辑。 2. `pom.xml`: Maven配置文件,定义项目依赖...

    hbase-meta-repair-hbase-2.0.2.jar

    HBase 元数据修复工具包。 ①修改 jar 包中的application.properties,重点是 zookeeper.address、zookeeper.nodeParent、hdfs....③开始修复 `java -jar -Drepair.tableName=表名 hbase-meta-repair-hbase-2.0.2.jar`

    hbase-2.4.16-bin.tar.gz

    hbase官网下载地址(官网下载太慢): https://downloads.apache.org/hbase/ 国内镜像hbase-2.4.16: https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/2.4.16/hbase-2.4.16-bin.tar.gz

    hbase-metrics-api-1.4.3-API文档-中文版.zip

    赠送jar包:hbase-metrics-api-1.4.3.jar; 赠送原API文档:hbase-metrics-api-1.4.3-javadoc.jar; 赠送源代码:hbase-metrics-api-1.4.3-sources.jar; 赠送Maven依赖信息文件:hbase-metrics-api-1.4.3.pom; ...

Global site tag (gtag.js) - Google Analytics