Exemple #1
0
 /// <summary>
 /// add node to the map
 /// return true if the node is added; false otherwise.
 /// </summary>
 internal virtual bool Add(DatanodeDescriptor node)
 {
     hostmapLock.WriteLock().Lock();
     try
     {
         if (node == null || Contains(node))
         {
             return(false);
         }
         string ipAddr   = node.GetIpAddr();
         string hostname = node.GetHostName();
         mapHost[hostname] = ipAddr;
         DatanodeDescriptor[] nodes = map[ipAddr];
         DatanodeDescriptor[] newNodes;
         if (nodes == null)
         {
             newNodes    = new DatanodeDescriptor[1];
             newNodes[0] = node;
         }
         else
         {
             // rare case: more than one datanode on the host
             newNodes = new DatanodeDescriptor[nodes.Length + 1];
             System.Array.Copy(nodes, 0, newNodes, 0, nodes.Length);
             newNodes[nodes.Length] = node;
         }
         map[ipAddr] = newNodes;
         return(true);
     }
     finally
     {
         hostmapLock.WriteLock().Unlock();
     }
 }
Exemple #2
0
        /// <summary>Add all nodes from a dependent nodes list to excludedNodes.</summary>
        /// <returns>number of new excluded nodes</returns>
        private int AddDependentNodesToExcludedNodes(DatanodeDescriptor chosenNode, ICollection
                                                     <Node> excludedNodes)
        {
            if (this.host2datanodeMap == null)
            {
                return(0);
            }
            int countOfExcludedNodes = 0;

            foreach (string hostname in chosenNode.GetDependentHostNames())
            {
                DatanodeDescriptor node = this.host2datanodeMap.GetDataNodeByHostName(hostname);
                if (node != null)
                {
                    if (excludedNodes.AddItem(node))
                    {
                        countOfExcludedNodes++;
                    }
                }
                else
                {
                    Log.Warn("Not able to find datanode " + hostname + " which has dependency with datanode "
                             + chosenNode.GetHostName());
                }
            }
            return(countOfExcludedNodes);
        }
Exemple #3
0
        /// <summary>
        /// remove node from the map
        /// return true if the node is removed; false otherwise.
        /// </summary>
        internal virtual bool Remove(DatanodeDescriptor node)
        {
            if (node == null)
            {
                return(false);
            }
            string ipAddr   = node.GetIpAddr();
            string hostname = node.GetHostName();

            hostmapLock.WriteLock().Lock();
            try
            {
                DatanodeDescriptor[] nodes = map[ipAddr];
                if (nodes == null)
                {
                    return(false);
                }
                if (nodes.Length == 1)
                {
                    if (nodes[0] == node)
                    {
                        Sharpen.Collections.Remove(map, ipAddr);
                        //remove hostname key since last datanode is removed
                        Sharpen.Collections.Remove(mapHost, hostname);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                //rare case
                int i = 0;
                for (; i < nodes.Length; i++)
                {
                    if (nodes[i] == node)
                    {
                        break;
                    }
                }
                if (i == nodes.Length)
                {
                    return(false);
                }
                else
                {
                    DatanodeDescriptor[] newNodes;
                    newNodes = new DatanodeDescriptor[nodes.Length - 1];
                    System.Array.Copy(nodes, 0, newNodes, 0, i);
                    System.Array.Copy(nodes, i + 1, newNodes, i, nodes.Length - i - 1);
                    map[ipAddr] = newNodes;
                    return(true);
                }
            }
            finally
            {
                hostmapLock.WriteLock().Unlock();
            }
        }