diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/security/DelegationTokenRenewer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/security/DelegationTokenRenewer.java index dfcceb8..e4f837f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/security/DelegationTokenRenewer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/security/DelegationTokenRenewer.java @@ -234,6 +234,7 @@ protected void serviceStop() { public long expirationDate; public TimerTask timerTask; public volatile boolean shouldCancelAtEnd; + public volatile boolean cancelled = false; public long maxDate; public String user; @@ -478,12 +479,12 @@ public void run() { try { requestNewHdfsDelegationTokenIfNeeded(dttr); - // if the token is not replaced by a new token, renew the token - if (appTokens.get(dttr.applicationId).contains(dttr)) { + // if the token is not cancelled, renew the token + if (!dttr.cancelled) { renewToken(dttr); setTimerForTokenRenewal(dttr);// set the next one } else { - LOG.info("The token was removed already. Token = [" +dttr +"]"); + LOG.info("The token was cancelled already. Token = [" +dttr +"]"); } } catch (Exception e) { LOG.error("Exception renewing token" + token + ". Not rescheduled", e); @@ -502,8 +503,7 @@ public boolean cancel() { * set task to renew the token */ @VisibleForTesting - protected void setTimerForTokenRenewal(DelegationTokenToRenew token) - throws IOException { + protected void setTimerForTokenRenewal(DelegationTokenToRenew token) { // calculate timer time long expiresIn = token.expirationDate - System.currentTimeMillis(); @@ -626,7 +626,14 @@ private void requestNewHdfsDelegationToken(ApplicationId applicationId, // cancel a token private void cancelToken(DelegationTokenToRenew t) { if(t.shouldCancelAtEnd) { + // cancel the timer + if (t.timerTask != null) { + t.timerTask.cancel(); + } + dtCancelThread.cancelToken(t.token, t.conf); + allTokens.remove(t.token); + t.cancelled = true; } else { LOG.info("Did not cancel "+t); } @@ -699,15 +706,9 @@ private void removeApplicationFromRenewal(ApplicationId applicationId) { + "; token=" + dttr.token.getService()); } - // cancel the timer - if (dttr.timerTask != null) - dttr.timerTask.cancel(); - // cancel the token cancelToken(dttr); - it.remove(); - allTokens.remove(dttr.token); } } }