private ICollection <ExtendedBlock> GetBlocksOnRack(IList <LocatedBlock> blks, string
                                                            rack)
        {
            ICollection <ExtendedBlock> ret = new HashSet <ExtendedBlock>();

            foreach (LocatedBlock blk in blks)
            {
                foreach (DatanodeInfo di in blk.GetLocations())
                {
                    if (rack.Equals(NetworkTopology.GetFirstHalf(di.GetNetworkLocation())))
                    {
                        ret.AddItem(blk.GetBlock());
                        break;
                    }
                }
            }
            return(ret);
        }
Example #2
0
 /// <exception cref="Org.Apache.Hadoop.Hdfs.Server.Blockmanagement.BlockPlacementPolicy.NotEnoughReplicasException
 ///     "/>
 protected internal override DatanodeStorageInfo ChooseLocalRack(Node localMachine
                                                                 , ICollection <Node> excludedNodes, long blocksize, int maxNodesPerRack, IList <DatanodeStorageInfo
                                                                                                                                                 > results, bool avoidStaleNodes, EnumMap <StorageType, int> storageTypes)
 {
     // no local machine, so choose a random machine
     if (localMachine == null)
     {
         return(ChooseRandom(NodeBase.Root, excludedNodes, blocksize, maxNodesPerRack, results
                             , avoidStaleNodes, storageTypes));
     }
     // choose one from the local rack, but off-nodegroup
     try
     {
         string scope = NetworkTopology.GetFirstHalf(localMachine.GetNetworkLocation());
         return(ChooseRandom(scope, excludedNodes, blocksize, maxNodesPerRack, results, avoidStaleNodes
                             , storageTypes));
     }
     catch (BlockPlacementPolicy.NotEnoughReplicasException)
     {
         // find the second replica
         DatanodeDescriptor newLocal = SecondNode(localMachine, results);
         if (newLocal != null)
         {
             try
             {
                 return(ChooseRandom(clusterMap.GetRack(newLocal.GetNetworkLocation()), excludedNodes
                                     , blocksize, maxNodesPerRack, results, avoidStaleNodes, storageTypes));
             }
             catch (BlockPlacementPolicy.NotEnoughReplicasException)
             {
                 //otherwise randomly choose one from the network
                 return(ChooseRandom(NodeBase.Root, excludedNodes, blocksize, maxNodesPerRack, results
                                     , avoidStaleNodes, storageTypes));
             }
         }
         else
         {
             //otherwise randomly choose one from the network
             return(ChooseRandom(NodeBase.Root, excludedNodes, blocksize, maxNodesPerRack, results
                                 , avoidStaleNodes, storageTypes));
         }
     }
 }
Example #3
0
        /// <summary><inheritDoc/></summary>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Server.Blockmanagement.BlockPlacementPolicy.NotEnoughReplicasException
        ///     "/>
        protected internal override void ChooseRemoteRack(int numOfReplicas, DatanodeDescriptor
                                                          localMachine, ICollection <Node> excludedNodes, long blocksize, int maxReplicasPerRack
                                                          , IList <DatanodeStorageInfo> results, bool avoidStaleNodes, EnumMap <StorageType,
                                                                                                                                int> storageTypes)
        {
            int    oldNumOfReplicas = results.Count;
            string rackLocation     = NetworkTopology.GetFirstHalf(localMachine.GetNetworkLocation
                                                                       ());

            try
            {
                // randomly choose from remote racks
                ChooseRandom(numOfReplicas, "~" + rackLocation, excludedNodes, blocksize, maxReplicasPerRack
                             , results, avoidStaleNodes, storageTypes);
            }
            catch (BlockPlacementPolicy.NotEnoughReplicasException)
            {
                // fall back to the local rack
                ChooseRandom(numOfReplicas - (results.Count - oldNumOfReplicas), rackLocation, excludedNodes
                             , blocksize, maxReplicasPerRack, results, avoidStaleNodes, storageTypes);
            }
        }
Example #4
0
        protected internal override string GetRack(DatanodeInfo cur)
        {
            string nodeGroupString = cur.GetNetworkLocation();

            return(NetworkTopology.GetFirstHalf(nodeGroupString));
        }