o
    `Û·i¸
  ã                   @   s2   d dl mZmZmZ d dlmZ G dd„ dƒZdS )é    )ÚListÚSetÚTuple)Ú	constantsc                   @   sp   e Zd ZdZdd„ Zdedefdd„Zdeded	efd
d„Zdefdd„Zde	e de
eeef  fdd„ZdS )ÚNodeTrackeraJ  Map nodes to their corresponding logs.

    We need to be a little careful here. At an given point in time, node_id <->
    ip can be interchangeably used, but the node_id -> ip relation is not
    bijective _across time_ since IP addresses can be reused. Therefore, we
    should treat node_id as the only unique identifier.
    c                 C   s   i | _ g | _d S ©N)Únode_mappingÚ	lru_order)Úself© r   úZ/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/autoscaler/_private/node_tracker.pyÚ__init__   s   
zNodeTracker.__init__Únode_idÚvaluec                 C   sd   || j v rd S t| jƒt| j ƒksJ ‚t| jƒtjkr%| j d¡}| j |= || j |< | j |¡ d S )Nr   )r   Úlenr	   r   ÚAUTOSCALER_MAX_NODES_TRACKEDÚpopÚappend)r
   r   r   r   r   r   Ú_add_node_mapping   s   

zNodeTracker._add_node_mappingÚipÚ	node_typec                 C   s"   || j vr|  |||f¡ dS dS )z¨
        Begin to track a new node.

        Args:
            node_id: The node id.
            ip: The node ip address.
            node_type: The node type.
        N)r   r   )r
   r   r   r   r   r   r   Útrack#   s   
	ÿzNodeTracker.trackc                 C   s&   || j v r| j |¡ | j |= dS dS )zñGracefully stop tracking a node. If a node is intentionally removed from
        the cluster, we should stop tracking it so we don't mistakenly mark it
        as failed.

        Args:
            node_id: The node id which failed.
        N)r   r	   Úremove)r
   r   r   r   r   Úuntrack/   s   
þzNodeTracker.untrackÚnon_failed_idsÚreturnc                    s@   | j  ¡ | ‰ g }t‡ fdd„| jƒD ]
}| | j | ¡ q|S )a‚  Get the information about all failed nodes. A failed node is any node which
        we began to track that is not pending or alive (i.e. not failed).

        Args:
            non_failed_ids: Nodes are failed unless they are in this set.

        Returns:
            List[Tuple[str, str]]: A list of tuples. Each tuple is the ip
            address and type of a failed node.
        c                    s   | ˆ v S r   r   )r   ©Úfailed_nodesr   r   Ú<lambda>K   s    z6NodeTracker.get_all_failed_node_info.<locals>.<lambda>)r   ÚkeysÚfilterr	   r   )r
   r   Úfailed_infor   r   r   r   Úget_all_failed_node_info;   s
   z$NodeTracker.get_all_failed_node_infoN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r   r   r   r   r   r"   r   r   r   r   r      s    ÿþr   N)Útypingr   r   r   Úray.autoscaler._privater   r   r   r   r   r   Ú<module>   s    