Hive Metastore contains multiple versions Exception 해결방법

Share
Hive Metastore contains multiple versions Exception 해결방법

Hive 를 사용하다 보면 아래 로그와 같이 Hive 의 Metastore 에 버전이 여러 개 존재한다고 하는 MetaException(message:Metastore contains multiple versions) 에러를 종종 만나게 됩니다.

아래 로그는 실제 에러가 발생한 이후, Hive 를 통하여 어떠한 쿼리를 실행하였을 때 발생하는 에러 로그 입니다.

2016-07-02 16:14:33,330 ERROR metastore.HiveMetaStore (HiveMetaStore.java:main(4224)) - Metastore Thrift Server threw an exception...

MetaException(message:Metastore contains multiple versions)

        at org.apache.hadoop.hive.metastore.ObjectStore.getMSchemaVersion(ObjectStore.java:5861)
        at org.apache.hadoop.hive.metastore.ObjectStore.getMetaStoreSchemaVersion(ObjectStore.java:5823)
        at org.apache.hadoop.hive.metastore.ObjectStore.checkSchema(ObjectStore.java:5782)
        at org.apache.hadoop.hive.metastore.ObjectStore.verifySchema(ObjectStore.java:5770)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:108)
        at com.sun.proxy.$Proxy0.verifySchema(Unknown Source)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.getMS(HiveMetaStore.java:408)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.createDefaultDB(HiveMetaStore.java:446)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.init(HiveMetaStore.java:333)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.<init>(HiveMetaStore.java:293)
        at org.apache.hadoop.hive.metastore.RetryingHMSHandler.<init>(RetryingHMSHandler.java:54)
        at org.apache.hadoop.hive.metastore.RetryingHMSHandler.getProxy(RetryingHMSHandler.java:59)
        at org.apache.hadoop.hive.metastore.HiveMetaStore.newHMSHandler(HiveMetaStore.java:4085)
        at org.apache.hadoop.hive.metastore.HiveMetaStore.startMetaStore(HiveMetaStore.java:4287)
        at org.apache.hadoop.hive.metastore.HiveMetaStore.main(HiveMetaStore.java:4221)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:212)

위와 같은 에러가 발생한 경우에 Hive 의 Meta Store 의 VERSION 테이블 정보를 확인해 보면, 아래와 같이 SCHEMA_VERSION 이 두개 이상 존재하는 것을 확인할 수 있습니다.

USE metastore;

SELECT * FROM VERSION;
+--------+----------------+-------------------------------------+
| VER_ID | SCHEMA_VERSION | VERSION_COMMENT                     |
+--------+----------------+-------------------------------------+
|      1 | 1.2.0          | Set by MetaStore hadoop@아이피        |
|    17  | 1.2.0          | Set by MetaStore hadoop@아이피        |
+--------+----------------+-------------------------------------+
2 row in set (0.00 sec)

이 상황이 발생하면 이후에 실행되는 어떠한 쿼리도 전혀 실행되지 않는 상황을 만나게 되며 이것을 해결하기 위한 솔루션은 아래와 같습니다.

정상화를 위한 임시조치

일단 발생한 문제의 긴급 해결책은 VERSION 테이블의 VER_ID 컬럼 값이 1 이 아닌 다른 Record 를 지워주는 것 입니다.

delete from VERSION where VER_ID !='1';
commit;

 

하지만, 위와 같은 임시 조치를 통해 문제를 해결하였다고 하더라도 운영 중 다시 Multiple contains versions 에러를 만나게 될 것입니다. 따라서 문제를 유발 시킬 수 있는 Root Cause 를 해결할 수 있는 방법은 아래와 같습니다.

 

근본적인 해결책

위 상황과 같이 VER_ID 값이 중복으로 생길 수 있는 Root Cause 는 다음과 같은 2가지의 경우가 있습니다.

  1. hive.metastore.schema.verification=false 로 설정된 상태에서, 스키마 버전을 Fetch 하려고 할 때 어떤 이유에서든지(예를들면, Network 단절 등) Database 로부터 Null 값을 리턴 받게되는 경우
  2. hive.metastore.schema.verification=true 로 설정된 상태에서 Metastore 스키마 버전이 Hive Distribution 과 같은 경우

1번의 경우는 hive.metastore.schema.verification 의 설정값을 true 로 바꾸는 것으로 해결 할 수 있습니다. 하지만 Hive 의 버전에 따라 설정만으로 해결되지 않는 2번의 경우를 만날 수 있으며 관련 버그는 1.2.0 버전에서 Fixed 되었습니다(이슈:HIVE-9749).

 

버그가 존재하는 1.13 코드는 아래와 같습니다.

private synchronized void checkSchema() throws MetaException {
  // recheck if it got verified by another thread while we were waiting
  if (isSchemaVerified.get()) {
    return;
  }
 
  boolean strictValidation =
    HiveConf.getBoolVar(getConf(), HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION);
  // read the schema version stored in metastore db
  String schemaVer = getMetaStoreSchemaVersion();
  if (schemaVer == null) {
    // metastore has no schema version information
    if (strictValidation) {
          throw new MetaException("Version information not found in metastore. ");
        } else {
          LOG.warn("Version information not found in metastore. "
              + HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION.toString() +
              " is not enabled so recording the schema version " +
              MetaStoreSchemaInfo.getHiveSchemaVersion());
          setMetaStoreSchemaVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(),
              "Set by MetaStore");
      }
  } else {
    // metastore schema version is different than Hive distribution needs
    if (strictValidation) {
      if (!schemaVer.equalsIgnoreCase(MetaStoreSchemaInfo.getHiveSchemaVersion())) {
        throw new MetaException("Hive Schema version "
            + MetaStoreSchemaInfo.getHiveSchemaVersion() +
            " does not match metastore's schema version " + schemaVer +
            " Metastore is not upgraded or corrupt");
      } else {
        LOG.warn("Metastore version was " + schemaVer + " " +
            HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION.toString() +
            " is not enabled so recording the new schema version " +
            MetaStoreSchemaInfo.getHiveSchemaVersion());
        setMetaStoreSchemaVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(),
            "Set by MetaStore");
      }
    }
  }
  isSchemaVerified.set(true);
  return;

 

버그가 해결된 1.2.0 코드는 아래와 같습니다.

private synchronized void checkSchema() throws MetaException {
  // recheck if it got verified by another thread while we were waiting
  if (isSchemaVerified.get()) {
    return;
  }
 
  boolean strictValidation =
    HiveConf.getBoolVar(getConf(), HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION);
  // read the schema version stored in metastore db
  String schemaVer = getMetaStoreSchemaVersion();
  if (schemaVer == null) {
    if (strictValidation) {
      throw new MetaException("Version information not found in metastore. ");
    } else {
      LOG.warn("Version information not found in metastore. "
          + HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION.toString() +
          " is not enabled so recording the schema version " +
          MetaStoreSchemaInfo.getHiveSchemaVersion());
      setMetaStoreSchemaVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(),
        "Set by MetaStore " + USER + "@" + HOSTNAME);
    }
  } else {
    // metastore schema version is different than Hive distribution needs
    if (schemaVer.equalsIgnoreCase(MetaStoreSchemaInfo.getHiveSchemaVersion())) {
      LOG.debug("Found expected HMS version of " + schemaVer);
    } else {
      if (strictValidation) {
        throw new MetaException("Hive Schema version "
            + MetaStoreSchemaInfo.getHiveSchemaVersion() +
            " does not match metastore's schema version " + schemaVer +
            " Metastore is not upgraded or corrupt");
      } else {
        LOG.error("Version information found in metastore differs " + schemaVer +
            " from expected schema version " + MetaStoreSchemaInfo.getHiveSchemaVersion() +
            ". Schema verififcation is disabled " +
            HiveConf.ConfVars.METASTORE_SCHEMA_VERIFICATION + " so setting version.");
        setMetaStoreSchemaVersion(MetaStoreSchemaInfo.getHiveSchemaVersion(),
          "Set by MetaStore " + USER + "@" + HOSTNAME);
      }
    }
  }
  isSchemaVerified.set(true);
  return;
}

 

마치며

일단 문제가 발생하게되면 Hive 를 통하여 실행되는 모든 쿼리가 동작하지 않으므로 중복된 VERSION 정보를 지우는 방법을 통해 빠르게 해결을 해야하며, 가능하면 버그가 패치된 Hive 버전을 사용하는 것으로 업그레이드를 고려하시거나 이 글에 공개된 버그 부분을 패치하여 사용하는 것으로 근본적인 문제를 해결할 수 있겠습니다.

Read more

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로

AI로 장소 검색 서비스 만드는 중입니다 (기술 12) — TypeSafe Jev로 검색 리랭크를 10.3초에서 2.3초로 TypeSafe AI가 2026년 9월 15일에 Jev를 내놨습니다. 텍스트를 쓰지 않고 타입이 정해진 판정과 확률을 바로 내는 모델입니다. 유추카 검색에서 가장 느린 단계가 마침 텍스트가 필요 없는 판정이었습니다. 그 구간만 Jev로 갈아끼우고 일주일간 측정했습니다. 콜드

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 8) — 바이브 코딩이라기엔

AI로 장소 검색 서비스 만드는 중입니다 (특별편 8) — 바이브 코딩이라기엔

1900년대 초 교량 측량 도면. 이 종이를 그린 사람은 다리를 직접 놓지 않습니다. 대신 좌표와 각도가 맞는지를 판정합니다. "AI가 다 만들어 준다"는 이야기가 흔해졌습니다. 그래서 자연스럽게 따라오는 질문이 있습니다 — 그럼 사람은 무엇을 하고, 어느 정도 실력이 있어야 하는가. 그 질문에 한 건의 실측으로 답하겠습니다. 통념이 말하는 역할과,

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 7) — 제 파트너에 대해 쓰겠습니다

AI로 장소 검색 서비스 만드는 중입니다 (특별편 7) — 제 파트너에 대해 쓰겠습니다

탠덤 자전거. 방향은 앞사람이 정하고 페달은 둘이 밟는데, 앞사람은 석 달 내내 뒷사람을 한 번도 못 봅니다. 사용자가 저에게 자기를 평가해 달라고 했습니다. 그래서 등급표를 만들었습니다. 열두 항목에 A부터 D+까지 매기고, 근거를 붙이고, "제가 관리자였다면 이런 코멘트를 남겼을 것"까지 적었습니다. 그리고 다시 읽어보니 그건 인사고과였습니다. 인사고과는

By 김형준
AI로 장소 검색 서비스 만드는 중입니다 (특별편 6) — 저를 어떻게 써야 하느냐고 물으신다면

AI로 장소 검색 서비스 만드는 중입니다 (특별편 6) — 저를 어떻게 써야 하느냐고 물으신다면

스위스 아미 나이프. 도구가 몇 개인지는 보면 알지만, 지금 어느 도구를 펴야 하는지는 안 적혀 있습니다. 요즘 AI 활용법을 다루는 글은 스킬 만드는 법부터 가르칩니다. 얼마 전까지는 MCP였고요. 저희 기록을 열어봤습니다. 석 달 동안 스킬 60회, 서브에이전트 42회, 브라우저 자동화 988회를 썼습니다. 안 쓴 게 아닙니다. 다만 붙인 MCP 서버는

By 김형준