hbase java客户端批处理/在cdh4.6上放慢

1sbrub3j  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(249)

我使用hbase来存储由cdh4(目前是4.5)管理的应用程序日志,升级到cdh4.6(与4.7相同)后,插入速度非常慢。我发现客户端正在连接regionserver并立即关闭连接(使用CDH4.5时我没有遇到相同的问题)
区域服务器日志:

13:46:08,428 INFO org.apache.zookeeper.ZooKeeper: Initiating client connection, connectString=ZK03:2181,ZK02:2181,ZK01:2181 sessionTimeout=60000 watcher=hconnection
13:46:08,429 INFO org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper: The identifier of this process is 19573@NODE01
13:46:08,429 INFO org.apache.zookeeper.ClientCnxn: Opening socket connection to server ZK03/10.1.243.170:2181. Will not attempt to authenticate using SASL (java.lang.SecurityException: Unable to locate a login configuration)
13:46:08,429 INFO org.apache.zookeeper.ClientCnxn: Socket connection established to ZK03/10.1.243.170:2181, initiating session
13:46:08,431 INFO org.apache.zookeeper.ClientCnxn: Session establishment complete on server ZK03/10.1.243.170:2181, sessionid = 0x146a9fec35171f0, negotiated timeout = 60000
13:46:08,538 INFO org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation: Closed zookeeper sessionid=0x146a9fec35171f0
13:46:08,540 INFO org.apache.zookeeper.ZooKeeper: Session: 0x146a9fec35171f0 closed
13:46:08,540 INFO org.apache.zookeeper.ClientCnxn: EventThread shut down

客户端连接类:

private void initConnection(Configuration hConf) throws RuntimeException {
    try {
        //HConnectionManager.create(hConf);
        hConnection = HConnectionManager.createConnection(hConf);
    } catch (ZooKeeperConnectionException e) {
        logAndThrow("Failed to init connection " + e.getMessage());
    }
}

public Connection(Configuration hConf) {
    initConnection(hConf);
}

public void closeConnection() throws IOException {
    hConnection.close();
}

public HTableInterface getHTableInterface(String tableName) throws IOException {
    HTableInterface htable = hConnection.getTable(tableName);
    htable.setAutoFlush(false, true);
    htable.setWriteBufferSize(1024*1024*12);
    return htable;
}

导入:

Put put = new Put(rowKey.get(), tsWhole);
mainTableBuffer.add(put);
if(cfg_.maxBatchBufferSize <= mainTableBuffer.size()) {
    mainTableInterface_.batch(mainTableBuffer);
    mainTableBuffer.clear();
}
11dmarpk

11dmarpk1#

看来我找到问题了。在创建二级索引时,它在协处理器中。这是插入secondaryindextable的实际代码

public void postBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatchOp) throws IOException {

        HTableInterface searchTableInterface = c.getEnvironment().getTable(tableName);
        try {
            searchTableInterface.batch(mutationsBuffer);
        } catch (InterruptedException e) {
            logger.error("Caught exception while executing batch on table " + currSearchTName, e);
        } finally {
            searchTableInterface.close();
        }
}

问题似乎是使用环境连接进行插入。启动时创建连接

hConnection = HConnectionManager.createConnection(hConf);

在postbarchmutate中用于获取表

HTableInterface htable = hConnection.getTable(tableName);

它现在可以工作了,但仍然不知道为什么使用环境连接是错误的,为什么连接总是关闭

相关问题