一,创建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