gpt4 book ai didi

java - Hbase 表存在方法未按预期工作

转载 作者:太空宇宙 更新时间:2023-11-04 12:25:50 25 4
gpt4 key购买 nike

我正在尝试在 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)

最佳答案

试试这个:

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

关于java - Hbase 表存在方法未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38393079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com