记录mapreduce遇到的问题

1、java.lang.ClassNotFoundException

后来发现原来是在0.20版本以后main方法中需要加:job.setJarByClass(HBaseToFile.class);才能找到自定义的map或reduce内部类。


2、ERROR lzo.GPLNativeCodeLoader: Could not load native gpl library

java.lang.UnsatisfiedLinkError: no gplcompression in java.library.path
缺少lzo相关的jar,需要安装上去。

3、No such method exception Hadoop <init>
解决:There's another thing to check when getting errors like this for classes which are writables, mappers, reducers, etc.
If the class is an inner class, make sure it's declared static (i.e. doesn't need an instance of the enclosing class). Otherwise, Hadoop cannot instantiate your inner class and will give this same error - that a zero-arg constructor is needed.
加上默认构造函数如:public StockKey(){}或者如果是inner class 的mapper的时候,需要申明是static的。

4、hadoop的Text类获取它的byte必须copyByte(text)或者text.toString.getBytes();直接text.getBytes()有bug。
见:http://blackwing.iteye.com/blog/1978501

5、使用hfile入hbase的过程中遇到如下问题:
1)莫名其妙乱码,有些row正常有些row不正常,原因是在map reduce过程中,有些操作调用了jvm的编码,而hadoop集群中,jvm file.encoding编码不统一,有些utf-8(符合hadoop的硬编码),有些是AISN什么的,详见:
http://blog.csdn.net/wisgood/article/details/14165145
解决方法除了停掉集群,重新设置file.encoding之后重启彻底解决之外,另外一种就是避开调用默认file.encoding,我的代码里:
ImmutableBytesWritable keyVid_w = new ImmutableBytesWritable(key.toString().getBytes());改成Bytes.toBytes(key.toString())
2)java.io.IOException: Added a key not lexically larger than previous key=\x00\x

原因是reduce 在写的时候由于词排序问题导致程序运行异常。这个问题,是由于hbase的row key 是基于词典排序,比如说reduce 写入 hbase 的row key 顺序是,r10,r11,r00,则会报上述异常。考虑到map有排序功能,于是将其rowkey作为map的输出key
我的代码是:
protected void map(Text key, Text value, Context context) throws java.io.IOException, InterruptedException {
  ImmutableBytesWritable keyVid_w = new ImmutableBytesWritable(Bytes.toBytes(key.toString()));
  String count = value.toString();
  if (count.isEmpty()) {
   return;
  }
  KeyValue kv = new KeyValue(Bytes.toBytes(key.toString()), outputTable[1].getBytes(), today.getBytes(), count.getBytes());
  context.write(keyVid_w, kv);

暂时想到这些。。。
6、 hadoop对数据的处理是分块处理的,默认是64M分为一个数据块,如果存在大量小数据文件(例如:2-3M一个的文件)这样的小数据文件远远不到一个数据块的大小就要按一个数据块来进行处理。
这样处理带来的后果由两个:1.存储大量小文件占据存储空间,致使存储效率不高检索速度也比大文件慢。
2.在进行MapReduce运算的时候这样的小文件消费计算能力,默认是按块来分配Map任务的(这个应该是使用小文件的主要缺点)

那么如何解决这个问题呢?
1.使用Hadoop提供的Har文件,Hadoop命令手册中有可以对小文件进行归档。
2.自己对数据进行处理,把若干小文件存储成超过64M的大文件。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值