瀏覽代碼

HDFS-7266. HDFS Peercache enabled check should not lock on object (awang via cmccabe)

Colin Patrick Mccabe 10 年之前
父節點
當前提交
4799570dfd

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -381,6 +381,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

+ 9 - 3
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<Value> 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()) {