HBase异常:hbase-default.xml file seems to be for and old version of HBase的解决方法

近期在使用HBase Java Client连接HBase服务端创建Configuration对象时,遇到了hbase-default.xml file seems to be for and old version of HBase的异常,经过查找资料及阅读HBase相关源码,对这类异常的解决方法做一下总结。

异常出现的原因

HBase客户端创建Configuration对象时,需要使用hbase-*.jar包,其中*部分标识了连接的HBase版本号:

[root@xxxxxx]$ ls hbase-*.jar
hbase-0.92.1.jar

然后,在hbase-*.jar包的hbase-default.xml中,有一个关于HBase默认版本号的配置项:

  <property skipInDoc="true">
    <name>hbase.defaults.for.version</name>
    <value>0.92.1</value>
    <description>
    This defaults file was compiled for version 0.92.1. This variable is used
    to make sure that a user doesn't have an old version of hbase-default.xml on the
    classpath.
    </description>
  </property>

在客户端启动时,会首先检查jar包名中指定的版本号和jar包中hbase-default.xml中设置的hbase.defaults.for.version选项是否一致,正常情况下二者一致,没有Exception抛出(如上述示例)。

否则,如果jar包名指定版本号小于hbase.defaults.for.version指定版本号,就会报出如下异常:

java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase ......
......

异常的解决方法

第一种情况

异常现象:

Caused by: java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (@@@VERSION@@@), this version is 0.92.1
        at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68)
        at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100)

这种情况是因为hbase-default.xml中的hbase.defaults.for.version配置项在打包时没有被正常替换成maven指定的版本号,具体自己可以解开hbase-*.jar打开hbase-default.xml进行验证。解决方法:

1、打开HBase maven工程的pom.properties文件,确定是否指定了version=0.92.1这一配置选项,如果没有,加上后进行重新打包。stackoverflow上有人建议将pom.xml中的如下部分:

          <execution>
            <phase>process-resources</phase>
            <configuration>
              <target>
                <replace file="${project.build.outputDirectory}/hbase-default.xml" token="@@@VERSION@@@" value="${project.version}" />
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>

将其中的target改为tasks:

          <execution>
            <phase>process-resources</phase>
            <configuration>
              <tasks>
                <replace file="${project.build.outputDirectory}/hbase-default.xml" token="@@@VERSION@@@" value="${project.version}" />
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>

经查阅Maven AntRun Plugin关于tasks和target的解释说明:

target     PlexusConfiguration     1.5     The XML for the Ant target. You can add anything you can add between <target> and </target> in a build.xml.
tasks     PlexusConfiguration     -     Deprecated. Use target instead

tasks已经不推荐使用,建议使用target。stackoverflow上作者说的情况,可能是由于AntRun插件版本低等原因(个人猜测,未经实际验证)。如果你已经确定@@@VERSION@@@被成功替换掉,则不用再进行以上操作。

2、另一种方法是直接解压jar包后修改hbase-default.xml,然后重新打成jar包。

第二种情况

异常现象:

Caused by: java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (*.**.*), this version is 0.92.1
        at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68)
        at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100)

这种情况是因为hbase-default.xml中的hbase.defaults.for.version配置项与hbase-*.jar名中指定版本号不一致。解决方法:

1、打开工程目录下的hbase-site.xml,将hbase.defaults.for.version.skip配置为true,忽略默认版本的检查:

  <property>
    <name>hbase.defaults.for.version.skip</name>
    <value>true</value>
    <description>
    Set to true to skip the 'hbase.defaults.for.version' check.
    Setting this to true can be useful in contexts other than
    the other side of a maven generation; i.e. running in an
    ide.  You'll want to set this boolean to true to avoid
    seeing the RuntimException complaint: "hbase-default.xml file
    seems to be for and old version of HBase (0.92.1), this
    version is X.X.X-SNAPSHOT"
    </description>
  </property>

2、将二者修改为一致的版本号,具体可参考第一种情况里的方法。

第三种情况

异常现象:

Caused by: java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (null), this version is 0.92.1
        at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68)
        at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100)

这种情况是因为加载hbase-default.xml失败没有获取默认的版本号。这种情况与实际环境相关,下面是一些可以尝试的解决方法:

1、删除Java的工程目录下的hbase-default.xml文件;

2、参考HBase mail list的搜索结果: 点击这里

posted on 2012-07-22 10:19  大圆那些事  阅读(8876)  评论(0编辑  收藏  举报

导航