+\hLdZddlmZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z mZddlmZddlmZmZddlmZdd lmZdd lmZmZmZdd lmZdd lmZdd l m!Z!ddl"m#Z#ddl$m%Z%e rddl&m'Z'm(Z(m)Z)ddl*m+Z+ddl,m-Z-dZ.d"dZ/d#dZ0GddZ1Gdde1Z2Gdde1Z3Gdde1Z4e5Z6d$dZ7d%dZ8d&d Z9d&d!Z:e.rejve:yy)'z9Class to monitor a MongoDB server on a background thread.) annotationsN) TYPE_CHECKINGAnyOptional)commonperiodic_executor) MovingMinimum)NetworkTimeout_OperationCancelled)Hello) _create_lock) _SDAM_LOGGER _debug_log_SDAMStatusMessage)_shutdown_executors)_is_faas) MovingAverage)ServerDescription) _SrvResolver) ConnectionPool_CancellationContext)TopologySettings)TopologyTc.d|_d|_d|_y)z'PYTHON-2433 Clear error traceback info.N) __traceback__ __context__ __cause__errors ^/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/synchronous/monitor.py _sanitizer"2sEEEOcDtdtj|z S)zReturn the duration since the given start time. Accounts for buggy platforms where time.monotonic() is not monotonic. See PYTHON-4600. g)maxtime monotonic)starts r!_monotonic_durationr)9s sDNN$u, --r#c<eZdZddZd dZd dZd dZd dZd dZy) MonitorBasecdfd }tj||||}||_ddfd }tj||j tj |||_t|y)zBase class to do periodic work on a background thread. The background thread is signaled to stop when the Topology or this instance is freed. c:}|y|jy)NFT)_run)monitorself_refs r!targetz$MonitorBase.__init__..targetLsjG LLNr#)interval min_intervalr1nameNc:}|r|jyyN gc_safe_close)dummyr/r0s r!_on_topology_gcz-MonitorBase.__init__.._on_topology_gcYs jG%%'r#)returnboolr6)r9zOptional[Topology]r;None) rPeriodicExecutor _executorweakrefrefcloseproxy _topology _register) selftopologyr4r2r3r1executorr:r0s @r!__init__zMonitorBase.__init__Cs` %55Ld " (;;tX^^4 xA$r#c8|jjy)z[Start monitoring, or restart after a fork. Multiple calls have no effect. N)r?openrFs r!rKzMonitorBase.openes r#c8|jjy)zGC safe close.N)r?rBrLs r!r8zMonitorBase.gc_safe_closels r#c$|jy)zWClose and stop monitoring. open() restarts the monitor after closing. Nr7rLs r!rBzMonitorBase.closeps r#c8|jjy)zWait for the monitor to stop.N)r?joinrLs r!rPzMonitorBase.joinw r#c8|jjy)z)If the monitor is sleeping, wake it soon.N)r?wakerLs r! request_checkzMonitorBase.request_check{rQr#N)rGrr4strr2intr3floatr;r=) __name__ __module__ __qualname__rIrKr8rBrPrTr#r!r+r+Bs! Dr#r+ceZdZ d fd Zd dZd dZd dZd dZd dZd dZ d dZ dd Z dd Z dd Z xZS)Monitorct||d|jtj||_||_||_|jjj|_ |jduxr|jj|_ d|_ d|_t|||j!|j"|_|j&dk(rd|_y|j&dk(rd|_yt+ |_y)aClass to monitor a MongoDB server on a background thread. Pass an initial ServerDescription, a Topology, a Pool, and TopologySettings. The Topology is weakly referenced. The Pool must be exclusive to this Monitor. pymongo_server_monitor_threadNstreamTpollF)superrIheartbeat_frequencyrMIN_HEARTBEAT_INTERVAL_server_description_pool _settings _pool_options_event_listeners _listenersenabled_for_server_heartbeat_publish_cancel_context_conn_id _RttMonitor_create_pool_for_monitoraddress _rtt_monitorserver_monitoring_mode_streamr)rFserver_descriptionrGpooltopology_settings __class__s r!rIzMonitor.__init__s   +  1 1  ) )  $6  *..66GGt3d8d8d ?C'+ '    - -.@.H.H I   3 3x ?DL  5 5 ? DL'z>DLr#cB|j}|r|jyy)zCancel any concurrent hello check. Note: this is called from a weakref.proxy callback and MUST NOT take any locks. N)rncancel)rFcontexts r! cancel_checkzMonitor.cancel_checks# &&  NN  r#c|jj|jjr|jj yy)z1Start an _RttMonitor that periodically runs ping.N)rsrKr?_stoppedrBrLs r!_start_rtt_monitorzMonitor._start_rtt_monitors:  >> " "    # # % #r#c|jj|jj|j yr6)r?rBrsr8r}rLs r!r8zMonitor.gc_safe_closes0  '') r#ctj|jj|jjdy)NT)return_exceptions)asynciogatherr?rPrsrLs r!rPz Monitor.joins/t~~**,d.?.?.D.D.FZ^_r#cx|j|jj|jyr6)r8rsrB_reset_connectionrLs r!rBz Monitor.closes.  !  r#c8|jjyr6)rgresetrLs r!rzMonitor._reset_connections r#c |j} |j|_|jj|j|jjt|jjt |j"rV|jj r@|jj$r*|j'|jj|jjr&|j r|jj|jjr|jjyy#t$r}t|t |jj ||_|j r|jjYd}~|jjr|jjyyd}~wwxYw#t($r|jYwxYw#|jjr|jjwwxYw)Nr) reset_poolinterrupt_connections)rf _check_serverr r"rrris_server_type_knownr? skip_sleeprrsrBrD on_changer isinstancer rutopology_versionrReferenceError)rFprev_sdexcs r!r.z Monitor._runs' *..G +/+=+=+?( NN $ $((3399&01I1I1O1OQ_&` %  ||((==,,=='')))+''--'2N2N))+ ~~&&!!'')'E' #+<,,44C,(//NN--/0~~&&!!'')'E <  JJL ~~&&!!'')'sM G0EC>#~~::'+ww'+'@'@&qz&qz# $(#6#6D  GGDM(,(?(?(E %Ho%%!!,,_=#00446 GW"7HgSZ[B}}222BB_h8J8J((7 .@@#~~::'+ww'+'@'@&qz&qz#.5"++ Q( ( ( s .GKK ctj}|jrt|j d}n{|j r]|j rQ|jjr;|j|jj|jj}n|jdd}t|}||fS)zcReturn (Hello, round_trip_time). Can raise ConnectionFailure or OperationFailure. T)rN) r&r' more_to_comer _next_replyruperformed_handshakerfr_hellorhrdr))rFrr(rrs r!rzMonitor._check_with_socket`s     T--/4@H LLT55$:R:R:c:c{{((9922H {{4.H&u-!!r#)rvrrGrrwrrxrrX)r;r)rrr;ztuple[Hello, float])rYrZr[rIr}rr8rPrBrr.rrr __classcell__rys@r!r^r^se&*-&*&* &* , &*P & `!(*T%;N;z"r#r^c0eZdZdfd ZddZddZxZS) SrvMonitorcRt||dtj|j||_|j j |_t|j jtsJ|j j|_ tj|_y)zClass to poll SRV records on a background thread. Pass a Topology and a TopologySettings. The Topology is weakly referenced. pymongo_srv_polling_threadN)rcrIrMIN_SRV_RESCAN_INTERVALrdrh_seeds _seedlistrfqdnrU_fqdnr&r' _startup_time)rFrGrxrys r!rIzSrvMonitor.__init__ys~   (  * *  1 1  +..$..--s333..-- !^^-r#c(tj|jtjzkry|j }|r.||_ |jj|j yy#t$r|jYywxYwr6) r&r'rrr _get_seedlistrrD on_srv_updaterrB)rFseedlists r!r.zSrvMonitor._runsw >> d0063Q3QQ Q %%' %DN ,,T^^< "   s%A55BBc t|j|jjj|jj }|j \}}t|dk(rt |jjt|tj|S#t$r|jYywxYw)zXPoll SRV records for a seedlist. Returns a list of ServerDescriptions. rN)rrrh pool_optionsconnect_timeoutsrv_service_nameget_hosts_and_min_ttllenrr?update_intervalr%rrrT)rFresolverrttls r!rzSrvMonitor._get_seedlists  # ++;;//H %::)rGrrxrrwrrX)rrWr;r=)r;ztuple[Optional[float], float])r;rW) rYrZr[rIrBrrrr.rrrs@r!rprps'$" 0 F % .r#rpcbtj|t}tj |yr6)r@rA _unregister _MONITORSadd)r/rAs r!rErEs ++g{ +C MM#r#c.tj|yr6)rremove) monitor_refs r!rrs [!r#cvtytt}|D]}|}|s |jd}yr6)rlistr8)monitorsrAr/s r!_shutdown_monitorsrsDIH$%   ! ! #$ Gr#cBt}|r|t}|r|yyr6)rr)shutdowns r!_shutdown_resourcesrs!!H "H r#)r rr;r=)r(rWr;rW)r/r+r;r=)rz"weakref.ReferenceType[MonitorBase]r;r=rX)<__doc__ __future__rratexitrr&r@typingrrrpymongorr pymongo._csotr pymongo.errorsr r pymongo.hellor pymongo.lockr pymongo.loggerrrrpymongo.periodic_executorrpymongo.pool_optionsrpymongo.read_preferencesrpymongo.server_descriptionr pymongo.synchronous.srv_resolverrpymongo.synchronous.poolrrrpymongo.synchronous.settingsrpymongo.synchronous.topologyr_IS_SYNCr"r)r+r^rrpsetrrErrrregisterr\r#r!rs@"  //-'>%GG9)289 >5 .;;|u"ku"p99x=.+=.F E  "   FOO'( r#