-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-875] Abstract hudi-sync-common, and support hudi-hive-sync #1810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
4c08849
3697950
458d7eb
fcc3a9c
e350377
3808c32
4dae21d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,11 @@ | |
| package org.apache.hudi | ||
|
|
||
| import java.util | ||
| import java.util.Properties | ||
|
|
||
| import org.apache.avro.Schema | ||
| import org.apache.avro.generic.GenericRecord | ||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.fs.{FileSystem, Path} | ||
| import org.apache.hadoop.hive.conf.HiveConf | ||
| import org.apache.hudi.DataSourceWriteOptions._ | ||
|
|
@@ -30,9 +32,11 @@ import org.apache.hudi.common.fs.FSUtils | |
| import org.apache.hudi.common.model.HoodieRecordPayload | ||
| import org.apache.hudi.common.table.HoodieTableMetaClient | ||
| import org.apache.hudi.common.table.timeline.HoodieActiveTimeline | ||
| import org.apache.hudi.common.util.ReflectionUtils | ||
| import org.apache.hudi.config.HoodieWriteConfig | ||
| import org.apache.hudi.exception.HoodieException | ||
| import org.apache.hudi.hive.{HiveSyncConfig, HiveSyncTool} | ||
| import org.apache.hudi.sync.common.AbstractSyncTool | ||
| import org.apache.log4j.LogManager | ||
| import org.apache.spark.api.java.{JavaRDD, JavaSparkContext} | ||
| import org.apache.spark.rdd.RDD | ||
|
|
@@ -209,7 +213,10 @@ private[hudi] object HoodieSparkSqlWriter { | |
| STREAMING_RETRY_CNT_OPT_KEY -> DEFAULT_STREAMING_RETRY_CNT_OPT_VAL, | ||
| STREAMING_RETRY_INTERVAL_MS_OPT_KEY -> DEFAULT_STREAMING_RETRY_INTERVAL_MS_OPT_VAL, | ||
| STREAMING_IGNORE_FAILED_BATCH_OPT_KEY -> DEFAULT_STREAMING_IGNORE_FAILED_BATCH_OPT_VAL, | ||
| SYNC_CLIENT_TOOL_CLASS -> DEFAULT_SYNC_CLIENT_TOOL_CLASS, | ||
| //just for backwards compatiblity | ||
| HIVE_SYNC_ENABLED_OPT_KEY -> DEFAULT_HIVE_SYNC_ENABLED_OPT_VAL, | ||
| HUDI_SYNC_ENABLED_OPT_KEY -> DEFAULT_HUDI_SYNC_ENABLED_OPT_VAL, | ||
| HIVE_DATABASE_OPT_KEY -> DEFAULT_HIVE_DATABASE_OPT_VAL, | ||
| HIVE_TABLE_OPT_KEY -> DEFAULT_HIVE_TABLE_OPT_VAL, | ||
| HIVE_BASE_FILE_FORMAT_OPT_KEY -> DEFAULT_HIVE_BASE_FILE_FORMAT_OPT_VAL, | ||
|
|
@@ -255,6 +262,43 @@ private[hudi] object HoodieSparkSqlWriter { | |
| hiveSyncConfig | ||
| } | ||
|
|
||
| private def metaSync(parameters: Map[String, String], | ||
| basePath: Path, | ||
| hadoopConf: Configuration): Boolean = { | ||
| val hiveSyncEnabled = parameters.get(HIVE_SYNC_ENABLED_OPT_KEY).exists(r => r.toBoolean) | ||
| var metaSyncEnabled = parameters.get(HUDI_SYNC_ENABLED_OPT_KEY).exists(r => r.toBoolean) | ||
|
vinothchandar marked this conversation as resolved.
Outdated
|
||
| var syncClientToolClass = parameters.get(SYNC_CLIENT_TOOL_CLASS).get | ||
| // for backward compatibility | ||
| if (hiveSyncEnabled) { | ||
| metaSyncEnabled = true | ||
| syncClientToolClass = DEFAULT_SYNC_CLIENT_TOOL_CLASS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if user sync both hive and dla meta, the dla meta would not get synced.?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this will back compatibility
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would users sync to both? down the line it may make sense to provide support for syncing to multiple things. but even here, if we just append the HiveSync class when
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, when user set hiveSyncEnabled and --sync-tool-classes, sync both hive and --sync-tool-classes make sense. i will fix it |
||
| } | ||
| var metaSyncSuccess = true | ||
| if (metaSyncEnabled) { | ||
| val impls = syncClientToolClass.split(",") | ||
| impls.foreach(impl => { | ||
| val syncSuccess = impl.trim match { | ||
| case DEFAULT_SYNC_CLIENT_TOOL_CLASS => { | ||
| log.info("Syncing to Hive Metastore (URL: " + parameters(HIVE_URL_OPT_KEY) + ")") | ||
|
vinothchandar marked this conversation as resolved.
|
||
| val fs = FSUtils.getFs(basePath.toString, hadoopConf) | ||
| syncHive(basePath, fs, parameters) | ||
| } | ||
| case _ => { | ||
| val fs = FSUtils.getFs(basePath.toString, hadoopConf) | ||
|
lw309637554 marked this conversation as resolved.
Outdated
|
||
| val properties = new Properties(); | ||
| properties.putAll(parameters) | ||
| properties.put("basePath", basePath.toString) | ||
| val syncHoodie = ReflectionUtils.loadClass(impl.trim, Array[Class[_]](classOf[Properties], classOf[FileSystem]), properties, fs).asInstanceOf[AbstractSyncTool] | ||
| syncHoodie.syncHoodieTable() | ||
|
vinothchandar marked this conversation as resolved.
|
||
| true | ||
| } | ||
| } | ||
| metaSyncSuccess = metaSyncSuccess && syncSuccess | ||
| }) | ||
| } | ||
| metaSyncSuccess | ||
| } | ||
|
|
||
| private def checkWriteStatus(writeStatuses: JavaRDD[WriteStatus], | ||
| parameters: Map[String, String], | ||
| client: HoodieWriteClient[_], | ||
|
|
@@ -280,17 +324,9 @@ private[hudi] object HoodieSparkSqlWriter { | |
| else { | ||
| log.info("Commit " + instantTime + " failed!") | ||
| } | ||
|
|
||
| val hiveSyncEnabled = parameters.get(HIVE_SYNC_ENABLED_OPT_KEY).exists(r => r.toBoolean) | ||
| val syncHiveSucess = if (hiveSyncEnabled) { | ||
| log.info("Syncing to Hive Metastore (URL: " + parameters(HIVE_URL_OPT_KEY) + ")") | ||
| val fs = FSUtils.getFs(basePath.toString, jsc.hadoopConfiguration) | ||
| syncHive(basePath, fs, parameters) | ||
| } else { | ||
| true | ||
| } | ||
| val metaSyncSuccess = metaSync(parameters, basePath, jsc.hadoopConfiguration()) | ||
| client.close() | ||
| commitSuccess && syncHiveSucess | ||
| commitSuccess && metaSyncSuccess | ||
| } else { | ||
| log.error(s"$operation failed with $errorCount errors :") | ||
| if (log.isTraceEnabled) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <artifactId>hudi</artifactId> | ||
| <groupId>org.apache.hudi</groupId> | ||
| <version>0.6.0-SNAPSHOT</version> | ||
| <relativePath>../../hudi</relativePath> | ||
| </parent> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>hudi-dla-sync</artifactId> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <properties> | ||
| <hadoop.aliyun.version>3.2.1</hadoop.aliyun.version> | ||
| <mysql.connector.java.version>5.1.47</mysql.connector.java.version> | ||
| <aliyun.sdk.oss.version>3.1.0</aliyun.sdk.oss.version> | ||
| <aliyun.java.sdk.core.version>3.7.1</aliyun.java.sdk.core.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <!-- Hoodie --> | ||
| <dependency> | ||
| <groupId>org.apache.hudi</groupId> | ||
| <artifactId>hudi-common</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.hudi</groupId> | ||
| <artifactId>hudi-sync-common</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.hudi</groupId> | ||
| <artifactId>hudi-hive-sync</artifactId> | ||
| <version>${project.version}</version> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>org.apache.hadoop</groupId> | ||
| <artifactId>hadoop-hdfs</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.apache.hive</groupId> | ||
| <artifactId>hive-shims</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>commons-lang</groupId> | ||
| <artifactId>commons-lang</artifactId> | ||
| </exclusion> | ||
|
|
||
| <exclusion> | ||
| <groupId>org.apache.zookeeper</groupId> | ||
| <artifactId>zookeeper</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>mysql</groupId> | ||
| <artifactId>mysql-connector-java</artifactId> | ||
| <version>${mysql.connector.java.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.hadoop</groupId> | ||
| <artifactId>hadoop-aliyun</artifactId> | ||
| <version>${hadoop.aliyun.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.aliyun.oss</groupId> | ||
| <artifactId>aliyun-sdk-oss</artifactId> | ||
| <version>${aliyun.sdk.oss.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.aliyun</groupId> | ||
| <artifactId>aliyun-java-sdk-core</artifactId> | ||
| <version>${aliyun.java.sdk.core.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- Logging --> | ||
| <dependency> | ||
| <groupId>log4j</groupId> | ||
| <artifactId>log4j</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.parquet</groupId> | ||
| <artifactId>parquet-avro</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- Hadoop --> | ||
| <dependency> | ||
| <groupId>org.apache.hadoop</groupId> | ||
| <artifactId>hadoop-common</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.hive</groupId> | ||
| <artifactId>hive-exec</artifactId> | ||
| <version>${hive.version}</version> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>commons-lang</groupId> | ||
| <artifactId>commons-lang</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.apache.commons</groupId> | ||
| <artifactId>commons-lang3</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.apache.zookeeper</groupId> | ||
| <artifactId>zookeeper</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <resources> | ||
| <resource> | ||
| <directory>src/main/resources</directory> | ||
| </resource> | ||
| </resources> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.rat</groupId> | ||
| <artifactId>apache-rat-plugin</artifactId> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <version>${maven-jar-plugin.version}</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>test-jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.jacoco</groupId> | ||
| <artifactId>jacoco-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use HiveSyncTool.class.getName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done