背景

项目中需要通过一些自定义的组件来操控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,着实费解了一些时间。

Hive Metastore 连接报错的更多相关文章

  1. CDH hive metastore启动报错:Unknown column 'A0.SCHEMA_VERSION_V2' in 'field list'

    新集群CDH版本,刚刚搭建起来,5个节点起了1个hive服务,另外5个节点又单独起了1个hive服务,一共2个人hive服务.老哥对其中的一个hive进行了数据迁移,对hive数据库进行了替换,就这样 ...

  2. Hive 报错:java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

    在配置好hive后启动报错信息如下: [walloce@bigdata-study- hive--cdh5.3.6]$ bin/hive Logging initialized using confi ...

  3. 【原创】大叔问题定位分享(31)hive metastore报错

    hive metastore在建表时报错 [pool-5-thread-2]: MetaException(message:Got exception: java.net.ConnectExcepti ...

  4. 报错:org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.

    报错环境: CDH中集成的hive服务,启动报错,所以初始化一下元数据. 配置文件:/etc/hive/conf hive-site.xml 命令目录:/opt/cloudera/parcels/CD ...

  5. hive报错:Caused by: ERROR XBM0H: Directory /var/lib/hive/metastore/metastore_db cannot be created.

    在cdh集群中,删除之前的hive服务,然后将hive添加到其他节点,然后再通过hive客户端连接hive报错: Caused by: ERROR XJ041: Failed to create da ...

  6. hive 报错FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient FAILED: Execu

    使用hive一段时间以后,今天在使用的时候突然报错,如下: hive> show databases;FAILED: Error in metadata: java.lang.RuntimeEx ...

  7. hive 报错 java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

    Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unable ...

  8. hive metastore异常 org.apache.thrift.protocol.TProtocolException: Missing version in readMessageBegin, old client

    hiveserver2的端口是10000hive.metastoe.uris 的端口9083改为10000之后 beelien 连接hiveserver2报错 Error: Could not ope ...

  9. Hive Metastore ObjectStore PersistenceManager自动关闭bug解析

    最近在测试HCatalog,由于Hcatalog本身就是一个独立JAR包,虽然它也可以运行service,但是其实这个service就是metastore thrift server,我们在写基于Hc ...

随机推荐

  1. ZZNU 2055(基姆拉尔森计算公式)

    题目链接 题意: 比如今天是2017年8月16日,星期三.下一个也是星期三的8月16日发生在2023年. 现在是日期是yyyy-mm-dd,我们希望你求出薛定谔会跳跃到那一年. 题解: emmmm.. ...

  2. 内核漏洞学习—熟悉HEVD

    一直以来内核漏洞安全给很多人的印象就是:难,枯燥.但是内核安全是否掌握是衡量一个系统安全工程师水平的标准之一,也是安全从业人员都应该掌握的基本功.本文通过详细的实例带领读者走进内核安全的大门.难度系数 ...

  3. js中call、apply、bind的使用

    写在前面的话 这三个方法都是来自Function.prototype上,所以所有的函数都可以使用. 他们有一个共同点,就是可以指定函数执行时的内部this指向. call和apply的区别在于参数的方 ...

  4. 杭电OJ之2020-2029(C语言版)

    2020. 绝对值排序 题目 Problem Description 输入n(n<=100)个整数,按照绝对值从大到小排序后输出.题目保证对于每一个测试实例,所有的数的绝对值都不相等. Inpu ...

  5. rabbitmq系列一 之简单队列

    1. rabbitmq简介 rabbitmq是一个消息代理,或者讲是一个消息中间件.主要是用来接收和转发信息的,它是对消息不做任何处理的.MQ是消费-生产者模型的一个典型的代表,一端往消息队列中不断写 ...

  6. csc命令

    CSC.exe把Visual C#程序代码编译成IL文件时,有着很多参数和开关选项.正确的了解和运用这些参数和开关有时会解 决一些看似很棘手的问题.下面就通过一张表来大致说明一下这些参数和开关的具体作 ...

  7. HTTP请求头及其作用 转

    HTTP请求头Header及其作用详解 下面是访问的一个URL,http://www.hzau.edu.cn的一个header,根据实例分析各部分的功能和作用. 1.Accept,浏览器端能够处理的内 ...

  8. docker registry push错误“server gave HTTP response to HTTPS client”

    系统环境:centos7 docker版本: 1.12.3(注意版本,可能存在不同版本设置不同的情况) docker registry版本:2.4.1 问题: 成功安装docker registry, ...

  9. express中间件原理 && 实现

    一.什么是express中间件? 什么是express中间件呢? 我们肯定都听说过这个词,并且,如果你用过express,那么你就一定用过express中间件,如下: var express = re ...

  10. 使用SharedPreference保存用户数据的步骤

    1. 声明 SharedPreferences sp; 2. 初始化 sp = this.getSharedPreferences("文件名", 0);//0代表的是私有 3. 获 ...