加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

java访问hbase时一直卡住不执行

(2017-11-24 16:30:29)
标签:

hbase

java

io

streams

netutils

分类: 大数据处理
一、背景:
    在ubuntu中已经正确安装了hbase 0.94版本,通过./hbase shell也能够正确访问hbase数据库了,此时想要通过java的api调用去访问数据库。
    在idea中创建了maven工程,里面pom文件的配置信息如下:
[dependencies>
        [dependency>
            [groupId>org.apache.hbase[/groupId>
            [artifactId>hbase[/artifactId>
            [version>0.94.16[/version>
        [/dependency>

        [dependency>
            [groupId>org.apache.hadoop[/groupId>
            [artifactId>hadoop-hdfs[/artifactId>
            [version>2.6.0[/version>
        [/dependency>

        [dependency>
            [groupId>org.apache.hadoop[/groupId>
            [artifactId>hadoop-common[/artifactId>
            [version>2.6.0[/version>
        [/dependency>

    [/dependencies>
    然后执行程序后显示如下信息,卡在这里一直不动
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.

二、问题定位和解决
1、java程序如下:
public static void main(String[] args){
        try{
            Configuration HBASE_CONFIG = HBaseConfiguration.create();
            HBASE_CONFIG.set("hbase.zookeeper.quorum", "hbasestudy");
            System.out.println("good1");

            HBaseAdmin admin = new HBaseAdmin(HBASE_CONFIG);
            System.out.println("good2");
            if(admin.tableExists("te")){
                System.out.println("te" + " exists!");
            }else{
                HTableDescriptor tableDesc = new HTableDescriptor("te");
                tableDesc.addFamily(new HColumnDescriptor("co"));
                admin.createTable(tableDesc);
                System.out.println("create table success!");
            }
        }catch(IOException e){
            e.printStackTrace();
        }


    }

2、首先定位到是HBaseAdmin(xx)的这个位置出问题了,通过debug模式一直访问内部代码,最后定位到是HConnectionManager.java文件的如下位置出错了。
 for (int tries = 0;
          !this.closed && this.master == null && tries < numRetries;
        tries++) {

          try {
            sn = masterAddressTracker.getMasterAddress();
            if (sn == null) {
              LOG.info("ZooKeeper available but no active master location found");
              throw new MasterNotRunningException();
            }

            InetSocketAddress isa =
              new InetSocketAddress(sn.getHostname(), sn.getPort());
            HMasterInterface tryMaster = rpcEngine.getProxy(
                HMasterInterface.class, HMasterInterface.VERSION, isa, this.conf,
                this.rpcTimeout)
;


            if (tryMaster.isMasterRunning()) {
              this.master = tryMaster;
              this.masterLock.notifyAll();
              break;
            }

          } catch (IOException e) {
           if (!shouldRetryGetMaster(tries, e)) break;
          } catch (UndeclaredThrowableException ute) {
            if (!shouldRetryGetMaster(tries, ute)) break;
          }

3、当执行到上面第2个红色的时候,查看IDEA的调试面板,看到如下信息
detailMessage="Could not set up IO Streams"
cause=java.lang.NoSuchMethodError: org.apache.hadoop.net.NetUtils.getInputStream(LLjava/io/InputStream;
也就是说找不到某个函数的定义,导致rpc访问hbase的时候报错了。
于是乎我将hadoop的版本从0.26->1.1.2->2.5.0->2.6.0,但是始终会报这个错误,郁闷!!

4、通过翻阅web海量查找,发现这样一个临时方案。
hbase目录下有个lib文件,只要将这个lib引入idea的libraries即可。
于是我尝试后发现果然成功了。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有