使用异步 HBase 客户端从 HBase 服务器故障中恢复

Recovering from HBase server failure using Async HBase client

我目前正在尝试找到一种方法来处理应用程序中的意外 HBase 故障。更具体地说,我要解决的是我的应用程序将数据插入 HBase 然后 HBase 失败并重新启动的情况。

为了检查我的应用程序如何对该场景做出反应,我编写了一个使用 HBase Async client 的应用程序,方法是执行紧密循环并将结果保存在 HBase 中。当我启动应用程序时,我可以看到行已保存到 table 中,如果在此期间我故意使我的 HBase 服务器失败并重新启动它,则客户端似乎重新连接但新插入内容未保存到 table 中

代码如下所示:

HConnection connection = HConnectionManager.createConnection();
HBaseClient hbaseClient = new HBaseClient(connection);

IntStream.range(0, 10000)
                .forEach(new IntConsumer() {
                    @Override
                    public void accept(int value) {
                        try {
                            System.out.println("in value: " + value);
                            Thread.sleep(2000);
                            Get get = new Get(Bytes.toBytes("key"));
                            hbaseClient.get(TableName.valueOf("testTable"), get, new ResponseHandler<Result>() {
                                            @Override
                                                public void onSuccess(Result response) {
                                                    System.out.println("SUCCESS");
                                                }

                                @Override
                                public void onFailure(IOException e) {
                                    System.out.println("FAILURE");
                                }
                            });
                            urlsClient.save("valuekey", "w" + value, new FailureHandler<IOException>() {
                                @Override
                                public void onFailure(IOException failure) {
                                    System.out.println("FAILURE");
                                }
                            });
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                });

这显然只是一个简单的测试,但我想要实现的是异步客户端将在我重新启动 HBase 服务器后成功保存新行。如果我实际在 "onFailure" 方法中打印堆栈跟踪,异步 HBase 客户端打印给我的内容是:

org.apache.hadoop.hbase.ipc.RpcClient$CallTimeoutException: Call id=303, waitTime=60096, rpcTimeout=60000
    at org.apache.hadoop.hbase.ipc.AsyncRpcChannel.cleanupCalls(AsyncRpcChannel.java:612)
    at org.apache.hadoop.hbase.ipc.AsyncRpcChannel.run(AsyncRpcChannel.java:119)
    at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:581)
    at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:655)
    at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:367)
    at java.lang.Thread.run(Thread.java:745)

所以我的问题是:

谢谢

好久没问这个问题了,最后还是用了HBase的高可用,没有想办法用代码解决