Hbase Connection Pool

I am trying to create a hbase connection pool. I tried the following. But I do not know the consequences. Will it affect my work? Can anybody help? Hosts can be deleted or even local.

HashMap cons = new HashMap();
    public void getDataFromHbase(String host, String tableid){
        conf.set("hbase.zookeeper.quorum", host);
        ThreadPoolExecutor executor= (ThreadPoolExecutor) Executors.newCachedThreadPool();
        executor.setMaximumPoolSize(50);
        if(cons.get(host+"tableA_"+tableid) != null){
            table1 = cons.get(host+"tableA_"+tableid);
            table2 = cons.get(host+"tableB_"+tableid);
        }
        else{
            table1 = new HTable(conf,Bytes.toBytes("tableA_"+tableid),executor);
            table2 = new HTable(conf,Bytes.toBytes("tableB_"+tableid),executor);
            cons.put(host+"tableA_"+tableid,table1);
            cons.put(host+"tableB_"+tableid,table2);
        }
        Scan scan = new Scan();
        scan.addFamily(Bytes.toBytes("n"));
        scan.setCaching(1000);
        ResultScanner resultScanner = table1.getScanner(scan);
        ResultScanner resultScannerB = table2.getScanner(scan);
    }
+4
source share
1 answer

I would recommend HTablePool .. rather, native connection management, which is more error prone and difficult to debug .

Class HTablePool

java.lang.Object org.apache.hadoop.hbase.client.HTablePool

All implemented interfaces:

Closeable, AutoCloseable

Outdated. Use HConnection.getTable (String) instead.

Public class HTablePool extends Object implements Closeable

HTable. HTablePool . , HTablePool getTable (String) HTable . , HTableInterface.close(), , HTableInterface, HTableInterface.close(), () (HTableInterface). maxSize, HTable-, - . Integer.MAX_VALUE.

. HConnectionManager.

+2
source

Source: https://habr.com/ru/post/1660765/


All Articles