Hbase表存在方法无法按预期工作

时间:2016-07-15 09:51:26

标签: java hbase

我正在尝试在hbase中创建一个表,如果它不存在,那么这就是 -

    Configuration config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", "indlin2741");
config.set("hbase.zookeeper.property.clientPort", "2181");

HTable hTable = new HTable(config, "test1");
System.out.println(hTable.getName());
Admin admin=ConnectionFactory.createConnection(config).getAdmin();
HTableDescriptor table = new HTableDescriptor(TableName.valueOf("test1"));

// creating column family descriptor
HColumnDescriptor family = new HColumnDescriptor("ht".getBytes());

// adding coloumn family to HTable
table.addFamily(family);

if(admin.tableExists(TableName.valueOf("test1"))){
admin.createTable(table);
}

如果我删除tableExists方法,一切正常。 一旦调用此方法,所有区域服务器都将关闭。 并且在此之后出现波纹管误差

                at com.amdocs.vivo.dh.MergeSchema.Test.main(Test.java:32)
Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
Fri Jul 15 15:12:12 IST 2016, null, java.net.SocketTimeoutException: callTimeout=60000, callDuration=77018: row 'test1,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=indlin2741.corp.amdocs.com,60020,1468503848155, seqNum=0

    at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.throwEnrichedException(RpcRetryingCallerWithReadReplicas.java:276)

1 个答案:

答案 0 :(得分:0)

试试这个:

HBaseAdmin admin = new HBaseAdmin(hbaseTemplate.getConfiguration());
    if (!admin.tableExists("test1")) {

        HTableDescriptor td = new HTableDescriptor("test1");
        HColumnDescriptor cd = new HColumnDescriptor(columnFamilyProfile);
        td.addFamily(cd);

        admin.createTable(td);
    }