HBase常用写入数据方式
1、使用MapReduce作业中的TableOutputformat类 //context.write(new ImmutableBytesWritable(Bytes.toBytes(rowkey)), put)
2、使用客户端API //table.put(put)
然而,这些方法并不总是最有效的方法。
BulkLoad
bulkload方式:mapreduce按hbase内部数据格式 在hdfs上 直接生成StoreFile,然后将StoreFile加载到hbase集群中。
优点:
1.因为数据直接写文件,速度上比HBase API方式快很多。
2.只需更少的cpu、IO、网络资源等。
实施
第一步、生成StoreFile文件
mapreduce job以HFileOutputFormat2为OutputFormat,在map阶段将数据(格式可以KeyValue/Put/Text)以hbase内部存储格式写到hdfs上,以便于后续高效的将文件纳入到hbase集群中。
第二步、将StoreFile加载到HBase集群
1、命令行:hadoop jar hbase-server-VERSION.jar completebulkload [-c /path/to/hbase/config/hbase-site.xml] /user/todd/myoutput $mytable
2、java代码编程导入使用LoadIncrementalHFiles。