public virtual void TestChooseTargetWithDependencies() { for (int i = 0; i < NumOfDatanodes; i++) { cluster.Remove(dataNodes[i]); } for (int i_1 = 0; i_1 < NumOfDatanodesMoreTargets; i_1++) { DatanodeDescriptor node = dataNodesInMoreTargetsCase[i_1]; if (cluster.Contains(node)) { cluster.Remove(node); } } Host2NodesMap host2DatanodeMap = namenode.GetNamesystem().GetBlockManager().GetDatanodeManager ().GetHost2DatanodeMap(); for (int i_2 = 0; i_2 < NumOfDatanodesForDependencies; i_2++) { cluster.Add(dataNodesForDependencies[i_2]); host2DatanodeMap.Add(dataNodesForDependencies[i_2]); } //add dependencies (node1 <-> node2, and node3<->node4) dataNodesForDependencies[1].AddDependentHostName(dataNodesForDependencies[2].GetHostName ()); dataNodesForDependencies[2].AddDependentHostName(dataNodesForDependencies[1].GetHostName ()); dataNodesForDependencies[3].AddDependentHostName(dataNodesForDependencies[4].GetHostName ()); dataNodesForDependencies[4].AddDependentHostName(dataNodesForDependencies[3].GetHostName ()); //Update heartbeat for (int i_3 = 0; i_3 < NumOfDatanodesForDependencies; i_3++) { UpdateHeartbeatWithUsage(dataNodesForDependencies[i_3], 2 * HdfsConstants.MinBlocksForWrite * BlockSize, 0L, 2 * HdfsConstants.MinBlocksForWrite * BlockSize, 0L, 0L, 0L, 0 , 0); } IList <DatanodeStorageInfo> chosenNodes = new AList <DatanodeStorageInfo>(); DatanodeStorageInfo[] targets; ICollection <Node> excludedNodes = new HashSet <Node>(); excludedNodes.AddItem(dataNodesForDependencies[5]); //try to select three targets as there are three node groups targets = ChooseTarget(3, dataNodesForDependencies[1], chosenNodes, excludedNodes ); //Even there are three node groups, verify that //only two targets are selected due to dependencies NUnit.Framework.Assert.AreEqual(targets.Length, 2); NUnit.Framework.Assert.AreEqual(targets[0], storagesForDependencies[1]); NUnit.Framework.Assert.IsTrue(targets[1].Equals(storagesForDependencies[3]) || targets [1].Equals(storagesForDependencies[4])); //verify that all data nodes are in the excluded list NUnit.Framework.Assert.AreEqual(excludedNodes.Count, NumOfDatanodesForDependencies ); for (int i_4 = 0; i_4 < NumOfDatanodesForDependencies; i_4++) { NUnit.Framework.Assert.IsTrue(excludedNodes.Contains(dataNodesForDependencies[i_4 ])); } }
/// <summary> /// Get an instance of the configured Block Placement Policy based on the /// the configuration property /// <see cref="Org.Apache.Hadoop.Hdfs.DFSConfigKeys.DfsBlockReplicatorClassnameKey"/> /// . /// </summary> /// <param name="conf">the configuration to be used</param> /// <param name="stats">an object that is used to retrieve the load on the cluster</param> /// <param name="clusterMap">the network topology of the cluster</param> /// <returns>an instance of BlockPlacementPolicy</returns> public static BlockPlacementPolicy GetInstance(Configuration conf, FSClusterStats stats, NetworkTopology clusterMap, Host2NodesMap host2datanodeMap) { Type replicatorClass = conf.GetClass <BlockPlacementPolicy>(DFSConfigKeys.DfsBlockReplicatorClassnameKey , DFSConfigKeys.DfsBlockReplicatorClassnameDefault); BlockPlacementPolicy replicator = ReflectionUtils.NewInstance(replicatorClass, conf ); replicator.Initialize(conf, stats, clusterMap, host2datanodeMap); return(replicator); }
protected internal override void Initialize(Configuration conf, FSClusterStats stats , NetworkTopology clusterMap, Host2NodesMap host2datanodeMap) { base.Initialize(conf, stats, clusterMap, host2datanodeMap); }
/// <summary>Used to setup a BlockPlacementPolicy object.</summary> /// <remarks> /// Used to setup a BlockPlacementPolicy object. This should be defined by /// all implementations of a BlockPlacementPolicy. /// </remarks> /// <param name="conf">the configuration object</param> /// <param name="stats">retrieve cluster status from here</param> /// <param name="clusterMap">cluster topology</param> protected internal abstract void Initialize(Configuration conf, FSClusterStats stats , NetworkTopology clusterMap, Host2NodesMap host2datanodeMap);