HDFS-2589. Remove unnecessary hftp token fetch and renewal thread. Contributed by Daryn Sharp.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.0@1214661 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 9cb0329..7bab118 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -61,6 +61,9 @@
BUG FIXES
+ HDFS-2589. Remove unnecessary hftp token fetch and renewal thread.
+ (Daryn Sharp via mattf)
+
MAPREDUCE-3475. JT can't renew its own tokens. (Daryn Sharp via mattf)
HADOOP-7869. HADOOP_HOME warning happens all of the time (Owen O'Malley
diff --git a/src/hdfs/org/apache/hadoop/hdfs/HftpFileSystem.java b/src/hdfs/org/apache/hadoop/hdfs/HftpFileSystem.java
index 3bbe860..b5539f1 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/HftpFileSystem.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/HftpFileSystem.java
@@ -81,12 +81,12 @@
static {
HttpURLConnection.setFollowRedirects(true);
- dtRenewer.start();
}
public static final Text TOKEN_KIND = new Text("HFTP delegation");
protected UserGroupInformation ugi;
+ private boolean remoteIsInsecure = false;
private URI hftpURI;
protected InetSocketAddress nnAddr;
@@ -150,10 +150,6 @@
this.nnAddr = getNamenodeAddr(name);
this.nnSecureAddr = getNamenodeSecureAddr(name);
this.hftpURI = DFSUtil.createUri(name.getScheme(), nnAddr);
-
- if (UserGroupInformation.isSecurityEnabled()) {
- initDelegationToken();
- }
}
protected void initDelegationToken() throws IOException {
@@ -229,6 +225,7 @@
" using https.");
LOG.debug("error was ", e);
//Maybe the server is in unsecure mode (that's bad but okay)
+ remoteIsInsecure = true;
return null;
}
for (Token<? extends TokenIdentifier> t : c.getAllTokens()) {
@@ -296,6 +293,9 @@
String tokenString = null;
if (UserGroupInformation.isSecurityEnabled()) {
synchronized (this) {
+ if (delegationToken == null && !remoteIsInsecure) {
+ initDelegationToken();
+ }
if (delegationToken != null) {
tokenString = delegationToken.encodeToUrlString();
return (query + JspHelper.getDelegationTokenUrlParam(tokenString));
diff --git a/src/hdfs/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenRenewer.java b/src/hdfs/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenRenewer.java
index 28db767..5e043f2 100644
--- a/src/hdfs/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenRenewer.java
+++ b/src/hdfs/org/apache/hadoop/hdfs/security/token/delegation/DelegationTokenRenewer.java
@@ -139,9 +139,15 @@
setDaemon(true);
}
+ @Override
+ public void start() {
+ return; // lazy start when addRenewAction is actually called
+ }
+
/** Add a renew action to the queue. */
public void addRenewAction(final T fs) {
queue.add(new RenewAction<T>(fs));
+ if (!isAlive()) super.start();
}
@Override
diff --git a/src/test/org/apache/hadoop/hdfs/security/token/TestDelegationTokenRenewer.java b/src/test/org/apache/hadoop/hdfs/security/token/TestDelegationTokenRenewer.java
new file mode 100644
index 0000000..2877337
--- /dev/null
+++ b/src/test/org/apache/hadoop/hdfs/security/token/TestDelegationTokenRenewer.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdfs.security.token;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.hadoop.hdfs.HftpFileSystem;
+import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenRenewer;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class TestDelegationTokenRenewer {
+
+ @Test
+ public void testLazyRenewerStartup() {
+ DelegationTokenRenewer<HftpFileSystem> dtr =
+ new DelegationTokenRenewer<HftpFileSystem>(HftpFileSystem.class);
+ assertFalse(dtr.isAlive());
+ dtr.start();
+ assertFalse(dtr.isAlive());
+ dtr.addRenewAction(null);
+ assertTrue(dtr.isAlive());
+ }
+}
\ No newline at end of file