
    fr                        d dl mZmZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	ej                  j                  ej                  j                  ej                  j                  e            d      Z ej                          Z G d d      Zy)    )ListOptionalNlibc                       e Zd ZdZdZddedee   fdZdefdZ	e
d	        Ze
d
        Ze
d        Ze
d        ZdefdZd Zd Zy)Serverz 
    The milvus-lite server
    milvusNdb_fileaddressc                    t         j                  j                  d      :t        j                  t         j                  d         j                         | _        n,t        j                  t              j                         | _        t        j                  |      j                         | _        t        j                  d| j                  j                        s#t        d| j                  j                   d      t        | j                  j                        dkD  r#t        d| j                  j                   d      | j                  j                  | _        || _        d| _        t%        j&                          d	| j                  j                   d
| _        t+        | j                  j                  d| j                  j                   dz        | _        d| _        y)a  
        Args:
            db_file (str):
               The local file to store data.
            address (address, optional):
               grpc server address, example: localhost:19530,
               if not set, the MilvusLite service will use UDS.
        BIN_PATHNz^[a-zA-Z0-9.\-_]+$zUnsupport db name z(, the name must match ^[a-zA-Z0-9.\-_]+$$   zDb name z$ is too long, should be less than 36_z.sock.z.lock)osenvirongetpathlibPathabsolute	_bin_pathr   _db_filerematchnameRuntimeErrorlenparent	_work_dir_address_ptempfilemktemp	_uds_pathstr
_lock_path_lock_fd)selfr	   r
   s      Q/opt/lhia/ganansol/python/venv/lib/python3.12/site-packages/milvus_lite/server.py__init__zServer.__init__$   sX    ::>>*%1$\\"**Z*@AJJLDN$\\(3<<>DNW-668xx-t}}/A/AB!3DMM4F4F3GGopqqt}}!!"R'$--*<*<)==abcc--$OO-.a0B0B/C5Idmm22q9K9K8LE5RRS    returnc                     | j                   j                         st        j                  d       y| j                  j                         s t        j                  d| j                         y)NzBin path not existsFzDir %s not existT)r   existsloggererrorr   r'   s    r(   initzServer.init=   sH    ~~$$&LL./~~$$&LL+T^^<r*   c                 2    t        | j                  dz        S )Nr   )r$   r   r0   s    r(   
milvus_binzServer.milvus_binE   s    4>>H,--r*   c                 B    t         j                  j                  dd      S )N	LOG_LEVELERROR)r   r   r   r0   s    r(   	log_levelzServer.log_levelI   s    zz~~k733r*   c                      d| j                    S )Nzunix:)r#   r0   s    r(   uds_pathzServer.uds_pathM   s    t~~&''r*   c                     | j                   .| j                  | j                  | j                   | j                  gS | j                  | j                  | j                  | j                  | j
                  gS N)r   r3   r   r7   r9   r%   r0   s    r(   argszServer.argsQ   sP    ==$OOT]]DMM4>>RRt~~t__r*   c                    | j                   J d       t        | j                  d      | _        	 t	        j
                  | j                  t        j                  t        j                  z         t        j                  | j                  t        | j                        t        | j                        dt        | j                              | _         y# t        $ r# t        j!                  d| j"                         Y yw xY w)NzServer already starteda)LD_LIBRARY_PATHDYLD_LIBRARY_PATH)r<   envcwdTz;Open %s failed, the file has been opened by another programF)r    openr%   r&   fcntllockfLOCK_EXLOCK_NB
subprocessPopenr<   r$   r   r   BlockingIOErrorr.   r/   r   r0   s    r(   startzServer.startW   s    ww8 88T__c2	KKu}}u}}'DE &&YY'*4>>':),T^^)< 'DG  	LLVX\XeXef	s   B"C )C?>C?c                    | j                   >	 | j                   j                          | j                   j                  d       d | _         | j                  rOt        j                  | j                  t        j                         | j                  j                          d | _        t        j                  | j                        j                  d       t        j                  | j                        j                  d       y # t        j                  $ r: | j                   j                          | j                   j                  d       Y w xY w)N   )timeout   T)
missing_ok)r    	terminatewaitrH   TimeoutExpiredkillr&   rD   flockLOCK_UNcloser   r   r#   unlinkr%   r0   s    r(   stopzServer.stopi   s    77(!!#Q' DG==KKu}}5MM! DMT^^$++t+<T__%,,,= ,, (Q'(s   6D A	EEc                 $    | j                          y r;   )rY   r0   s    r(   __del__zServer.__del__y   s    		r*   r;   )__name__
__module____qualname____doc__
MILVUS_BINr$   r   r)   boolr1   propertyr3   r7   r9   r<   rK   rY   r[    r*   r(   r   r      s     J hsm 2d  . . 4 4 ( ( ` `
t $> r*   r   )typingr   r   r!   r   rH   r   loggingrD   r   pathjoindirnameabspath__file__r   	getLoggerr.   r   rc   r*   r(   <module>rl      sm    "  	     	 77<<(ABEJ 
			] ]r*   