hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject git commit: HDFS-7122. Use of ThreadLocal<Random> results in poor block placement. (wang)
Date Mon, 29 Sep 2014 22:00:32 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk e10eeaabc -> c6c3247dc


HDFS-7122. Use of ThreadLocal<Random> results in poor block placement. (wang)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c6c3247d
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c6c3247d
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c6c3247d

Branch: refs/heads/trunk
Commit: c6c3247dc0dcb8c72ea00f3fb14a0879fcf49c56
Parents: e10eeaa
Author: Andrew Wang <wang@apache.org>
Authored: Mon Sep 29 14:50:28 2014 -0700
Committer: Andrew Wang <wang@apache.org>
Committed: Mon Sep 29 15:00:26 2014 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/net/NetworkTopology.java  | 25 ++++----------------
 hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt     |  3 +++
 2 files changed, 7 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/c6c3247d/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java
index 5f11367..aaa5ae3 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java
@@ -673,27 +673,11 @@ public class NetworkTopology {
     return node1.getParent()==node2.getParent();
   }
 
-  private static final ThreadLocal<Random> r = new ThreadLocal<Random>();
-
-  /**
-   * Getter for thread-local Random, which provides better performance than
-   * a shared Random (even though Random is thread-safe).
-   *
-   * @return Thread-local Random.
-   */
-  protected Random getRandom() {
-    Random rand = r.get();
-    if (rand == null) {
-      rand = new Random();
-      r.set(rand);
-    }
-    return rand;
-  }
+  private static final Random r = new Random();
 
   @VisibleForTesting
   void setRandomSeed(long seed) {
-    Random rand = getRandom();
-    rand.setSeed(seed);
+    r.setSeed(seed);
   }
 
   /** randomly choose one node from <i>scope</i>
@@ -745,7 +729,7 @@ public class NetworkTopology {
           "Failed to find datanode (scope=\"" + String.valueOf(scope) +
           "\" excludedScope=\"" + String.valueOf(excludedScope) + "\").");
     }
-    int leaveIndex = getRandom().nextInt(numOfDatanodes);
+    int leaveIndex = r.nextInt(numOfDatanodes);
     return innerNode.getLeaf(leaveIndex, node);
   }
 
@@ -918,11 +902,10 @@ public class NetworkTopology {
       list.add(node);
     }
 
-    Random rand = getRandom();
     int idx = 0;
     for (List<Node> list: tree.values()) {
       if (list != null) {
-        Collections.shuffle(list, rand);
+        Collections.shuffle(list, r);
         for (Node n: list) {
           nodes[idx] = n;
           idx++;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c6c3247d/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
index 41d8066..1b3053c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
@@ -532,6 +532,9 @@ Release 2.6.0 - UNRELEASED
     HDFS-6865. Byte array native checksumming on client side
     (James Thomas via todd)
 
+    HDFS-7122. Use of ThreadLocal<Random> results in poor block placement.
+    (wang)
+
   BUG FIXES
 
     HDFS-6823. dfs.web.authentication.kerberos.principal shows up in logs for 


Mime
View raw message