Hive Metastore 连接报错

背景

项目中需要通过一些自定义的组件来操控hive的元数据,于是使用了remote方式来存储hive元数据,使用一个服务后台作为gateway,由它来控制hive元数据。

现象

在windows上连接hive metastore的时候,无端的会报NullPointerException,非常费解。

分析

看了代码后发现,连接后会获取本地用户所在的用户组信息(org.apache.hadoop.hive.metastore.HiveMetaStoreClient中的open方法):

          if (isConnected && !useSasl && conf.getBoolVar(ConfVars.METASTORE_EXECUTE_SET_UGI)){
            // Call set_ugi, only in unsecure mode.
            try {
              UserGroupInformation ugi = Utils.getUGI();
              client.set_ugi(ugi.getUserName(), Arrays.asList(ugi.getGroupNames()));
            } catch (LoginException e) {
              LOG.warn("Failed to do login. set_ugi() is not successful, " +
                       "Continuing without it.", e);
            } catch (IOException e) {
              LOG.warn("Failed to find ugi of client set_ugi() is not successful, " +
                  "Continuing without it.", e);
            } catch (TException e) {
              LOG.warn("set_ugi() not successful, Likely cause: new client talking to old server. "
                  + "Continuing without it.", e);
            }
          }
ugi.getGroupNames()会去调用本地命令在windows平台上会使用一个叫winutils的工具,但是作为客户端开发的话不会在windows端安装这些二进制文件,所以代码流程就出错了
  /**
   * a Unix command to get a given user's groups list.
   * If the OS is not WINDOWS, the command will get the user's primary group
   * first and finally get the groups list which includes the primary group.
   * i.e. the user's primary group will be included twice.
   */
  public static String[] getGroupsForUserCommand(final String user) {
    //'groups username' command return is non-consistent across different unixes
    return (WINDOWS)? new String[] { WINUTILS, "groups", "-F", "\"" + user + "\""}
                    : new String [] {"bash", "-c", "id -gn " + user
                                     + "&& id -Gn " + user};
WINUTILS的初始化在如下函数中,如果path中找不到的话会返回null
  /** a Windows utility to emulate Unix commands */
  public static final String WINUTILS = getWinUtilsPath();

  public static final String getWinUtilsPath() {
    String winUtilsPath = null;

    try {
      if (WINDOWS) {
        winUtilsPath = getQualifiedBinPath("winutils.exe");
      }
    } catch (IOException ioe) {
       LOG.error("Failed to locate the winutils binary in the hadoop binary path",
         ioe);
    }

    return winUtilsPath;
  }
在java.lang.ProcessBuilder.java中的start中有如下判断:
public Process start() throws IOException {
        // Must convert to array first -- a malicious user-supplied
        // list might try to circumvent the security check.
        String[] cmdarray = command.toArray(new String[command.size()]);
        cmdarray = cmdarray.clone();

        for (String arg : cmdarray)
            if (arg == null)
                throw new NullPointerException();
        // Throws IndexOutOfBoundsException if command is empty
        String prog = cmdarray[0];

由于cmdarray中的第一个元素就是null,所以马上甩出NullPointerException

toString() 中的null值检测

另外在org.apache.hadoop.util.Shell中

ShellCommandExecutor

这个类中存在一个问题,就是toString方面没有对成员为null的情况进行判断如:

    /**
     * Returns the commands of this instance.
     * Arguments with spaces in are presented with quotes round; other
     * arguments are presented raw
     *
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
      StringBuilder builder = new StringBuilder();
      String[] args = getExecString();
      for (String s : args) {
        if (s.indexOf(' ') >= 0) {
          builder.append('"').append(s).append('"');
        } else {
          builder.append(s);
        }
        builder.append(' ');
      }
      return builder.toString();
    }

即假如我们的命令args中有元素是null,那么这个toString也会抛出NullPointerException,因为在没有判断的情况下直接引用了对象方法(s.indexOf),记得这个问题似乎在Effective Java里看到过。一般并不会触发这问题,可是在打开调试器的时候,它会去执行当前环境里对象的toString方法。所以每当debug到相关代码段时,总是莫名其妙的就突然爆出个NullPointerException,着实费解了一些时间。

 

转载于:https://www.cnblogs.com/lailailai/p/4553031.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hive Metastore Canary时,这可能是由于以下几个原因造成的。 首先,检查Hive Metastore服务是否正常运行。可以通过查看日志文件或运行命令(如`systemctl status hive-metastore`或`service hive-metastore status`)来确定服务是否启动。如果服务未启动,可以尝试重新启动它并观察是否解决了问题。 其次,检查Hive Metastore配置文件是否正确。Hive Metastore的配置文件通常位于`/etc/hive/conf/hive-site.xml`路径下。确保配置文件中的所有属性和值都是正确的,并且与其他相关组件(如Hadoop)的配置相匹配。 另外,检查Hive Metastore连接的数据库是否可用。Hive Metastore使用数据库来存储元数据信息,例如表、分区和列等。确保数据库服务已启动,并且Metastore配置文件中的数据库连接属性正确设置。 此外,还要考虑Hive Metastore版本与其他组件的兼容性。如果使用的Hive Metastore版本与其他组件(如Hadoop、Spark等)不兼容,可能会导致Canary。在这种情况下,可以尝试升级或降级Hive Metastore版本,以与其他组件保持兼容性。 最后,如果以上方法都没有解决问题,可以尝试重启整个Hive集群。有时候,重启可以解决一些不明原因的故障。 综上所述,当Hive Metastore Canary时,我们可以通过检查Hive Metastore服务、配置文件、数据库连接以及版本兼容性来解决问题。如果以上方法都无效,我们可以尝试重启整个Hive集群。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值