HDFS-7122. Use of ThreadLocal<Random> results in poor block placement. (wang)
This commit is contained in:
parent
e10eeaabce
commit
c6c3247dc0
@ -673,27 +673,11 @@ protected boolean isSameParents(Node node1, Node node2) {
|
||||
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 @@ private Node chooseRandom(String scope, String excludedScope){
|
||||
"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 void sortByDistance(Node reader, Node[] nodes, int activeLen) {
|
||||
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++;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user