diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index f090442df9..0971fcc482 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -450,6 +450,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 19c6e5b53d..0fd183d763 100644
--- a/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
+++ b/hadoop-common-project/hadoop-common/dev-support/findbugsExcludeFile.xml
@@ -291,5 +291,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 1224600c9b..b60507afa3 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.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 @@
@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 synchronized void addRenewAction(final
}
}
- /** 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 789641dc32..86a580c525 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 long renew(Configuration conf) {
}
return renewCount;
}
+
+ @Override
+ public void cancel(Configuration conf) {
+ cancelled = true;
+ }
}
static class TestFileSystem extends FileSystem implements
@@ -123,27 +129,12 @@ public void setup() {
}
@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 void testRemoveRenewAction() throws IOException, InterruptedException {
}
}
- 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);
}
}