Hive MetaTool
Hive MetaTool
Hive MetaTool은 관리자가 메타스토어에 있는 데이터베이스·테이블·파티션 레코드의 location 필드를 일괄 수정할 수 있게 해주는 도구예요. HDFS NameNode 주소가 바뀌었을 때나 HA NN으로 전환할 때 특히 유용합니다.
출처: 문서
본문
Hive 0.10.0에서 도입되었습니다. HIVE-3056과 HIVE-3443 참고.
Hive MetaTool은 관리자가 메타스토어의 데이터베이스·테이블·파티션 레코드에 있는 location 필드를 일괄 갱신(bulk update)할 수 있게 해줍니다. 다음 기능을 제공합니다:
- NN(NameNode)을 참조하는 메타스토어 레코드에서 HDFS NN(NameNode) location을 검색·치환하는 기능. 한 가지 용도는 Hive 배포를 HDFS HA NN(HDFS 고가용성 NameNode)으로 전환하는 것입니다.
- 메타스토어에 대해 JDOQL을 실행하는 커맨드 라인 도구. 메타스토어에 대해 JDOQL을 실행하는 기능은 사용자와 Hive 개발자 모두에게 유용한 디버깅 도구입니다.
metatool 커맨드
metatool 커맨드는 다음 옵션으로 Hive MetaTool을 호출합니다:
| Option | Description |
|---|---|
| -listFSRoot | 현재 파일 시스템 루트(NameNode)의 위치를 출력합니다. 값은 hdfs:// scheme으로 접두됩니다. |
| -updateLocation <new-loc> <old-loc> | 메타스토어의 레코드를 새 NameNode 위치(파일 시스템 루트 위치)를 가리키도록 갱신합니다. new-loc와 old-loc은 모두 유효한 호스트명과 scheme을 가진 유효한 URI여야 합니다. HDFS HA NN으로 업그레이드할 때 new-loc은 dfs.nameservices 속성의 값과 일치해야 합니다. old-loc은 listFSRoot 옵션이 반환한 값과 일치해야 합니다. dryRun 옵션으로 실행하면 변경 사항이 표시만 되고 저장되지는 않습니다. serdepropKey/tablePropKey 옵션으로 실행하면, updateLocation은 지정된 serde-prop-key/table-prop-key를 찾아 그 값이 있으면 갱신합니다. |
| -serdePropKey <serde-prop-key> | 값 필드가 HDFS NameNode 위치를 참조해 갱신이 필요할 수 있는 SerDe 속성 키를 지정합니다. 예를 들어 Haivvero 스키마 URL을 갱신하려면 이 인자에 schema.url을 지정합니다. 이 옵션은 updateLocation 옵션에서만 유효합니다. |
| -tablePropKey <table-prop-key> | 값 필드가 HDFS NameNode 위치를 참조해 갱신이 필요할 수 있는 테이블 속성 키를 지정합니다. 예를 들어 Avro SerDe 스키마 URL을 갱신하려면 이 인자에 avro.schema.url을 지정합니다. 이 옵션은 updateLocation 옵션에서만 유효합니다. |
| -dryRun | updateLocation 변경의 드라이 런을 수행합니다. updateLocation 변경 사항이 표시만 되고 저장되지는 않습니다. 이 옵션은 updateLocation 옵션에서만 유효합니다. |
| -executeJDOQL <query-string> | 주어진 JDOQL 쿼리를 실행합니다. |
| -help | 명령 옵션과 설명 목록을 출력합니다. |
어떤 Avro SerDe 버전을 쓰는지 확실하지 않다면, serdePropKey와 tablePropKey 인자를 해당 키 값과 함께 모두 updateLocation에 전달하세요.
Hive 구성 디렉터리(Hive Configuration Directory)
metatool은 Hive 관리자용 커맨드이며 메타스토어 RDBMS에 직접 접근해야 합니다. 일부 환경에서는 RDBMS 로그인 정보(특히 비밀번호 또는 비밀번호 키)가 메타스토어 서버 호스트나 메타스토어 서버 전용 구성 디렉터리(더 제한적인 파일 시스템 권한)에만 저장되어 있습니다. 그런 경우 메타스토어 서버 머신에서 hive 사용자로 실행하고 HIVE_CONF_DIR 환경 변수를 적절히 설정해야 합니다(예: export HIVE_CONF_DIR=*<path to metastore server config dir>*).
사용 예시 (Usage Example)
다음 metatool 커맨드는 updateLocation, tablePropKey, serdePropKey 옵션을 사용해 NameNode 위치를 hdfs://namenode2:8020에서 hdfs://localhost:9000으로 갱신합니다.
./hive --service metatool -updateLocation hdfs://localhost:9000 hdfs://namenode2:8020 -tablePropKey avro.schema.url -serdePropKey avro.schema.url
Initializing HiveMetaTool..
15/04/22 14:18:42 INFO metastore.ObjectStore: ObjectStore, initialize called
15/04/22 14:18:42 INFO DataNucleus.Persistence: Property hive.metastore.integral.jdo.pushdown unknown - will be ignored
15/04/22 14:18:42 INFO DataNucleus.Persistence: Property datanucleus.cache.level2 unknown - will be ignored
15/04/22 14:18:43 INFO metastore.ObjectStore: Setting MetaStore object pin classes with hive.metastore.cache.pinobjtypes="Table,StorageDescriptor,SerDeInfo,Partition,Database,Type,FieldSchema,Order"
15/04/22 14:18:43 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:43 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:44 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:44 INFO DataNucleus.Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table.
15/04/22 14:18:44 INFO DataNucleus.Query: Reading in results for query "org.datanucleus.store.rdbms.query.SQLQuery@0" since the connection used is closing
15/04/22 14:18:44 INFO metastore.MetaStoreDirectSql: Using direct SQL, underlying DB is MYSQL
15/04/22 14:18:44 INFO metastore.ObjectStore: Initialized ObjectStore
Looking for LOCATION_URI field in DBS table to update..
Successfully updated the following locations..
Updated 0 records in DBS table
Looking for LOCATION field in SDS table to update..
Successfully updated the following locations..
Updated 0 records in SDS table
Looking for value of avro.schema.url key in TABLE_PARAMS table to update..
Successfully updated the following locations..
Updated 0 records in TABLE_PARAMS table
Looking for value of avro.schema.url key in SD_PARAMS table to update..
Successfully updated the following locations..
Updated 0 records in SD_PARAMS table
Looking for value of avro.schema.url key in SERDE_PARAMS table to update..
Successfully updated the following locations..
Updated 0 records in SERDE_PARAMS table
metatool로 테이블 정보를 읽어오기(모든 메타스토어 백엔드 지원).
HIVE_CONF_DIR=/etc/hive/conf/conf.server/ hive --service metatool -executeJDOQL 'select dbName+"."+tableName+"::"+colName+"="+numDVs from org.apache.hadoop.hive.metastore.model.MTableColumnStatistics';
HIVE_CONF_DIR=/etc/hive/conf/conf.server/ hive --service metatool -executeJDOQL 'select dbName+"."+tableName+"("+partitionName+")::"+colName+"="+numDVs from org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics';
더 알아보기 (Learn more)
MetaTool은 NameNode 주소 변경 시 메타스토어에 흩어진 location 필드를 일괄 치환하는 관리 도구예요. -dryRun으로 미리 확인한 뒤 실행하는 것을 권장하고, Avro 스키마 URL 같은 속성은 serdePropKey/tablePropKey로 함께 갱신할 수 있습니다.