|
@@ -591,21 +591,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead,
|
|
|
// The encryption key used is invalid.
|
|
|
refetchEncryptionKey--;
|
|
|
dfsClient.clearDataEncryptionKey();
|
|
|
- } else if ((ex instanceof InvalidBlockTokenException || ex instanceof InvalidToken)
|
|
|
- && refetchToken > 0) {
|
|
|
- DFSClient.LOG.info("Will fetch a new access token and retry, "
|
|
|
- + "access token was invalid when connecting to " + targetAddr
|
|
|
- + " : " + ex);
|
|
|
- /*
|
|
|
- * 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.
|
|
|
- */
|
|
|
+ } else if (refetchToken > 0 && tokenRefetchNeeded(ex, targetAddr)) {
|
|
|
refetchToken--;
|
|
|
fetchBlockAt(target);
|
|
|
} else {
|
|
@@ -978,11 +964,7 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead,
|
|
|
// The encryption key used is invalid.
|
|
|
refetchEncryptionKey--;
|
|
|
dfsClient.clearDataEncryptionKey();
|
|
|
- } else if ((e instanceof InvalidBlockTokenException || e instanceof InvalidToken)
|
|
|
- && refetchToken > 0) {
|
|
|
- DFSClient.LOG.info("Will get a new access token and retry, "
|
|
|
- + "access token was invalid when connecting to " + targetAddr
|
|
|
- + " : " + e);
|
|
|
+ } else if (refetchToken > 0 && tokenRefetchNeeded(e, targetAddr)) {
|
|
|
refetchToken--;
|
|
|
fetchBlockAt(block.getStartOffset());
|
|
|
continue;
|
|
@@ -1003,6 +985,34 @@ implements ByteBufferReadable, CanSetDropBehind, CanSetReadahead,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 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) {
|
|
|
+ DFSClient.LOG.info("Access token was invalid when connecting to "
|
|
|
+ + targetAddr + " : " + ex);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
private Peer newTcpPeer(InetSocketAddress addr) throws IOException {
|
|
|
Peer peer = null;
|
|
|
boolean success = false;
|