hbase bulk load相关源码简析之HFileOutputFormat、LoadIncrementalHFiles
来源:互联网 发布:媒体的作用 知乎 编辑:程序博客网 时间:2024/06/01 09:20
转载请注明出处: http://blog.csdn.net/lonelytrooper/article/details/17040895
PutSortReducer:
- // 对map阶段传递过来的puts中的KVs做排序,并将有序的KVs写到输出流(最终写的类是HFileWriterV1或HFileWriterV2的append方法)...
- public class PutSortReducer extends
- Reducer<ImmutableBytesWritable, Put, ImmutableBytesWritable, KeyValue> {
- @Override
- protected void reduce(ImmutableBytesWritable row, java.lang.Iterable<Put> puts,
- Reducer<ImmutableBytesWritable, Put, ImmutableBytesWritable, KeyValue>.Context context)
- throws java.io.IOException, InterruptedException {
- // although reduce() is called per-row, handle pathological case
- // 设定一个RAM的阀值,用于应对非常规的情况.. 默认值2L * (1 << 30)为Integer.MAX_VALUE+1
- long threshold = context.getConfiguration().getLong("putsortreducer.row.threshold",
- 2L * (1 << 30));
- Iterator<Put> iter = puts.iterator();
- while (iter.hasNext()) {
- TreeSet<KeyValue> map = new TreeSet<KeyValue>(KeyValue.COMPARATOR); // KVComparator
- long curSize = 0;
- // stop at the end or the RAM threshold
- // 用curSize累计当前puts的size,但这个size不能超过threshold...
- while (iter.hasNext() && curSize < threshold) {
- Put p = iter.next();
- for (List<KeyValue> kvs : p.getFamilyMap().values()) {
- for (KeyValue kv : kvs) {
- map.add(kv);
- curSize += kv.getLength();
- }
- }
- }
- // 记录已读取的map中的KV的个数,并将curSize转成易读的KB,MB,GB..
- context.setStatus("Read " + map.size() + " entries of " + map.getClass() + "("
- + StringUtils.humanReadableInt(curSize) + ")");
- int index = 0;
- // 将当前有序的KV写到输出流..
- for (KeyValue kv : map) {
- context.write(row, kv);
- if (index > 0 && index % 100 == 0) // 记录进度,每100个记录一次..
- context.setStatus("Wrote " + index);
- }
- // if we have more entries to process
- //如果居然还有put没处理完..我们会通过context.write(null, null)强刷.. 这会关闭当前的Writer(StoreFile.Writer),并形成了一个StoreFile。
- //在外层的下次循环中,会继续处理余下的数据,并创建新的StoreFile的Writer。 换言之,这种情况下相同rowkey的数据会被写到不同的StoreFile中...
- //细节部分可以看下HFileOutputFormat下RecordWriter类下的write方法..
- if (iter.hasNext()) {
- // force flush because we cannot guarantee intra-row sorted
- // order
- context.write(null, null);
- }
- }
- }
- }
KeyValueSortReducer:
- // 类比PutSortReducer,对map传递过来的KVs进行排序,并将有序的KVs写到输出流...
- // 如果一行包含的列非常多的话,有oom的风险..
- public class KeyValueSortReducer extends Reducer<ImmutableBytesWritable, KeyValue, ImmutableBytesWritable, KeyValue> {
- protected void reduce(ImmutableBytesWritable row, java.lang.Iterable<KeyValue> kvs,
- org.apache.hadoop.mapreduce.Reducer<ImmutableBytesWritable, KeyValue, ImmutableBytesWritable, KeyValue>.Context context)
- throws java.io.IOException, InterruptedException {
- TreeSet<KeyValue> map = new TreeSet<KeyValue>(KeyValue.COMPARATOR);
- for (KeyValue kv: kvs) {
- map.add(kv.clone());
- }
- context.setStatus("Read " + map.getClass());
- int index = 0;
- for (KeyValue kv: map) {
- context.write(row, kv);
- if (index > 0 && index % 100 == 0) context.setStatus("Wrote " + index);
- }
- }
- }
简单说下TotalOrderPartitioner和SimpleTotalOrderPartitioner:
TotalOrderPartitioner:
做全排序的东东,Hbase中的TOP其实就是Hadoop中TOP的直接拷贝,通过从外部文件中读取分区点来实现。 在bulk load中,这个外部文件即为从HTable中获取的region的startKeys处理之后得到的split points,这个split points文件被写到了路径Path partitionsPath = new Path(job.getWorkingDirectory(), "partitions_" + UUID.randomUUID())。
SimpleTotalOrderPartitioner:
简单的做全排序的东东,原则是根据输入的startkey和endkey进行均分,区间是左闭右开。阅读全文
0 0
- hbase bulk load相关源码简析之HFileOutputFormat、LoadIncrementalHFiles
- hbase bulk load相关源码简析之HFileOutputFormat、LoadIncrementalHFiles
- hbase bulk load相关源码简析之PutSortReducer、KeyValueSortReducer
- hbase bulk load相关源码简析之PutSortReducer、KeyValueSortReducer
- HBase之Bulk Load实现快速导入数据
- hbase打HFileOutputFormat补丁
- Trafodion Bulk Load 对比 Native HBase Bulk Load
- hbase的bulk load一个小改造
- bulk-load装载hdfs数据到hbase
- bulk-load 装载HDFS数据到HBase
- 通过Bulk Load导入HBase海量数据
- Kerberos HBase集群Bulk Load权限问题
- HBase Bulk Load的基本使用
- HBase数据导入----improttsv&Bulk Load
- [HBase] bulk-load装载hdfs数据到hbase小结
- hbase的bulk load一个小改造(续)
- hbase bulk load 小实践及一些总结
- Bulk Load-HBase数据导入最佳实践
- 深机笔记
- 处理java中内存溢出
- 如何准备BAT技术面试答案(中)——Java研发方向
- AE 制作一个简单的动画
- STL库容器vector front函数&back函数
- hbase bulk load相关源码简析之HFileOutputFormat、LoadIncrementalHFiles
- 用两个栈实现队列
- assert java 断言
- [LeetCode] 82. Remove Duplicates from Sorted List II
- C++类与对象(概念部分)
- Vue中父组件向子组件通信
- hdu 1260 Tickets(DP)
- 孙权的复仇技能实现
- centOS(linux)系统中,java class文件应该如何放到Tomcat系统中?