HDFS-6497. Make TestAvailableSpaceVolumeChoosingPolicy deterministic (cmccabe)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1601035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
14394eed00
commit
9528ed939d
|
@ -648,6 +648,9 @@ Release 2.5.0 - UNRELEASED
|
||||||
HDFS-6424. blockReport doesn't need to invalidate blocks on SBN. (Ming Ma
|
HDFS-6424. blockReport doesn't need to invalidate blocks on SBN. (Ming Ma
|
||||||
via jing9)
|
via jing9)
|
||||||
|
|
||||||
|
HDFS-6497. Make TestAvailableSpaceVolumeChoosingPolicy deterministic
|
||||||
|
(cmccabe)
|
||||||
|
|
||||||
Release 2.4.1 - UNRELEASED
|
Release 2.4.1 - UNRELEASED
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -45,11 +45,19 @@ public class AvailableSpaceVolumeChoosingPolicy<V extends FsVolumeSpi>
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(AvailableSpaceVolumeChoosingPolicy.class);
|
private static final Log LOG = LogFactory.getLog(AvailableSpaceVolumeChoosingPolicy.class);
|
||||||
|
|
||||||
private static final Random RAND = new Random();
|
private final Random random;
|
||||||
|
|
||||||
private long balancedSpaceThreshold = DFS_DATANODE_AVAILABLE_SPACE_VOLUME_CHOOSING_POLICY_BALANCED_SPACE_THRESHOLD_DEFAULT;
|
private long balancedSpaceThreshold = DFS_DATANODE_AVAILABLE_SPACE_VOLUME_CHOOSING_POLICY_BALANCED_SPACE_THRESHOLD_DEFAULT;
|
||||||
private float balancedPreferencePercent = DFS_DATANODE_AVAILABLE_SPACE_VOLUME_CHOOSING_POLICY_BALANCED_SPACE_PREFERENCE_FRACTION_DEFAULT;
|
private float balancedPreferencePercent = DFS_DATANODE_AVAILABLE_SPACE_VOLUME_CHOOSING_POLICY_BALANCED_SPACE_PREFERENCE_FRACTION_DEFAULT;
|
||||||
|
|
||||||
|
AvailableSpaceVolumeChoosingPolicy(Random random) {
|
||||||
|
this.random = random;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AvailableSpaceVolumeChoosingPolicy() {
|
||||||
|
this(new Random());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void setConf(Configuration conf) {
|
public synchronized void setConf(Configuration conf) {
|
||||||
balancedSpaceThreshold = conf.getLong(
|
balancedSpaceThreshold = conf.getLong(
|
||||||
|
@ -128,7 +136,7 @@ public class AvailableSpaceVolumeChoosingPolicy<V extends FsVolumeSpi>
|
||||||
(highAvailableVolumes.size() * balancedPreferencePercent) /
|
(highAvailableVolumes.size() * balancedPreferencePercent) /
|
||||||
preferencePercentScaler;
|
preferencePercentScaler;
|
||||||
if (mostAvailableAmongLowVolumes < replicaSize ||
|
if (mostAvailableAmongLowVolumes < replicaSize ||
|
||||||
RAND.nextFloat() < scaledPreferencePercent) {
|
random.nextFloat() < scaledPreferencePercent) {
|
||||||
volume = roundRobinPolicyHighAvailable.chooseVolume(
|
volume = roundRobinPolicyHighAvailable.chooseVolume(
|
||||||
highAvailableVolumes,
|
highAvailableVolumes,
|
||||||
replicaSize);
|
replicaSize);
|
||||||
|
|
|
@ -22,6 +22,7 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_AVAILABLE_SPACE_
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configurable;
|
import org.apache.hadoop.conf.Configurable;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
@ -251,10 +252,10 @@ public class TestAvailableSpaceVolumeChoosingPolicy {
|
||||||
*/
|
*/
|
||||||
public void doRandomizedTest(float preferencePercent, int lowSpaceVolumes,
|
public void doRandomizedTest(float preferencePercent, int lowSpaceVolumes,
|
||||||
int highSpaceVolumes) throws Exception {
|
int highSpaceVolumes) throws Exception {
|
||||||
@SuppressWarnings("unchecked")
|
Random random = new Random(123L);
|
||||||
final AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi> policy =
|
final AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi> policy =
|
||||||
ReflectionUtils.newInstance(AvailableSpaceVolumeChoosingPolicy.class, null);
|
new AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi>(random);
|
||||||
|
|
||||||
List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>();
|
List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>();
|
||||||
|
|
||||||
// Volumes with 1MB free space
|
// Volumes with 1MB free space
|
||||||
|
|
Loading…
Reference in New Issue