Skip to content

Commit 342c525

Browse files
committed
YARN-3336. FileSystem memory leak in DelegationTokenRenewer.
(cherry picked from commit 6ca1f12)
1 parent 943d9ee commit 342c525

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ Release 2.7.0 - UNRELEASED
774774
YARN-3384. TestLogAggregationService.verifyContainerLogs fails after
775775
YARN-2777. (Naganarasimha G R via ozawa)
776776

777+
YARN-3336. FileSystem memory leak in DelegationTokenRenewer.
778+
(Zhihai Xu via cnauroth)
779+
777780
Release 2.6.0 - 2014-11-18
778781

779782
INCOMPATIBLE CHANGES

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/security/DelegationTokenRenewer.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ private void requestNewHdfsDelegationToken(ApplicationId applicationId,
605605
rmContext.getSystemCredentialsForApps().put(applicationId, byteBuffer);
606606
}
607607

608+
@VisibleForTesting
608609
protected Token<?>[] obtainSystemTokensForUser(String user,
609610
final Credentials credentials) throws IOException, InterruptedException {
610611
// Get new hdfs tokens on behalf of this user
@@ -615,8 +616,16 @@ protected Token<?>[] obtainSystemTokensForUser(String user,
615616
proxyUser.doAs(new PrivilegedExceptionAction<Token<?>[]>() {
616617
@Override
617618
public Token<?>[] run() throws Exception {
618-
return FileSystem.get(getConfig()).addDelegationTokens(
619-
UserGroupInformation.getLoginUser().getUserName(), credentials);
619+
FileSystem fs = FileSystem.get(getConfig());
620+
try {
621+
return fs.addDelegationTokens(
622+
UserGroupInformation.getLoginUser().getUserName(),
623+
credentials);
624+
} finally {
625+
// Close the FileSystem created by the new proxy user,
626+
// So that we don't leave an entry in the FileSystem cache
627+
fs.close();
628+
}
620629
}
621630
});
622631
return newTokens;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/security/TestDelegationTokenRenewer.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,16 @@ public String toString() {
287287
* exception
288288
*/
289289
static class MyFS extends DistributedFileSystem {
290-
291-
public MyFS() {}
292-
public void close() {}
290+
private static AtomicInteger instanceCounter = new AtomicInteger();
291+
public MyFS() {
292+
instanceCounter.incrementAndGet();
293+
}
294+
public void close() {
295+
instanceCounter.decrementAndGet();
296+
}
297+
public static int getInstanceCounter() {
298+
return instanceCounter.get();
299+
}
293300
@Override
294301
public void initialize(URI uri, Configuration conf) throws IOException {}
295302

@@ -299,6 +306,11 @@ public MyToken getDelegationToken(String renewer) throws IOException {
299306
LOG.info("Called MYDFS.getdelegationtoken " + result);
300307
return result;
301308
}
309+
310+
public Token<?>[] addDelegationTokens(
311+
final String renewer, Credentials credentials) throws IOException {
312+
return new Token<?>[0];
313+
}
302314
}
303315

304316
/**
@@ -1022,4 +1034,16 @@ public void testAppSubmissionWithPreviousToken() throws Exception{
10221034
// app2 completes, app1 is still running, check the token is not cancelled
10231035
Assert.assertFalse(Renewer.cancelled);
10241036
}
1037+
1038+
// Test FileSystem memory leak in obtainSystemTokensForUser.
1039+
@Test
1040+
public void testFSLeakInObtainSystemTokensForUser() throws Exception{
1041+
Credentials credentials = new Credentials();
1042+
String user = "test";
1043+
int oldCounter = MyFS.getInstanceCounter();
1044+
delegationTokenRenewer.obtainSystemTokensForUser(user, credentials);
1045+
delegationTokenRenewer.obtainSystemTokensForUser(user, credentials);
1046+
delegationTokenRenewer.obtainSystemTokensForUser(user, credentials);
1047+
Assert.assertEquals(oldCounter, MyFS.getInstanceCounter());
1048+
}
10251049
}

0 commit comments

Comments
 (0)