Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient報錯,問題排查


背景

最近在整合pyspark與hive,新安裝spark-2.3.3以客戶端的方式訪問hive數據,運行方式使用spark on yarn,但是在配置spark讀取hive數據的時候,這里直接把hive下的hive-site.xml復制到spark目錄下,啟動了一次spark,上面的問題就出現了。

網上的說法:

hive元數據問題,需要重新初始化hive的元數據
但是這個方法肯定不適合我,因為倉庫里的表不能受影響,上千張表呢,如果初始化了,所有表都要重新創建。

排查過程

* 首先查看服務器上/tmp/${user}/hive.log文件,這個是公司服務器當時配置的詳細的hive執行日志。
 在日志中,有一段報錯:
2019-07-06T10:01:53,737 ERROR [370c0a81-c922-4c61-8315-264c39b372c3 main] metastore.RetryingHMSHandler: MetaException(message:Hive Schema version 3.1.0 does not match metastore's schema version 1.2.0 Metastore is not upgraded or corrupt)
        at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:9063)
        at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:9027)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
這里的意思是,hive的版本是3.1.0,但是元數據中的版本信息是1.2.0,因此報錯。

* 到hive的元數據庫里查了下version表里的數據,確實版本是1.2.0

問題原因

這里猜測,spark在讀取hive元數據的時候,因為spark是直接從官網上下載的,可能官網上的spark是用hive1.2.0版本編譯的,所以,它默認使用的1.2.0,導致在啟動的時候,修改了hive的元數據

但是具體的原因還不知道
下面會拿官網上的spark源碼手動編譯測試一下

解決辦法

  1. 直接修改version表的數據
select * from version;
update VERSION set SCHEMA_VERSION='2.1.1' where  VER_ID=1;

2、在hvie-site.xml中關閉版本驗證

<property>
    <name>hive.metastore.schema.verification</name>
    <value>false</value>
</property>

深入研究

在spark官網上查看了相關的資料,發現,在官網上下載的spark安裝包,默認編譯的hive版本是1.2.1的,所以每次啟動spark的時候,會檢查hive的版本。如果采用hive的默認配置,如果不一樣,

就會修改version

一開始嘗試着下載spark源碼重新編譯spark安裝包,編譯執行hive的版本為3.1.1,但是,發現每次指定hive的版本,maven下載依賴的時候,都會報錯。
報錯信息如下:

后來想了個折中的辦法,spark還是使用原始版本,但是修改一下hive-site.xml文件。
注意:這里修改的是spark的conf下的hive-site.xml,原始的hive里的不需要修改

  <property>
    <name>hive.metastore.schema.verification</name>
    <value>true</value>
    <description>
      Enforce metastore schema version consistency.
      True: Verify that version information stored in metastore matches with one from Hive jars.  Also disable automatic
            schema migration attempt. Users are required to manually migrate schema after Hive upgrade which ensures
            proper metastore schema migration. (Default)
      False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.
    </description>
  </property>
  <property>
    <name>hive.metastore.schema.verification.record.version</name>
    <value>false</value>
    <description>
      When true the current MS version is recorded in the VERSION table. If this is disabled and verification is
       enabled the MS will be unusable.
    </description>
  </property>

這兩個配置,hive.metastore.schema.verification如果設置為true,那么每次啟動hive或者spark的時候,都會檢查hive的版本。為false,則會告警
hive.metastore.schema.verification.record.version如果設置為true,每次啟動spark的時候,如果檢查了hive的版本和spark編譯的版本不一致,那么就會修改hive的元數據

這里的修改需要設置hive.metastore.schema.verification=false 且hive.metastore.schema.verification.record.version=false
如過這兩個都為true,那么spark會修改hive元數據
如果hive.metastore.schema.verification=true,並且hive.metastore.schema.verification.record.version=false,這時候啟動spark就會報錯:

Caused by: MetaException(message:Hive Schema version 1.2.0 does not match metastore's schema version 3.1.0 Metastore is not upgraded or corrupt)
	at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:6679)
	at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:6645)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

如果設置hive.metastore.schema.verification=false 且hive.metastore.schema.verification.record.version=true,spark還是會修改hive的元數據

所以,只要設置hive.metastore.schema.verification.record.version=false就可以了,但是為了保險起見,我兩個都設置成false了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM