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 cca6e8d..599e90b 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 @@ -233,6 +233,7 @@ protected void serviceStop() { public final boolean shouldCancelAtEnd; public long maxDate; public String user; + protected AtomicBoolean isTokenInProcessOfCancelling = new AtomicBoolean(false); public DelegationTokenToRenew(ApplicationId jId, Token token, Configuration conf, long expirationDate, boolean shouldCancelAtEnd, @@ -255,6 +256,14 @@ public DelegationTokenToRenew(ApplicationId jId, Token token, this.shouldCancelAtEnd = shouldCancelAtEnd; } + public boolean isTokenInProcessOfCancelling() { + return isTokenInProcessOfCancelling.get(); + } + + public void setTokenInProcessOfCancelling() { + this.isTokenInProcessOfCancelling.set(true); + } + public void setTimerTask(TimerTask tTask) { timerTask = tTask; } @@ -445,7 +454,6 @@ private void handleAppSubmitEvent(DelegationTokenRenewerAppSubmitEvent evt) */ private class RenewalTimerTask extends TimerTask { private DelegationTokenToRenew dttr; - private AtomicBoolean cancelled = new AtomicBoolean(false); RenewalTimerTask(DelegationTokenToRenew t) { dttr = t; @@ -453,7 +461,7 @@ private void handleAppSubmitEvent(DelegationTokenRenewerAppSubmitEvent evt) @Override public void run() { - if (cancelled.get()) { + if (dttr.isTokenInProcessOfCancelling()) { return; } @@ -462,7 +470,8 @@ 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 (appTokens.get(dttr.applicationId).contains(dttr) + && !dttr.isTokenInProcessOfCancelling()) { renewToken(dttr); setTimerForTokenRenewal(dttr);// set the next one } else { @@ -473,12 +482,6 @@ public void run() { removeFailedDelegationToken(dttr); } } - - @Override - public boolean cancel() { - cancelled.set(true); - return super.cancel(); - } } /** @@ -531,7 +534,8 @@ private void requestNewHdfsDelegationTokenIfNeeded( if (hasProxyUserPrivileges && dttr.maxDate - dttr.expirationDate < credentialsValidTimeRemaining - && dttr.token.getKind().equals(new Text("HDFS_DELEGATION_TOKEN"))) { + && dttr.token.getKind().equals(new Text("HDFS_DELEGATION_TOKEN")) + && !dttr.isTokenInProcessOfCancelling()) { // remove all old expiring hdfs tokens for this application. Set tokenSet = appTokens.get(dttr.applicationId); @@ -543,6 +547,7 @@ private void requestNewHdfsDelegationTokenIfNeeded( if (t.token.getKind().equals(new Text("HDFS_DELEGATION_TOKEN"))) { iter.remove(); if (t.timerTask != null) { + t.setTokenInProcessOfCancelling(); t.timerTask.cancel(); } LOG.info("Removed expiring token " + t); @@ -621,6 +626,7 @@ private void removeFailedDelegationToken(DelegationTokenToRenew t) { LOG.error("removing failed delegation token for appid=" + applicationId + ";t=" + t.token.getService()); appTokens.get(applicationId).remove(t); + t.setTokenInProcessOfCancelling(); // cancel the timer if (t.timerTask != null) { t.timerTask.cancel(); @@ -676,6 +682,9 @@ private void removeApplicationFromRenewal(ApplicationId applicationId) { LOG.debug("Removing delegation token for appId=" + applicationId + "; token=" + dttr.token.getService()); } + + //set token to be in process of cancellation + dttr.setTokenInProcessOfCancelling(); // cancel the timer if (dttr.timerTask != null)