批量生成HFile格式方法

最近一直在搞批量生成HFile格式的代码,使用了好多方法,具体如下:


方法一、KeyValue生成,代码大致如下:

KeyValue kev = new KeyValue(Bytes.toBytes(row.toString()), Bytes
                .toBytes("info"), Bytes.toBytes(tableField), Bytes.toBytes(value));

但是总是报错,如下:

Added a key not lexically larger than previous

网上找了些解决方法,都是治标不治本,无结果。



方法二、Put生成,代码大致如下:

Put put = new Put(Bytes.toBytes(row));

put.add(Bytes.toBytes("info"), Bytes.toBytes(tableField), Bytes.toBytes(value));


但是总是报错,如下:

12/05/29 09:35:00 INFO mapred.JobClient:Task Id : attempt_201205181722_0988_r_000000_0, Status : FAILED
org.apache.hadoop.hbase.ZooKeeperConnectionException:HBase is able to connect to ZooKeeper but the connection closes immediately.This could be a sign that the server has too many connections (30 is thedefault). Consider inspecting your ZK server logs for that error and then makesure you are reusing HBaseConfiguration as often as you can. See HTable'sjavadoc for more information.

         atorg.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.<init>(ZooKeeperWatcher.java:160)

         atorg.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getZooKeeperWatcher(HConnectionManager.java:1209)

         atorg.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.setupZookeeperTrackers(HConnectionManager.java:511)

         atorg.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.<init>(HConnectionManager.java:502)

         atorg.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:172)

         atorg.apache.hadoop.hbase.client.HTable.<init>(HTable.java:175)

同样网上找了些解决方法,同样都是治标不治本,同样无结果。

方法三:参考hbase批量导入类src\org\apache\hadoop\hbase\mapreduce\ImportTsv.java代码,代码生成关键大致如下:

                  KeyValue kv = new KeyValue(lineBytes, parsed
                            .getRowKeyOffset(), parsed.getRowKeyLength(),
                            parser.getFamily(i), 0, parser.getFamily(i).length,
                            parser.getQualifier(i), 0,
                            parser.getQualifier(i).length, ts,
                            KeyValue.Type.Put, lineBytes, parsed
                                    .getColumnOffset(i), parsed
                                    .getColumnLength(i));

折腾了一上午,因为要和业务相关联,所以改了好多代码。搞定!


写的比较简单,但是过程相当痛苦!

希望大家拍砖!呵呵。

希望和各位有云经验的一起进步。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值