HDFS-7122. Use of ThreadLocal<Random> results in poor block placement. (wang)
(cherry picked from commit d7086c563ff2847c415913ac625b2a557eeccbdd)
This commit is contained in:
parent
9bc676aa6e
commit
47ddaee1db
|
@ -674,27 +674,11 @@ public class NetworkTopology {
|
||||||
return node1.getParent()==node2.getParent();
|
return node1.getParent()==node2.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ThreadLocal<Random> r = new ThreadLocal<Random>();
|
private static final Random r = new 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setRandomSeed(long seed) {
|
void setRandomSeed(long seed) {
|
||||||
Random rand = getRandom();
|
r.setSeed(seed);
|
||||||
rand.setSeed(seed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** randomly choose one node from <i>scope</i>
|
/** randomly choose one node from <i>scope</i>
|
||||||
|
@ -746,7 +730,7 @@ public class NetworkTopology {
|
||||||
"Failed to find datanode (scope=\"" + String.valueOf(scope) +
|
"Failed to find datanode (scope=\"" + String.valueOf(scope) +
|
||||||
"\" excludedScope=\"" + String.valueOf(excludedScope) + "\").");
|
"\" excludedScope=\"" + String.valueOf(excludedScope) + "\").");
|
||||||
}
|
}
|
||||||
int leaveIndex = getRandom().nextInt(numOfDatanodes);
|
int leaveIndex = r.nextInt(numOfDatanodes);
|
||||||
return innerNode.getLeaf(leaveIndex, node);
|
return innerNode.getLeaf(leaveIndex, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,11 +903,10 @@ public class NetworkTopology {
|
||||||
list.add(node);
|
list.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
Random rand = getRandom();
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (List<Node> list: tree.values()) {
|
for (List<Node> list: tree.values()) {
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
Collections.shuffle(list, rand);
|
Collections.shuffle(list, r);
|
||||||
for (Node n: list) {
|
for (Node n: list) {
|
||||||
nodes[idx] = n;
|
nodes[idx] = n;
|
||||||
idx++;
|
idx++;
|
||||||
|
|
|
@ -277,6 +277,9 @@ Release 2.6.0 - UNRELEASED
|
||||||
HDFS-6865. Byte array native checksumming on client side
|
HDFS-6865. Byte array native checksumming on client side
|
||||||
(James Thomas via todd)
|
(James Thomas via todd)
|
||||||
|
|
||||||
|
HDFS-7122. Use of ThreadLocal<Random> results in poor block placement.
|
||||||
|
(wang)
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
||||||
HDFS-6823. dfs.web.authentication.kerberos.principal shows up in logs for
|
HDFS-6823. dfs.web.authentication.kerberos.principal shows up in logs for
|
||||||
|
|
Loading…
Reference in New Issue