日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Hive Metastore 连接报错

發布時間:2023/11/27 生活经验 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 unixesreturn (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 emptyString 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.*/@Overridepublic 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

總結

以上是生活随笔為你收集整理的Hive Metastore 连接报错的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。