
    %`i#                     <   d dl Z d dlmZmZ d dlZd dlmc mZ d dlmc m	Z	 d dl
Zd dlmZ d dlmZ d dlmZ d dlmZ ddgZej                                        Zd	 Zdd
Z	 	 	 	 	 	 	 ddZddZ	 ddZd ZddedefdZdeeej         e!f                  fdZ"dS )    N)ListTuple)build_address)GlobalState)GcsClientOptions)
common_pb2free	global_gcc                  d    t           j        j        j        } | j                                         dS )z3Trigger gc.collect() on all workers in the cluster.N)ray_privateworkerglobal_workercore_workerr
   r   s    m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/_private/internal_api.pyr
   r
      s,     \ .F
  """""    c                     t          j        |           } t                      }t          j        | d dd          }|                    |           |S )NTF)allow_cluster_id_nilfetch_cluster_id_if_nil)services%canonicalize_bootstrap_address_or_dier   r   create_initialize_global_state)addressstateoptionss      r   get_state_from_addressr      sV    <WEEGMME%D%  G 
""7+++Lr   NODE_ADDRESSOBJECT_SIZEBTFc                     ddl m} t          |           }t          |          }	|rt	          |	          S  |||||||          t	          |	          z   S )Nr   )memory_summary)ray.dashboard.memory_utilsr#   r   get_memory_info_replystore_stats_summary)
r   group_bysort_byunits	line_wrap
stats_onlynum_entriesr#   r   replys
             r   r#   r#   #   sw     :99999"7++E!%((E *"5)))>x)UK E""# #r   c                    ddl m} ddlm}m} ||Nd}|                                 D ]}|d         r|} n|
J d            t          |d         |d                   }nt          ||          } ||d	t          fd
t          fg          }	|                    |	          }
|
	                    |
                    d          d          }|S )zReturns global memory info.r   init_grpc_channelnode_manager_pb2node_manager_pb2_grpcNAlivezEvery raylet is deadNodeManagerAddressNodeManagerPortgrpc.max_send_message_lengthgrpc.max_receive_message_lengthr   Finclude_memory_infog      N@timeout)ray._private.grpc_utilsr0   ray.core.generatedr2   r3   
node_tabler   MAX_MESSAGE_LENGTHNodeManagerServiceStubFormatGlobalMemoryInfoFormatGlobalMemoryInfoRequest)r   node_manager_addressnode_manager_portr0   r2   r3   rayletnoderaylet_addresschannelstubr-   s               r   r%   r%   8   sA    :99999JJJJJJJJ #'8'@$$&& 	 	DG}  !!#9!!!&'(&1B*C
 
 '';=NOO+-?@.0BC
  G !77@@D''6656QQ (  E Lr   c                    ddl m} ddlm}m} | |J t          | |          } ||dt          fdt          fg          }|                    |          }|                    |	                    |          d	
          }	|	S )z@Returns NodeStats object describing memory usage in the cluster.r   r/   r1   Nr7   r8   r9   r:   g      >@r<   )
r>   r0   r?   r2   r3   r   rA   rB   GetNodeStatsGetNodeStatsRequest)
rE   rF   r;   r0   r2   r3   rI   rJ   rK   
node_statss
             r   rO   rO   ^   s    
 :99999JJJJJJJJ  +0A0M0MM"#79JKKN+-?@.0BC
  G !77@@D"",,AT,UU #  J r   c           
         d}|d                     t          | j        j        dz            | j        j        t          d| j        j        z  | j        j        z  d          t          d| j        j        z  | j        j        z  d                    z  }| j        j        dk    r2|d                     t          | j        j        dz                      z  }| j        j	        dk    re|d                     t          | j        j
        dz            | j        j        t          | j        j
        dz  | j        j	        z                      z  }| j        j        dk    re|d	                     t          | j        j        dz            | j        j        t          | j        j        dz  | j        j        z                      z  }| j        j        r|d
z  }|S )zDReturns formatted string describing object store stats in all nodes.z6--- Aggregate object store stats across all nodes ---
z=Plasma memory usage {} MiB, {} objects, {}% full, {}% needed
i   d      r   z%Plasma filesystem mmap usage: {} MiB
z:Spilled {} MiB, {} objects, avg write throughput {} MiB/s
z:Restored {} MiB, {} objects, avg read throughput {} MiB/s
z4Object fetches queued, waiting for available memory.)formatintstore_statsobject_store_bytes_usednum_local_objectsroundobject_store_bytes_availobject_store_bytes_primary_copyobject_store_bytes_fallbackspill_time_total_sspilled_bytes_totalspilled_objects_totalrestore_time_total_srestored_bytes_totalrestored_objects_totalobject_pulls_queued)r-   store_summarys     r   r&   r&   y   s	   MM 	6!9[IJJ/#;<#<= 	  #CD#<= 	 
 
M& 4q88AHH!=MNN
 
 	
 +a//IPPE%9[IJJ!7%9"$':;  
	
 -11IPPE%:kJKK!8%:"$'<=  
	
 , POOr   object_refs
local_onlyc                    t          j        dt                     t          j        j        j        }t          | t          j                  r| g} t          | t                    s/t          d                    t          |                               | D ]>}t          |t          j                  s"t          d                    |                    ?|                                 t          j        d          5  t!          |           dk    r	 ddd           dS |j                            | |           ddd           dS # 1 swxY w Y   dS )a  
    DeprecationWarning: `free` is a deprecated API and will be
    removed in a future version of Ray. If you have a use case
    for this API, please open an issue on GitHub.

    Free a list of IDs from the in-process and plasma object stores.

    This function is a low-level API which should be used in restricted
    scenarios.

    If local_only is false, the request will be send to all object stores.

    This method will not return any value to indicate whether the deletion is
    successful or not. This function is an instruction to the object store. If
    some of the objects are in use, the object stores will delete them later
    when the ref count is down to 0.

    Examples:

        .. testcode::

            import ray

            @ray.remote
            def f():
                return 0

            obj_ref = f.remote()
            ray.get(obj_ref)  # wait for object to be created first
            free([obj_ref])  # unpin & delete object globally

    Args:
        object_refs (List[ObjectRef]): List of object refs to delete.
        local_only: Whether only deleting the list of objects in local
            object store or all object stores.
    z`free` is a deprecated API and will be removed in a future version of Ray. If you have a use case for this API, please open an issue on GitHub.z*free() expects a list of ObjectRef, got {}zIAttempting to call `free` on the value {}, which is not an ray.ObjectRef.zray.freer   N)warningswarnDeprecationWarningr   r   r   r   
isinstance	ObjectReflist	TypeErrorrS   typecheck_connected	profilingprofilelenr   free_objects)rd   re   r   
object_refs       r   r	   r	      s   J M	O  
 \ .F+s}-- $"mk4(( 
8??[@Q@QRR
 
 	

 "  
*cm44 	117
1C1C  	 		:	&	& A A{q  A A A A A A A A 	''Z@@@	A A A A A A A A A A A A A A A A A As   ;EEE	E	returnc                      t           j        j        j        } |                                  | j                                        S )a  Return the locally submitted ongoing retry tasks
       triggered by lineage reconstruction.

    NOTE: for the lineage reconstruction task status,
    this method only returns the status known to the submitter
    (i.e. it returns SUBMITTED_TO_WORKER instead of RUNNING).

    The return type is a list of pairs where pair.first is the
    lineage reconstruction task info and pair.second is the number
    of ongoing lineage reconstruction tasks of this type.
    )r   r   r   r   ro   r   .get_local_ongoing_lineage_reconstruction_tasksr   s    r   rw   rw      s8     \ .F
LLNNNr   )N)Nr   r    r!   TFN)NN)NNT)F)#rg   typingr   r   r   ray._private.profilingr   rp   ray._private.servicesr   ray._private.workerray._common.network_utilsr   ray._private.stater   ray._rayletr   r?   r   __all___configmax_grpc_message_sizerA   r
   r   r#   r%   rO   r&   rl   boolr	   LineageReconstructionTaskrT   rw    r   r   <module>r      s            



 * * * * * * * * * ( ( ( ( ( ( ( ( (     3 3 3 3 3 3 * * * * * * ( ( ( ( ( ( ) ) ) ) ) );
[6688 # # #    
# # # #*# # # #N LP   67 7 7tAA AAd AA AA AA AA AAHO	*
.
349 O O O O O Or   