因为生产产品运用HBASE, 在整合API的同时,进行必要的测试;
测试目的很简单,执行封装好的HBASE,进行建表删表操作,代码如下
DBClient client = new HBaseDBClient();
boolean res1 = client.prepare("test").exec(Commands.CREATETABLE, "testCreateTable", columnList,null);
System.out.println("is table created?" + res1);
client.release();
Thread.sleep(1000 * 20);
DBClient client2 = new HBaseDBClient();
boolean res2 = client2.prepare("test").exec(Commands.DELETETABLE, "testCreateTable", columnList,null);
System.out.println("is table deleted?" + res2);
client2.release();
于是出现问题.
打印结果为
is table created? true
is table deleted? false
=====================================================================
该测试,使用HBASE API的顺序如下(简单描写)
ConnectionFactory.createConnection(config) -> admin.tableExists() - > admin.createTable -> releaseAllResource()
ConnectionFactory.createConnection(config) -> admin.tableExists() -> admin.disableTable -> admin.dropTable -> releaseAllResource()
接着摸索,发现问题出现在第二次admin.tableExists()返回为false. 该API代码如下
@Override
public boolean tableExists(final TableName tableName) throws IOException {
return executeCallable(new RpcRetryingCallable<Boolean>() {
@Override
protected Boolean rpcCall(int callTimeout) throws Exception {
return MetaTableAccessor.tableExists(connection, tableName);
}
});
}
其作用为在metaTable中的查找该表是否存在记录,在HBASE SHELL中使用以下指令可以查看详细<