Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,10 +56,9 @@ public class DFSPropertiesConfiguration {
private static final Logger LOG = LogManager.getLogger(DFSPropertiesConfiguration.class);

public static final String DEFAULT_PROPERTIES_FILE = "hudi-defaults.conf";

public static final String CONF_FILE_DIR_ENV_NAME = "HUDI_CONF_DIR";

public static final String DEFAULT_CONF_FILE_DIR = "file:/etc/hudi/conf";
public static final Path DEFAULT_PATH = new Path(DEFAULT_CONF_FILE_DIR + "/" + DEFAULT_PROPERTIES_FILE);

// props read from hudi-defaults.conf
private static TypedProperties GLOBAL_PROPS = loadGlobalProps();
Expand Down Expand Up @@ -97,11 +99,7 @@ public static TypedProperties loadGlobalProps() {
if (defaultConfPath.isPresent()) {
conf.addPropsFromFile(defaultConfPath.get());
} else {
try {
conf.addPropsFromFile(new Path(DEFAULT_CONF_FILE_DIR));
} catch (Exception ignored) {
Copy link
Member

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 addPropsFromFile

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments addressed in #5311 .

LOG.warn("Didn't find config file under default conf file dir: " + DEFAULT_CONF_FILE_DIR);
}
conf.addPropsFromFile(DEFAULT_PATH);
}
return conf.getProps();
}
Expand All @@ -128,14 +126,19 @@ public void addPropsFromFile(Path filePath) {
filePath.toString(),
Option.ofNullable(hadoopConfig).orElseGet(Configuration::new)
);
try {
if (filePath.equals(DEFAULT_PATH) && !fs.exists(filePath)) {
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)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the try here? it closes the reader correctly right ?

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);
}
}

Expand Down Expand Up @@ -192,7 +195,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void testIncludes() {
}

@Test
public void testLocalFileSystemLoading() {
public void testLocalFileSystemLoading() throws IOException {
DFSPropertiesConfiguration cfg = new DFSPropertiesConfiguration(dfs.getConf(), new Path(dfsBasePath + "/t1.props"));

cfg.addPropsFromFile(
Expand All @@ -156,8 +156,7 @@ public void testLocalFileSystemLoading() {
.getResource("props/test.properties")
.getPath()
)
)
);
));

TypedProperties props = cfg.getProps();

Expand Down