客户端API源码
施工中
createConnection()
Configuration configuration = HBaseConfiguration.create(); |
创建connection过程如下:ConnectionFactory.createConnection(Configuration conf)
, 返回的是一个HConnectionImplementation的对象, 调用了HConnectionImplementation的构造函数:HConnectionImplementation(Configuration conf, boolean managed, ExecutorService pool, User user)
看一下HConnectionImplementation构造都做了哪些初始化:{
this.asyncProcess = this.createAsyncProcess(this.conf);
this.rpcClient = RpcClientFactory.createClient(this.conf, this.clusterId, this.metrics);
}
getTable()
Connection connection = ConnectionFactory.createConnection(configuration); |
Connection.getTable()
实际调用到了HConnectionImplementation.getTable()
返回了一个新对象: new HTable(tableName, this, this.connectionConfig, this.rpcCallerFactory, this.rpcControllerFactory, pool)
HTable有几个重要成员:
connection,
multiAp,
locator
在HTable初始化时, 上面几个成员按如下顺序初始化:this.multiAp = this.connection.getAsyncProcess();
this.locator = new HRegionLocator(this.tableName, this.connection);
put()
Put put = new Put(rowKey.getBytes()); |
HTable.put(Put)
并不会立刻发送RPC请求, 而是等多次请求后再一次backgroundFlushCommits,submit(tableName, buffer, true, null, false);