From b19d1186ab6d42d6f91360e73638b80eb6346a4c Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Thu, 8 Mar 2012 18:31:33 +0000 Subject: [PATCH] HDFS-2976. Remove unnecessary method (tokenRefetchNeeded) in DFSClient. (Contributed by Uma Maheswara Rao G) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1298495 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ .../org/apache/hadoop/hdfs/DFSClient.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 6cb5290c81a..4e25789ed24 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -53,6 +53,8 @@ Trunk (unreleased changes) HDFS-3030. Remove getProtocolVersion and getProtocolSignature from translators. (jitendra) + HDFS-2976. Remove unnecessary method (tokenRefetchNeeded) in DFSClient. + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java index 110a50b2691..074be7eaedf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSClient.java @@ -132,6 +132,7 @@ import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.TokenRenewer; import org.apache.hadoop.util.DataChecksum; import org.apache.hadoop.util.Progressable; +import org.apache.hadoop.hdfs.security.token.block.InvalidBlockTokenException; import com.google.common.base.Preconditions; @@ -670,6 +671,33 @@ public class DFSClient implements java.io.Closeable { return false; } + /** + * Should the block access token be refetched on an exception + * + * @param ex Exception received + * @param targetAddr Target datanode address from where exception was received + * @return true if block access token has expired or invalid and it should be + * refetched + */ + private static boolean tokenRefetchNeeded(IOException ex, + InetSocketAddress targetAddr) { + /* + * Get a new access token and retry. Retry is needed in 2 cases. 1) When + * both NN and DN re-started while DFSClient holding a cached access token. + * 2) In the case that NN fails to update its access key at pre-set interval + * (by a wide margin) and subsequently restarts. In this case, DN + * re-registers itself with NN and receives a new access key, but DN will + * delete the old access key from its memory since it's considered expired + * based on the estimated expiration date. + */ + if (ex instanceof InvalidBlockTokenException || ex instanceof InvalidToken) { + LOG.info("Access token was invalid when connecting to " + targetAddr + + " : " + ex); + return true; + } + return false; + } + /** * Cancel a delegation token * @param token the token to cancel