Hbase1.0 客户端api---神算子

最近在试用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说明翻译下:



关于 Connection接口的说明:
A cluster connection encapsulating lower level individual connections to actual servers and a connection to zookeeper. Connections are instantiated through the  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.

Connection封装了底层与各实际服务器的连接以及与zookeeper的连接。Connection通过  ConnectionFactory类实例化 。Connection的生命周期由调用者维护,调用者通过调用close(),释放资源。
连接对象包含发现master,定位region,缓存region位置一边当region移动后,重新矫正位置。通往各服务器的连接,meta数据缓存,zookeeper连接等,与通过Connection获取的Table,Admin实例都是共享的。
创建Connection是重量级操作。 Connection是线程安全的,因此,多个客户端线程可以共享一个Connection。Table和Admin实例,相反地,是轻量级的并且非线程安全。典型的用法,一个客户端程序共享一个单独的Connection,每一个线程获取自己的Table实例。不建议缓存或者池化(pooling)Table、Admin。



关于 ConnectionFactory.createConnection函数的说明:

public static Connection createConnection(org.apache.hadoop.conf.Configuration conf)
Create a new Connection instance using the passed  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.

Connection封装了连接到集群的所有维护工作。通过返回的connection生成的table、接口等共享zookeeper连接,meta缓存,到region server以及master的连接。
调用者负责释放connection实例。

Similarly,  Connection  also returns  Admin  and  RegionLocator  implementations
类似返回table接口,Connection还可以返回Admin,RegionLoacator实例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值