From 66f322ba99847f8abbf8f3068a1450b06cf5c04e Mon Sep 17 00:00:00 2001 From: Alejandro Abdelnur Date: Tue, 27 Nov 2012 19:26:09 +0000 Subject: [PATCH] HADOOP-9084. Augment DelegationTokenRenewer API to cancel the tokens on calls to removeRenewAction. (kkambatl via tucu) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1414331 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../dev-support/findbugsExcludeFile.xml | 10 +++++- .../hadoop/fs/DelegationTokenRenewer.java | 22 +++++++++++-- .../hadoop/fs/TestDelegationTokenRenewer.java | 33 +++++++------------ 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 710127cf6d7..afd6e0c0cb3 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -158,6 +158,9 @@ Release 2.0.3-alpha - Unreleased HADOOP-9049. DelegationTokenRenewer needs to be Singleton and FileSystems should register/deregister to/from. (Karthik Kambatla via tomwhite) + HADOOP-9084. Augment DelegationTokenRenewer API to cancel the tokens on + calls to removeRenewAction. (kkambatl via tucu) + Release 2.0.2-alpha - 2012-09-07 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml b/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml index 0244955865a..5ca05fd6615 100644 --- a/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml +++ b/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml @@ -303,5 +303,13 @@ - + + + + + + diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java index 1224600c9b0..b60507afa34 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DelegationTokenRenewer.java @@ -24,6 +24,8 @@ import java.util.concurrent.DelayQueue; import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.TokenIdentifier; @@ -35,6 +37,9 @@ import org.apache.hadoop.util.Time; @InterfaceAudience.Private public class DelegationTokenRenewer extends Thread { + private static final Log LOG = LogFactory + .getLog(DelegationTokenRenewer.class); + /** The renewable interface used by the renewer. */ public interface Renewable { /** @return the renew token. */ @@ -168,11 +173,24 @@ public class DelegationTokenRenewer } } - /** Remove the associated renew action from the queue */ + /** + * Remove the associated renew action from the queue + * + * @throws IOException + */ public synchronized void removeRenewAction( - final T fs) { + final T fs) throws IOException { for (RenewAction action : queue) { if (action.weakFs.get() == fs) { + try { + fs.getRenewToken().cancel(fs.getConf()); + } catch (InterruptedException ie) { + LOG.error("Interrupted while canceling token for " + fs.getUri() + + "filesystem"); + if (LOG.isDebugEnabled()) { + LOG.debug(ie.getStackTrace()); + } + } queue.remove(action); return; } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java index 789641dc328..86a580c5258 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestDelegationTokenRenewer.java @@ -23,6 +23,7 @@ public class TestDelegationTokenRenewer { @SuppressWarnings("rawtypes") static class TestToken extends Token { public volatile int renewCount = 0; + public volatile boolean cancelled = false; @Override public long renew(Configuration conf) { @@ -33,6 +34,11 @@ public class TestDelegationTokenRenewer { } return renewCount; } + + @Override + public void cancel(Configuration conf) { + cancelled = true; + } } static class TestFileSystem extends FileSystem implements @@ -123,27 +129,12 @@ public class TestDelegationTokenRenewer { } @Test - public void testAddRenewAction() throws IOException, InterruptedException { + public void testAddRemoveRenewAction() throws IOException, + InterruptedException { TestFileSystem tfs = new TestFileSystem(); renewer.addRenewAction(tfs); - for (int i = 0; i < 10; i++) { - Thread.sleep(RENEW_CYCLE); - if (tfs.testToken.renewCount > 0) { - return; - } - } - - assertTrue("Token not renewed even after 10 seconds", - (tfs.testToken.renewCount > 0)); - } - - @Test - public void testRemoveRenewAction() throws IOException, InterruptedException { - TestFileSystem tfs = new TestFileSystem(); - renewer.addRenewAction(tfs); - - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 60; i++) { Thread.sleep(RENEW_CYCLE); if (tfs.testToken.renewCount > 0) { renewer.removeRenewAction(tfs); @@ -151,9 +142,9 @@ public class TestDelegationTokenRenewer { } } - assertTrue("Token not renewed even once", + assertTrue("Token not renewed even after 1 minute", (tfs.testToken.renewCount > 0)); - assertTrue("Token not removed", - (tfs.testToken.renewCount < MAX_RENEWALS)); + assertTrue("Token not removed", (tfs.testToken.renewCount < MAX_RENEWALS)); + assertTrue("Token not cancelled", tfs.testToken.cancelled); } }