HBase-05源码

客户端API源码

施工中

createConnection()

Configuration configuration = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(configuration);
connection.getTable(TableName.valueOf("tbl_xxx"));

创建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(TableName.valueOf("tbl_xxx"));

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());
put.addColumn(family.getBytes(), qualifier.getBytes(), val.getBytes());
table.put(put);

HTable.put(Put) 并不会立刻发送RPC请求, 而是等多次请求后再一次backgroundFlushCommits,
submit(tableName, buffer, true, null, false);