为了支持 Las Catalog 的元数据容灾备份,Las Catalog 提供了元数据导出工具,用户可以通过 Spark 作业的方式,将自己在 Las Catalog 中的元数据导出到客户的 HMS 中或 TOS 中。本文介绍如何通过运行 Spark 作业的方式导出元数据。
登录 EMR Master 节点。
请参照如下示例,根据自己的环境准备一份 yaml 文件,yaml 文件准备好之后,上传到 HDFS 或者 TOS 路径下。
mode: las_to_hive lasClientInfo: akMode: AUTO endPoint: thrift://cs.lakeformation.las.cn-beijing.ivolces.com:48869 regionId: cn-beijing hmsClientInfo: hiveConfPath: /etc/emr/hive/conf/hive-site.xml runOptions: includeCatalogPrefixs: [las_exporter] includeDatabasePrefixs: [las_exporter] includeTablePrefixs: [exporter_table_1000] batchSize: 1000 objectTypes: - catalog - database - table - partition - function
--上传到当前目录 hadoop fs -put application.jar ./application.jar
--上传到 tos://exporter_bucket/exporter_las 目录下 hadoop fs -put export_to_hive.yaml tos://exporter_bucket/exporter_las/export_to_hive.yaml
参数名 | 默认值 | 备注说明 | |
---|---|---|---|
mode | las_to_tos | 可取值
| |
lasClientInfo | akMode | MANUAL | 可取值:
说明
|
accessKeyId | — | 访问 LAS 元数据的用户 ID,当 akMode 是 AUTO 时,可以为空 | |
accessKeySecret | — | 访问 LAS 元数据的用户密码,当 akMode 是 AUTO 时,可以为空 | |
endPoint | — | 取值:
| |
regionId |
| 可取值
| |
hmsClientInfo | hiveConfPath | /etc/emr/hive/conf/hive-site.xml | 半托管环境配置,hive 的 conf 文件所在的地址 |
kerberosInfo.principal | — | 半托管开启Kerberos需要配置,访问 hms 的 principl | |
kerberosInfo.keytab | — | 半托管开启Kerberos需要配置,访问 hms 的 keytab 地址 | |
hmsClientInfo | metastoreUris | — | 要导出的目标 HiveMetastore uri 地址,比如 thrift://xxx:9083 |
jdbcDriver | com.mysql.cj.jdbc.Driver | 要导出的目标 HiveMetastore 使用的数据库连接 Driver 类 | |
jdbcUri | — | 要导出的目标 HiveMetastore 使用的数据库连接 URI | |
jdbcUserName | — | 要导出的目标HiveMetastore 使用的数据库连接 用户名 | |
jdbcPassword | — | 要导出的目标HiveMetastore 使用的数据库连接 密码 | |
runOptions | includeCatalogPrefixs | [hive] | 要导出的 catalog 名字前缀,因为运行环境的原因,目前只支持单个 catalog 的导入,不支持多catalog同时导入。 注意 如果 catalog 的名称不是默认值 hive,那么用户侧的 HMS 中需要设置metastore.catalog.default 为该名称。 |
includeDatabasePrefixs | — |
| |
includeTablePrefixs | — |
| |
includeFunctionPrefixs | — |
| |
objectTypes | — | 要导出的对象类型,可以同时选择多个类型
| |
batchSize | 1000 | 读取las或者写入 hive/tos 每个 batch 大小,当前最大值是 1000 | |
sparkTaskBatchSize | 200000 | 单个 sparkTask 处理的元数据分区个数。导出的分区个数超过20w会增加一个 spark task 处理。 | |
locationMappings
| — | 如果模式设置的是的 tos_to_hive,可以配置填写地址的映射(不填默认 LocationUri 保持一致),source 表示 tos 中存储的元数据的 LocationUri (注意和 tos 本身的地址做区分),target 表示要导入到的 hive 中的 locationUri,需要反斜杠'/'结尾,例如:
| |
fixIfInConsistence | ignore | 如果元数据在 Las 和 Hive,库/表名字都存在,一致性处理策略
| |
outputBaseDir | — | 若导出模式是导出到 TOS 中,则需要配置 | |
inputBaseDir | — | 若从 TOS 导入数据到 Hive ,则需要配置 |
metastore.catalog.default=XX
**,**XX是需要导出的Catalog名称,配置完成后需重启 HiveMetastore。wget https://lasformation-cn-beijing.tos-cn-beijing.ivolces.com/las-exporter/application.jar
例示:将下载的 jar 包和配置文件上传到 tos://exporter_bucket/exporter_las目录下 。
hadoop fs -put application.jar tos://exporter_bucket/exporter_las/application.jar
spark-submit --master yarn --deploy-mode cluster --driver-memory 12G --executor-memory 8G --executor-cores 2 --num-executors 5 --conf spark.sql.shuffle.partitions=200 --conf spark.sql.adaptive.enabled=false --class bytedance.olap.las.Exporter ./application.jar ./export_to_hive.yaml
spark-submit --master yarn --deploy-mode cluster --driver-memory 12G --executor-memory 8G --executor-cores 2 --num-executors 5 --conf spark.sql.shuffle.partitions=200 --conf spark.sql.adaptive.enabled=false --class bytedance.olap.las.Exporter tos://exporter_bucket/exporter_las/application.jar tos://exporter_bucket/exporter_las/export_to_hive.yaml
上面命令中的加粗的路径,需要跟第3步中的application.jar和配置文件路径相同。如果分区数量较多,可以适当调大num-executors
的数量,比如100w分区配置100个,这样能增加写入的并行度,加快写入的速度。
从 Spark History Server UI 中查看本次导出任务的执行详情日志,或者从Hive 中直接通过命令行的方式查看具体的元数据信息是否导入成功。