Skip to content

Commit 729cb3a

Browse files
committed
HDFS-12748. NameNode memory leak when accessing webhdfs GETHOMEDIRECTORY. Contributed by Weiwei Yang.
1 parent acd2d52 commit 729cb3a

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSUtilClient.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,4 +994,24 @@ public static Path makePathFromFileId(long fileId) {
994994
return new Path(sb.toString());
995995
}
996996

997+
/**
998+
* Returns current user home directory under a home directory prefix.
999+
* The home directory prefix can be defined by
1000+
* {@link HdfsClientConfigKeys#DFS_USER_HOME_DIR_PREFIX_KEY}.
1001+
* User info is obtained from given {@link UserGroupInformation}.
1002+
* @param conf configuration
1003+
* @param ugi {@link UserGroupInformation} of current user.
1004+
* @return the home directory of current user.
1005+
*/
1006+
public static Path getHomeDirectory(Configuration conf,
1007+
UserGroupInformation ugi) {
1008+
String userHomePrefix = HdfsClientConfigKeys
1009+
.DFS_USER_HOME_DIR_PREFIX_DEFAULT;
1010+
if (conf != null) {
1011+
userHomePrefix = conf.get(
1012+
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY,
1013+
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT);
1014+
}
1015+
return new Path(userHomePrefix + "/" + ugi.getShortUserName());
1016+
}
9971017
}

hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ public class DistributedFileSystem extends FileSystem
132132
implements KeyProviderTokenIssuer {
133133
private Path workingDir;
134134
private URI uri;
135-
private String homeDirPrefix =
136-
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT;
137135

138136
DFSClient dfs;
139137
private boolean verifyChecksum = true;
@@ -169,9 +167,6 @@ public void initialize(URI uri, Configuration conf) throws IOException {
169167
if (host == null) {
170168
throw new IOException("Incomplete HDFS URI, no host: "+ uri);
171169
}
172-
homeDirPrefix = conf.get(
173-
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY,
174-
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT);
175170

176171
this.dfs = new DFSClient(uri, conf, statistics);
177172
this.uri = URI.create(uri.getScheme()+"://"+uri.getAuthority());
@@ -214,8 +209,7 @@ public void setWorkingDirectory(Path dir) {
214209

215210
@Override
216211
public Path getHomeDirectory() {
217-
return makeQualified(new Path(homeDirPrefix + "/"
218-
+ dfs.ugi.getShortUserName()));
212+
return makeQualified(DFSUtilClient.getHomeDirectory(getConf(), dfs.ugi));
219213
}
220214

221215
/**

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,9 +1205,8 @@ protected Response get(
12051205
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
12061206
}
12071207
case GETHOMEDIRECTORY: {
1208-
final String js = JsonUtil.toJsonString("Path",
1209-
FileSystem.get(conf != null ? conf : new Configuration())
1210-
.getHomeDirectory().toUri().getPath());
1208+
String userHome = DFSUtilClient.getHomeDirectory(conf, ugi).toString();
1209+
final String js = JsonUtil.toJsonString("Path", userHome);
12111210
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
12121211
}
12131212
case GETACLSTATUS: {

0 commit comments

Comments
 (0)