最近在试用Hbase1.0的客户端API,发觉变化还是挺大(以前版本也不熟)。到处都是deprecated。
现在应该是这样子:
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "quorum1,quorum2,quorum3");
conf.set("hbase.zookeeper.property.clientPort", "2181");
connection = ConnectionFactory.createConnection(conf);// HBase 0.99+
//connection = HConnectionManager.createConnection(conf); // HBase <0.99
Table table = connection.getTable(TableName.valueOf("TestTable"));
新的客户端API中,Connection处于关键位置,以下api说明翻译下:
ConnectionFactory class. The lifecycle of the connection is managed by the caller, who has to
close() the connection to release the resources.
The connection object contains logic to find the master, locate regions out on the cluster, keeps a cache of locations and then knows how to re-calibrate after they move. The individual connections to servers, meta cache, zookeeper connection, etc are all shared by the Table and Admin instances obtained from this connection.
Connection creation is a heavy-weight operation. Connection implementations are thread-safe, so that the client can create a connection once, and share it with different threads. Table and Admin instances, on the other hand, are light-weight and are not thread-safe. Typically, a single connection per client application is instantiated and every thread will obtain its own Table instance. Caching or pooling of Table and Admin is not recommended.
This class replaces HConnection, which is now deprecated.
ConnectionFactory类实例化
。Connection的生命周期由调用者维护,调用者通过调用close(),释放资源。
关于 ConnectionFactory.createConnection函数的说明:
public static Connection createConnection(org.apache.hadoop.conf.Configuration conf)
conf instance. Connection encapsulates all housekeeping for a connection to the cluster. All tables and interfaces created from returned connection share zookeeper connection, meta cache, and connections to region servers and masters.
The caller is responsible for calling
Connection.close() on the returned connection instance.
本文介绍了HBase 1.0客户端API的主要变化及使用方法,详细解释了如何配置并创建Connection,以及Connection的重要作用。此外,还提供了关于ConnectionFactory.createConnection函数的具体说明。
360

被折叠的 条评论
为什么被折叠?



