2016-07-15 61 views
1

我想在HBase的創建表,如果它不exists.code這種方法是不工作 -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) 

回答

0

後appering試試這個:

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); 
    } 
+0

不工作同樣的問題.... –

+0

增加蜂巢和HBase的CONF到類路徑任職後 –