-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-2880] Fixing loading of props from default dir #4167
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,18 +18,21 @@ | |
|
|
||
| package org.apache.hudi.common.config; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hudi.common.fs.FSUtils; | ||
| import org.apache.hudi.common.util.Option; | ||
| import org.apache.hudi.common.util.StringUtils; | ||
| import org.apache.hudi.common.util.ValidationUtils; | ||
| import org.apache.hudi.exception.HoodieIOException; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.log4j.LogManager; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
@@ -77,7 +80,7 @@ public DFSPropertiesConfiguration(@Nonnull Configuration hadoopConf, @Nonnull Pa | |
| this.currentFilePath = filePath; | ||
| this.hoodieConfig = new HoodieConfig(); | ||
| this.visitedFilePaths = new HashSet<>(); | ||
| addPropsFromFile(filePath); | ||
| addPropsFromFile(filePath, false); | ||
| } | ||
|
|
||
| public DFSPropertiesConfiguration() { | ||
|
|
@@ -95,13 +98,9 @@ public static TypedProperties loadGlobalProps() { | |
| DFSPropertiesConfiguration conf = new DFSPropertiesConfiguration(); | ||
| Option<Path> defaultConfPath = getConfPathFromEnv(); | ||
| if (defaultConfPath.isPresent()) { | ||
| conf.addPropsFromFile(defaultConfPath.get()); | ||
| conf.addPropsFromFile(defaultConfPath.get(), false); | ||
| } else { | ||
| try { | ||
| conf.addPropsFromFile(new Path(DEFAULT_CONF_FILE_DIR)); | ||
| } catch (Exception ignored) { | ||
| LOG.warn("Didn't find config file under default conf file dir: " + DEFAULT_CONF_FILE_DIR); | ||
| } | ||
| conf.addPropsFromFile(new Path(DEFAULT_CONF_FILE_DIR + "/" + DEFAULT_PROPERTIES_FILE), true); | ||
| } | ||
| return conf.getProps(); | ||
| } | ||
|
|
@@ -119,7 +118,7 @@ public static void clearGlobalProps() { | |
| * | ||
| * @param filePath File path for configuration file | ||
| */ | ||
| public void addPropsFromFile(Path filePath) { | ||
| public void addPropsFromFile(Path filePath, boolean isDefaultDirectory) { | ||
nsivabalan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (visitedFilePaths.contains(filePath.toString())) { | ||
| throw new IllegalStateException("Loop detected; file " + filePath + " already referenced"); | ||
| } | ||
|
|
@@ -128,14 +127,19 @@ public void addPropsFromFile(Path filePath) { | |
| filePath.toString(), | ||
| Option.ofNullable(hadoopConfig).orElseGet(Configuration::new) | ||
| ); | ||
| try { | ||
| if (isDefaultDirectory && !fs.exists(filePath)) { | ||
nsivabalan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| LOG.warn("Properties file " + filePath + " not found. Ignoring to load props file"); | ||
| return; | ||
| } | ||
|
|
||
| try (BufferedReader reader = new BufferedReader(new InputStreamReader(fs.open(filePath)))) { | ||
| BufferedReader reader = new BufferedReader(new InputStreamReader(fs.open(filePath))); | ||
|
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. why remove the |
||
| visitedFilePaths.add(filePath.toString()); | ||
| currentFilePath = filePath; | ||
| addPropsFromStream(reader); | ||
| } catch (IOException ioe) { | ||
| LOG.error("Error reading in properties from dfs"); | ||
| throw new IllegalArgumentException("Cannot read properties from dfs", ioe); | ||
| LOG.error("Error reading in properties from dfs from file " + filePath); | ||
| throw new HoodieIOException("Cannot read properties from dfs from file " + filePath, ioe); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -154,7 +158,7 @@ public void addPropsFromStream(BufferedReader reader) throws IOException { | |
| String[] split = splitProperty(line); | ||
| if (line.startsWith("include=") || line.startsWith("include =")) { | ||
| Path includeFilePath = new Path(currentFilePath.getParent(), split[1]); | ||
| addPropsFromFile(includeFilePath); | ||
| addPropsFromFile(includeFilePath, false); | ||
| } else { | ||
| hoodieConfig.setValue(split[0], split[1]); | ||
| } | ||
|
|
@@ -192,7 +196,7 @@ private static Option<Path> getConfPathFromEnv() { | |
| } | ||
|
|
||
| private String[] splitProperty(String line) { | ||
| line = line.replaceAll("\\s+"," "); | ||
| line = line.replaceAll("\\s+", " "); | ||
| String delimiter = line.contains("=") ? "=" : " "; | ||
| int ind = line.indexOf(delimiter); | ||
| String k = line.substring(0, ind).trim(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is actually preferrable to leaking the check for a default path inside
addPropsFromFileThere 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.
Comments addressed in #5311 .