HDFS-2335. DataNodeCluster and NNStorage always pull fresh entropy. Contributed by Uma Maheswara Rao G
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1220510 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a89baed833
commit
5e185702ea
@ -234,6 +234,9 @@ Release 0.23.1 - UNRELEASED
|
|||||||
HDFS-2675. Reduce warning verbosity when double-closing edit logs
|
HDFS-2675. Reduce warning verbosity when double-closing edit logs
|
||||||
(todd)
|
(todd)
|
||||||
|
|
||||||
|
HDFS-2335. DataNodeCluster and NNStorage always pull fresh entropy.
|
||||||
|
(Uma Maheswara Rao G via eli)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-2130. Switch default checksum to CRC32C. (todd)
|
HDFS-2130. Switch default checksum to CRC32C. (todd)
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -69,11 +70,23 @@ protected Random initialValue() {
|
|||||||
return new Random();
|
return new Random();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final ThreadLocal<SecureRandom> SECURE_RANDOM = new ThreadLocal<SecureRandom>() {
|
||||||
|
@Override
|
||||||
|
protected SecureRandom initialValue() {
|
||||||
|
return new SecureRandom();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** @return a pseudorandom number generator. */
|
/** @return a pseudo random number generator. */
|
||||||
public static Random getRandom() {
|
public static Random getRandom() {
|
||||||
return RANDOM.get();
|
return RANDOM.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return a pseudo secure random number generator. */
|
||||||
|
public static SecureRandom getSecureRandom() {
|
||||||
|
return SECURE_RANDOM.get();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compartor for sorting DataNodeInfo[] based on decommissioned states.
|
* Compartor for sorting DataNodeInfo[] based on decommissioned states.
|
||||||
|
@ -66,7 +66,6 @@
|
|||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.AbstractList;
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -1086,7 +1085,7 @@ static String createNewStorageId(int port) {
|
|||||||
LOG.warn("Could not find ip address of \"default\" inteface.");
|
LOG.warn("Could not find ip address of \"default\" inteface.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int rand = new SecureRandom().nextInt(Integer.MAX_VALUE);
|
int rand = DFSUtil.getSecureRandom().nextInt(Integer.MAX_VALUE);
|
||||||
return "DS-" + rand + "-" + ip + "-" + port + "-"
|
return "DS-" + rand + "-" + ip + "-" + port + "-"
|
||||||
+ System.currentTimeMillis();
|
+ System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -978,13 +976,7 @@ String newBlockPoolID() throws UnknownHostException{
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rand = 0;
|
int rand = DFSUtil.getSecureRandom().nextInt(Integer.MAX_VALUE);
|
||||||
try {
|
|
||||||
rand = SecureRandom.getInstance("SHA1PRNG").nextInt(Integer.MAX_VALUE);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
LOG.warn("Could not use SecureRandom");
|
|
||||||
rand = DFSUtil.getRandom().nextInt(Integer.MAX_VALUE);
|
|
||||||
}
|
|
||||||
String bpid = "BP-" + rand + "-"+ ip + "-" + System.currentTimeMillis();
|
String bpid = "BP-" + rand + "-"+ ip + "-" + System.currentTimeMillis();
|
||||||
return bpid;
|
return bpid;
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,7 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
@ -234,12 +231,7 @@ static private String getUniqueRackPrefix() {
|
|||||||
System.out.println("Could not find ip address of \"default\" inteface.");
|
System.out.println("Could not find ip address of \"default\" inteface.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int rand = 0;
|
int rand = DFSUtil.getSecureRandom().nextInt(Integer.MAX_VALUE);
|
||||||
try {
|
|
||||||
rand = SecureRandom.getInstance("SHA1PRNG").nextInt(Integer.MAX_VALUE);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
rand = (new Random()).nextInt(Integer.MAX_VALUE);
|
|
||||||
}
|
|
||||||
return "/Rack-" + rand + "-"+ ip + "-" +
|
return "/Rack-" + rand + "-"+ ip + "-" +
|
||||||
System.currentTimeMillis();
|
System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user