From 4eef6dcb58318359777858cac89cbaaa1764f30c Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Mon, 20 Oct 2014 18:24:53 -0700 Subject: [PATCH] HDFS-7266. HDFS Peercache enabled check should not lock on object (awang via cmccabe) (cherry picked from commit 4799570dfdb7987c2ac39716143341e9a3d9b7d2) --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../main/java/org/apache/hadoop/hdfs/PeerCache.java | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 4b7358b4850..d43c108e742 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -23,6 +23,9 @@ Release 2.7.0 - UNRELEASED HDFS-6252. Phase out the old web UI in HDFS. (wheat9) + HDFS-7266. HDFS Peercache enabled check should not lock on object (awang + via cmccabe) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/PeerCache.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/PeerCache.java index fbe4e15581a..07c562e1df1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/PeerCache.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/PeerCache.java @@ -140,12 +140,15 @@ class PeerCache { * @return An open Peer connected to the DN, or null if none * was found. */ - public synchronized Peer get(DatanodeID dnId, boolean isDomain) { + public Peer get(DatanodeID dnId, boolean isDomain) { if (capacity <= 0) { // disabled return null; } + return getInternal(dnId, isDomain); + } + private synchronized Peer getInternal(DatanodeID dnId, boolean isDomain) { List sockStreamList = multimap.get(new Key(dnId, isDomain)); if (sockStreamList == null) { return null; @@ -174,7 +177,7 @@ class PeerCache { /** * Give an unused socket to the cache. */ - public synchronized void put(DatanodeID dnId, Peer peer) { + public void put(DatanodeID dnId, Peer peer) { Preconditions.checkNotNull(dnId); Preconditions.checkNotNull(peer); if (peer.isClosed()) return; @@ -183,7 +186,10 @@ class PeerCache { IOUtils.cleanup(LOG, peer); return; } - + putInternal(dnId, peer); + } + + private synchronized void putInternal(DatanodeID dnId, Peer peer) { startExpiryDaemon(); if (capacity == multimap.size()) {