源代码分析二:创建HTable

一,创建HTable
A,获取TableName对象,缓存( 使用CopyOnWriteArraySet)TableName优化
1,缓存使用 CopyOnWriteArraySet 实现(为什么作者使用Set ?? 而非Map,从检索性能和操作便捷度上,Map优于set)
缓存作用代码:
for (TableName tn : tableCache) {
      if (Arrays.equals(tn.getName(), fullName)) {
        return tn;
      }
    }
缓存添加数据代码:
TableName newTable = new TableName(bns, qns);
    if (tableCache.add(newTable)) {  // Adds the specified element if it is not already present
      return newTable;
    }

    // Someone else added it. Let's find it.
    for (TableName tn : tableCache) {
      if (Bytes.equals(tn.getQualifier(), qns) && Bytes.equals(tn.getNamespace(), bns)) {
        return tn;
      }
    }
2,获取TableName,通过":"区分namespace和tableName,若不含":",则使用默认namespace
B,初始化connection和configuration
C,初始化ThreadPoolExecutor
1,初始化线程池执行器的最大线程数( hbase.htable.threads.max)和keepAliveTime( hbase.htable.threads.keepalivetime)
2,创建ThreadPoolExecutor
3,基于已经parse的配置设置HTable的参数
a,根据是否为系统表来设置超时时长,若true则超时由 hbase.client.meta.operation.timeout 配置
若false超时则由 hbase.client.operation.timeout配置
b,设置writeBufferSize,由 hbase.client.write.buffer配置
c,设置autoFlush,默认为true
d,设置scannerCaching,由 hbase.client.scanner.caching配置
e,初始化rpcCallerFactory,开发者可以自己拓展,由 hbase.rpc.callerfactory.class配置
f,初始化rpcControllerFactory,开发者可以自己拓展,由 hbase.rpc.controllerfactory.class配置
g,初始化AsyncProcess
TableName newTable = new TableName(bns, qns);
    if (tableCache.add(newTable)) {  // Adds the specified element if it is not already present
      return newTable;
    }

    // Someone else added it. Let's find it.
    for (TableName tn : tableCache) {
      if (Bytes.equals(tn.getQualifier(), qns) && Bytes.equals(tn.getNamespace(), bns)) {
        return tn;
      }
    }

h,设置HTable状态控制。closed=false

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值