分享

hbase编写自定义count功能的问题

linguobao 发表于 2014-6-20 14:58:15 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 12 37255
我的环境:hadoop2.2+hbase0.98自定义编写了一个count功能统计hbase表的行数,服务器端是直接采用RowCountEndpoint.java这个,客户端编写如下:
public void getCount(){

                final ExampleProtos.CountRequest request = ExampleProtos.CountRequest.getDefaultInstance();
                try {
                        Map<byte[],Long> result = table.coprocessorService(ExampleProtos.RowCountService.class,
                                null, null,
                                new Batch.Call<ExampleProtos.RowCountService,Long>() {
                                  public Long call(ExampleProtos.RowCountService counter) throws IOException {
                                    ServerRpcController controller = new ServerRpcController();
                                    BlockingRpcCallback<ExampleProtos.CountResponse> rpcCallback = new BlockingRpcCallback<ExampleProtos.CountResponse>();
                                    counter.getRowCount(controller, request, rpcCallback);
                                    ExampleProtos.CountResponse response = rpcCallback.get();
                                    if (controller.failedOnException()) {
                                      throw controller.getFailedOn();
                                    }
                                    System.out.println(response.getCount() + "@@@@@@@@@");
                                    return (response != null && response.hasCount()) ? response.getCount() : 0;
                                  }
                                });
                        long total = 0;
            for (Map.Entry<byte[], Long> entry : result.entrySet()) {
                total += entry.getValue().longValue();
                System.out.println("Region: " + Bytes.toString(entry.getKey())
                        + ", Count: " + entry.getValue());
            }
            System.out.println("Total Count: " + total);
                } catch (ServiceException e) {
                        e.printStackTrace();
                } catch (Throwable e) {
                        e.printStackTrace();
                }
        }


把hbase-examples-0.98.1-hadoop2.jar设置到目标表syslog的属性中,用客户端调用。syslog表的行数可以被查出来。测试了几个表都是正常的。
但是当测试库里的一个有1.5亿条数据的表时,这个表有12个region,当查第6个region的时候,出现下面情况:
Eclipse出现如下错误:60000 millis timeout while waiting for channel to be ready for read. ch
hbase regionserver log出现如下错误:WARN  [RpcServer.handler=4,port=60020] ipc.RpcServer: RpcServer.handler=4,port=60020: caught a ClosedChannelException, this means that the server was processing a request but the client went away. The error message was: null
2014-06-20 14:20:07,430 ERROR [RpcServer.handler=10,port=60020] ipc.RpcServer: Unexpected throwable object
com.google.protobuf.UninitializedMessageException: Message missing required fields: count

尝试过把<property>
        <name>hbase.rpc.timeout</name>
        <value>6000000</value>
</property>调整这么大,还是不行。发现查第6个region的时候就出现regionserver log这样的问题。
请各帮忙看看。谢谢。





已有(12)人评论

跳转到指定楼层
howtodown 发表于 2014-6-20 15:46:17
你的字段count值是不是为空了,你给他赋一个值
回复

使用道具 举报

linguobao 发表于 2014-6-20 16:17:20
howtodown 发表于 2014-6-20 15:46
你的字段count值是不是为空了,你给他赋一个值

字段都有值,count是类似sql中count的功能,现在是统计了5个region的值,统计第6个的时候出了上述的问题。
回复

使用道具 举报

howtodown 发表于 2014-6-20 17:19:25
linguobao 发表于 2014-6-20 16:17
字段都有值,count是类似sql中count的功能,现在是统计了5个region的值,统计第6个的时候出了上述的问题 ...

不是你数据的字段,而是proto文件中的字段,你看看什么状态,是required还是optional
回复

使用道具 举报

linguobao 发表于 2014-6-20 17:20:38
howtodown 发表于 2014-6-20 17:19
不是你数据的字段,而是proto文件中的字段,你看看什么状态,是required还是optional

option java_package = "org.apache.hadoop.hbase.coprocessor.example.generated";
option java_outer_classname = "ExampleProtos";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;

message CountRequest {
}

message CountResponse {
  required int64 count = 1 [default = 0];
}

service RowCountService {
  rpc getRowCount(CountRequest)
    returns (CountResponse);
  rpc getKeyValueCount(CountRequest)
    returns (CountResponse);
}


是这样的。

回复

使用道具 举报

howtodown 发表于 2014-6-20 17:22:21
linguobao 发表于 2014-6-20 17:20
option java_package = "org.apache.hadoop.hbase.coprocessor.example.generated";
option java_outer_ ...
你改成optional试一下。
回复

使用道具 举报

linguobao 发表于 2014-6-23 10:12:36
howtodown 发表于 2014-6-20 17:22
你改成optional试一下。

还是出现com.google.protobuf.UninitializedMessageException: Message missing required fields: count        at com.google.protobuf.AbstractMessage$Builder.newUninitializedMessageException(AbstractMessage.java:770)
        at org.apache.hadoop.hbase.coprocessor.example.generated.MyExampleProtos$CountResponse$Builder.build(MyExampleProtos.java:684)
        at org.apache.hadoop.hbase.coprocessor.example.generated.MyExampleProtos$CountResponse$Builder.build(MyExampleProtos.java:1)
        at org.apache.hadoop.hbase.regionserver.HRegion.execService(HRegion.java:5506)
        at org.apache.hadoop.hbase.regionserver.HRegionServer.execServiceOnRegion(HRegionServer.java:3300)
        at org.apache.hadoop.hbase.regionserver.HRegionServer.execService(HRegionServer.java:3282)
        at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:29501)
        at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2012)
        at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:98)
        at org.apache.hadoop.hbase.ipc.SimpleRpcScheduler.consumerLoop(SimpleRpcScheduler.java:160)
        at org.apache.hadoop.hbase.ipc.SimpleRpcScheduler.access$000(SimpleRpcScheduler.java:38)
        at org.apache.hadoop.hbase.ipc.SimpleRpcScheduler$1.run(SimpleRpcScheduler.java:110)
        at java.lang.Thread.run(Thread.java:662)
这样的问题。

回复

使用道具 举报

howtodown 发表于 2014-6-23 10:42:09
linguobao 发表于 2014-6-23 10:12
还是出现com.google.protobuf.UninitializedMessageException: Message missing required fields: count         ...

你在检查检查是不是该的没有生效,或则其他的地方还需要修改。
回复

使用道具 举报

linguobao 发表于 2014-6-23 11:03:16
howtodown 发表于 2014-6-23 10:42
你在检查检查是不是该的没有生效,或则其他的地方还需要修改。

option java_package = "org.apache.hadoop.hbase.coprocessor.example.generated";
option java_outer_classname = "ExampleProtos";
option java_generic_services = true;
option java_generate_equals_and_hash = true;
option optimize_for = SPEED;

message CountRequest {
}

message CountResponse {
  optional int64 count = 1 [default = 0];
}

service RowCountService {
  rpc getRowCount(CountRequest)
    returns (CountResponse);
  rpc getKeyValueCount(CountRequest)
    returns (CountResponse);
}

这是Examples.proto问句的内容,只有一个地方有required,我已经改为optional了。你帮忙看下呢。

回复

使用道具 举报

howtodown 发表于 2014-6-23 11:12:25
linguobao 发表于 2014-6-23 11:03
option java_package = "org.apache.hadoop.hbase.coprocessor.example.generated";
option java_outer_ ...

这里肯定该了,你在看看其他的问题,不熟悉你的环境,你只能看看自己看看是不是个人原因造成的了。尽力帮你了。
回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条