HDFS-6497. Make TestAvailableSpaceVolumeChoosingPolicy deterministic (cmccabe)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1601036 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Colin McCabe 2014-06-06 23:41:08 +00:00
parent 96defb2d7b
commit 38c0114f2b
3 changed files with 18 additions and 6 deletions

View File

@ -327,6 +327,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

View File

@ -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);

View File

@ -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