예제 #1
0
        /// <summary>
        /// Find other nodes in the same nodegroup of <i>localMachine</i> and add them
        /// into <i>excludeNodes</i> as replica should not be duplicated for nodes
        /// within the same nodegroup
        /// </summary>
        /// <returns>number of new excluded nodes</returns>
        protected internal override int AddToExcludedNodes(DatanodeDescriptor chosenNode,
                                                           ICollection <Node> excludedNodes)
        {
            int          countOfExcludedNodes = 0;
            string       nodeGroupScope       = chosenNode.GetNetworkLocation();
            IList <Node> leafNodes            = clusterMap.GetLeaves(nodeGroupScope);

            foreach (Node leafNode in leafNodes)
            {
                if (excludedNodes.AddItem(leafNode))
                {
                    // not a existing node in excludedNodes
                    countOfExcludedNodes++;
                }
            }
            countOfExcludedNodes += AddDependentNodesToExcludedNodes(chosenNode, excludedNodes
                                                                     );
            return(countOfExcludedNodes);
        }
예제 #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));
         }
     }
 }
예제 #3
0
 /* choose one node from the nodegroup that <i>localMachine</i> is on.
  * if no such node is available, choose one node from the nodegroup where
  * a second replica is on.
  * if still no such node is available, choose a random node in the cluster.
  * @return the chosen node
  */
 /// <exception cref="Org.Apache.Hadoop.Hdfs.Server.Blockmanagement.BlockPlacementPolicy.NotEnoughReplicasException
 ///     "/>
 private DatanodeStorageInfo ChooseLocalNodeGroup(NetworkTopologyWithNodeGroup clusterMap
                                                  , 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 node group
     try
     {
         return(ChooseRandom(clusterMap.GetNodeGroup(localMachine.GetNetworkLocation()), excludedNodes
                             , blocksize, maxNodesPerRack, results, avoidStaleNodes, storageTypes));
     }
     catch (BlockPlacementPolicy.NotEnoughReplicasException)
     {
         DatanodeDescriptor newLocal = SecondNode(localMachine, results);
         if (newLocal != null)
         {
             try
             {
                 return(ChooseRandom(clusterMap.GetNodeGroup(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));
         }
     }
 }
예제 #4
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);
            }
        }
예제 #5
0
        /// <returns>
        /// the number of racks over which a given block is replicated
        /// decommissioning/decommissioned nodes are not counted. corrupt replicas
        /// are also ignored
        /// </returns>
        private static int GetNumberOfRacks(BlockManager blockManager, Block b)
        {
            ICollection <string>             rackSet      = new HashSet <string>(0);
            ICollection <DatanodeDescriptor> corruptNodes = GetCorruptReplicas(blockManager).GetNodes
                                                                (b);

            foreach (DatanodeStorageInfo storage in blockManager.blocksMap.GetStorages(b))
            {
                DatanodeDescriptor cur = storage.GetDatanodeDescriptor();
                if (!cur.IsDecommissionInProgress() && !cur.IsDecommissioned())
                {
                    if ((corruptNodes == null) || !corruptNodes.Contains(cur))
                    {
                        string rackName = cur.GetNetworkLocation();
                        if (!rackSet.Contains(rackName))
                        {
                            rackSet.AddItem(rackName);
                        }
                    }
                }
            }
            return(rackSet.Count);
        }
        /// <summary>Scan the targets list: all targets should be on different NodeGroups.</summary>
        /// <remarks>
        /// Scan the targets list: all targets should be on different NodeGroups.
        /// Return false if two targets are found on the same NodeGroup.
        /// </remarks>
        private static bool CheckTargetsOnDifferentNodeGroup(DatanodeStorageInfo[] targets
                                                             )
        {
            if (targets.Length == 0)
            {
                return(true);
            }
            ICollection <string> targetSet = new HashSet <string>();

            foreach (DatanodeStorageInfo storage in targets)
            {
                DatanodeDescriptor node      = storage.GetDatanodeDescriptor();
                string             nodeGroup = NetworkTopology.GetLastHalf(node.GetNetworkLocation());
                if (targetSet.Contains(nodeGroup))
                {
                    return(false);
                }
                else
                {
                    targetSet.AddItem(nodeGroup);
                }
            }
            return(true);
        }