hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1374417 - in /hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs: CHANGES.txt src/main/java/org/apache/hadoop/hdfs/server/namenode/SerialNumberManager.java
Date Fri, 17 Aug 2012 19:55:16 GMT
Author: daryn
Date: Fri Aug 17 19:55:16 2012
New Revision: 1374417

URL: http://svn.apache.org/viewvc?rev=1374417&view=rev
Log:
svn merge -c 1374127. FIXES: HDFS-2421. Improve the concurrency of SerialNumberMap in NameNode.
 Contributed by Jing Zhao and Weiyan Wang

Modified:
    hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
    hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SerialNumberManager.java

Modified: hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1374417&r1=1374416&r2=1374417&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Fri Aug
17 19:55:16 2012
@@ -21,6 +21,9 @@ Release 0.23.3 - UNRELEASED
 
   OPTIMIZATIONS
 
+    HDFS-2421. Improve the concurrency of SerialNumberMap in NameNode.
+    (Jing Zhao and Weiyan Wang via szetszwo)
+
   BUG FIXES
 
     HDFS-3166. Add timeout to Hftp connections.  (Daryn Sharp via szetszwo)

Modified: hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SerialNumberManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SerialNumberManager.java?rev=1374417&r1=1374416&r2=1374417&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SerialNumberManager.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/SerialNumberManager.java
Fri Aug 17 19:55:16 2012
@@ -17,7 +17,10 @@
  */
 package org.apache.hadoop.hdfs.server.namenode;
 
-import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
 
 /** Manage name-to-serial-number maps for users and groups. */
 class SerialNumberManager {
@@ -40,28 +43,36 @@ class SerialNumberManager {
   }
 
   private static class SerialNumberMap<T> {
-    private int max = 0;
-    private int nextSerialNumber() {return max++;}
-
-    private Map<T, Integer> t2i = new HashMap<T, Integer>();
-    private Map<Integer, T> i2t = new HashMap<Integer, T>();
-
-    synchronized int get(T t) {
+    private AtomicInteger max = new AtomicInteger(1);
+    private ConcurrentMap<T, Integer> t2i = new ConcurrentHashMap<T, Integer>();
+    private ConcurrentMap<Integer, T> i2t = new ConcurrentHashMap<Integer, T>();
+
+    int get(T t) {
+      if (t == null) {
+        return 0;
+      }
       Integer sn = t2i.get(t);
       if (sn == null) {
-        sn = nextSerialNumber();
-        t2i.put(t, sn);
+        sn = max.getAndIncrement();
+        Integer old = t2i.putIfAbsent(t, sn);
+        if (old != null) {
+          return old;
+        }
         i2t.put(sn, t);
       }
       return sn;
     }
 
-    synchronized T get(int i) {
-      if (!i2t.containsKey(i)) {
+    T get(int i) {
+      if (i == 0) {
+        return null;
+      }
+      T t = i2t.get(i);
+      if (t == null) {
         throw new IllegalStateException("!i2t.containsKey(" + i
             + "), this=" + this);
       }
-      return i2t.get(i);
+      return t;
     }
 
     /** {@inheritDoc} */
@@ -69,4 +80,4 @@ class SerialNumberManager {
       return "max=" + max + ",\n  t2i=" + t2i + ",\n  i2t=" + i2t;
     }
   }
-}
+}
\ No newline at end of file



Mime
View raw message