HBase体系结构02(Client)

HBase Client通过查询hbase:meta表找到感兴趣的RegionServers,这些RegionServers服务于特定的行范围。找到region(s)后,Client联络服务此region(s)的RegionServer,而不是联络master来处理读写请求。当执行负载均衡或RegionServer死亡时,master就会将region(s)重新分配,Client就需要重新查询目录表确定用户region的新位置。

1 集群连接

连接配置信息的API在HBase 1.0有所改变,参考Client configuration and dependencies connecting to an HBase cluster

1.1 HBase 1.0 API

HBase 1.0简洁地返回接口而不是特定类型,通过ConnectionFactory获取Connection对象,然后在需要时获取Table,Admin,RegionLocator等实例,用完后关闭实例,最后在退出时清理Connection实例。Connections是重量级对象但是线程安全,所有你只需创建一个该实例为你的应用程序。Table,Admin,RegionLocator等实例是轻量级的,创建完使用,使用完关闭。

1.2 HBase 1.0 API前

HBase 1.0 API前运用HTable与HBase集群交互,Table实例不是线程安全的,任何时候只允许一个线程操作该实例。为了共享ZooKeeper和socket实例,运用同样的HBaseConfiguration实例,如下:

HBaseConfiguration conf = HBaseConfiguration.create();
HTable table1 = new HTable(conf, "myTable");
HTable table2 = new HTable(conf, "myTable");

而不是:

HBaseConfiguration conf1 = HBaseConfiguration.create();
HTable table1 = new HTable(conf1, "myTable");
HBaseConfiguration conf2 = HBaseConfiguration.create();
HTable table2 = new HTable(conf2, "myTable");

连接池

当应用程序需要高并发访问时,可以预先创建Connection,如下:

// Create a connection to the cluster.
Configuration conf = HBaseConfiguration.create();
try (Connection connection = ConnectionFactory.createConnection(conf)) {
  try (Table table = connection.getTable(TableName.valueOf(tablename)) {
    // use table as needed, the table returned is lightweight
  }
}

构建HTableInterface实现非常轻量级,资源也是可控的。

HTablePool在HBase 0.94,0.95,0.96中废弃,0.98.1中移除,HConnection在HBase 1.0中废弃,代替使用Connection

2 写缓存和批处理

在HBase 1.0及之后,废弃支持Table的HTable,Table不在自动autoflush,运用BufferedMutator类。

HTable废弃前,通过调用close(),flushCommits(),刷写缓存。

更细粒度批量PutsDeletes,参见batch

3 外部客户端

非Java客户端和自定义协议相关信息,参见Apache HBase External APIs

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值