Skip to content
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

[fix](multi-catalog)fix create extra hdfs client during multithreaded access #38453

Closed
wants to merge 7 commits into from
Closed
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
51 changes: 28 additions & 23 deletions fe/fe-core/src/main/java/org/apache/doris/backup/HdfsStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class HdfsStorage extends BlobStorage {
private final int readBufferSize = 128 << 10; // 128k
private final int writeBufferSize = 128 << 10; // 128k

private FileSystem dfsFileSystem = null;
private volatile FileSystem dfsFileSystem = null;

/**
* init HdfsStorage with properties.
Expand All @@ -86,33 +86,38 @@ public static String getFsName(String path) {

@Override
public FileSystem getFileSystem(String remotePath) throws UserException {
if (dfsFileSystem == null) {
String username = hdfsProperties.get(HdfsResource.HADOOP_USER_NAME);
Configuration conf = new HdfsConfiguration();
boolean isSecurityEnabled = false;
for (Map.Entry<String, String> propEntry : hdfsProperties.entrySet()) {
conf.set(propEntry.getKey(), propEntry.getValue());
if (propEntry.getKey().equals(HdfsResource.HADOOP_SECURITY_AUTHENTICATION)
if (dfsFileSystem != null) {
return dfsFileSystem;
}
synchronized (this) {
if (dfsFileSystem == null) {
String username = hdfsProperties.get(HdfsResource.HADOOP_USER_NAME);
Configuration conf = new HdfsConfiguration();
boolean isSecurityEnabled = false;
for (Map.Entry<String, String> propEntry : hdfsProperties.entrySet()) {
conf.set(propEntry.getKey(), propEntry.getValue());
if (propEntry.getKey().equals(HdfsResource.HADOOP_SECURITY_AUTHENTICATION)
&& propEntry.getValue().equals(AuthType.KERBEROS.getDesc())) {
isSecurityEnabled = true;
isSecurityEnabled = true;
}
}
}

try {
if (isSecurityEnabled) {
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab(
conf.set("fs.hdfs.impl.disable.cache", "true");
try {
if (isSecurityEnabled) {
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab(
hdfsProperties.get(HdfsResource.HADOOP_KERBEROS_PRINCIPAL),
hdfsProperties.get(HdfsResource.HADOOP_KERBEROS_KEYTAB));
}
if (username == null) {
dfsFileSystem = FileSystem.get(new Path(remotePath).toUri(), conf);
} else {
dfsFileSystem = FileSystem.get(new Path(remotePath).toUri(), conf, username);
}
} catch (Exception e) {
LOG.error("errors while connect to " + remotePath, e);
throw new UserException("errors while connect to " + remotePath, e);
}
if (username == null) {
dfsFileSystem = FileSystem.get(new Path(remotePath).toUri(), conf);
} else {
dfsFileSystem = FileSystem.get(new Path(remotePath).toUri(), conf, username);
}
} catch (Exception e) {
LOG.error("errors while connect to " + remotePath, e);
throw new UserException("errors while connect to " + remotePath, e);
}
}
return dfsFileSystem;
Expand Down
Loading