gpt4 book ai didi

hbase - 如何确保 HBase Java 客户端正在使用 hbase-site.xml

转载 作者:行者123 更新时间:2023-12-03 18:27:49 27 4
gpt4 key购买 nike

版本:Hadoop: 2.0.0-cdh4.3.1
HBase: 0.94.6-cdh4.3.1

我正在运行 cloudera quick start vm,这是我的小型远程 HBase Java 客户端 (HbaseClient.java),它所做的是:

public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "s1");
System.out.println(table.getTableName());
}

当我运行我的 java 客户端时,出现此错误:

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2013-08-25 00:01:56.684 java[39082:1703] Unable to load realm info from SCDynamicStore
Exception in thread "main" org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for s1,,99999999999999 after 10 tries.
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:980)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:885)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:987)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:889)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:846)
at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:271)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:211)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:170)
at com.***************.api.HBaseClient.main(HBaseClient.java:24)

我通过代码调试,很难发现客户端是否在资源文件夹中使用我的hbase-site.xml。我什至在 hbase-site.xml 中放入了错误的格式内容,Java 客户端出现了同样的错误。所以我认为它没有使用它。资源文件夹不是 CLASSPATH 的一部分吗?有没有办法检查 hbase-site.xml 是否被使用,如果没有使用,如何让我的客户使用它。

enter image description here

最佳答案

首先将你的配置文件,意思是 core-site.xml hbase-site.xml hdfs-site.xml,放在 src/main/resources 中,然后将其设为源文件夹(在 eclipse 下右键单击文件夹 -> Build Path ->用作源文件夹)然后试试这段代码

public class HbaseConfig {
private static final Logger LOG = LoggerFactory.getLogger(HbaseConfig.class);
public static org.apache.hadoop.conf.Configuration getHHConfig() {
Configuration conf = HBaseConfiguration.create();
InputStream confResourceAsInputStream = conf.getConfResourceAsInputStream("hbase-site.xml");
int available = 0;
try {
available = confResourceAsInputStream.available();
} catch (Exception e) {
//for debug purpose
LOG.debug("configuration files not found locally");
} finally {
IOUtils.closeQuietly(confResourceAsInputStream);
}
if (available == 0 ) {
conf = new Configuration();
conf.addResource("core-site.xml");
conf.addResource("hbase-site.xml");
conf.addResource("hdfs-site.xml");
}
return conf;
}
}

最后在你的代码中

public static void main(String[] args) throws IOException {
Configuration config = HbaseConfig.getHHConfig();
HTable table = new HTable(config, "s1");
System.out.println(table.getTableName());
}

关于hbase - 如何确保 HBase Java 客户端正在使用 hbase-site.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18424945/

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