
    &g                        S r SSKJr  SSKJr  SSKJr  SSKJr  \(       a  SSK	J
r
  SrSrSS	 jrSS
 jrSS jrSS jrg)a  Criteria to select ServerDescriptions based on maxStalenessSeconds.

The Max Staleness Spec says: When there is a known primary P,
a secondary S's staleness is estimated with this formula:

  (S.lastUpdateTime - S.lastWriteDate) - (P.lastUpdateTime - P.lastWriteDate)
  + heartbeatFrequencyMS

When there is no known primary, a secondary S's staleness is estimated with:

  SMax.lastWriteDate - S.lastWriteDate + heartbeatFrequencyMS

where "SMax" is the secondary with the greatest lastWriteDate.
    )annotations)TYPE_CHECKING)ConfigurationError)SERVER_TYPE)	Selection
   Z   c                    X[         -   :  a  [        S[         XS-  4-  5      eU [        :  a  [        S[        U 4-  5      eg )NzmaxStalenessSeconds must be at least heartbeatFrequencyMS + %d seconds. maxStalenessSeconds is set to %d, heartbeatFrequencyMS is set to %d.i  zJmaxStalenessSeconds must be at least %d. maxStalenessSeconds is set to %d.)IDLE_WRITE_PERIODr   SMALLEST_MAX_STALENESS)max_stalenessheartbeat_frequencys     dC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/max_staleness_selectors.py_validate_max_stalenessr   .   se    ->>> 2 !-t1KLM
 	
 -- 03I=2YZ
 	
 .    c                   UR                   nU(       d   e/ nUR                   H  nUR                  [        R                  :X  a~  UR
                  (       a  UR
                  (       d   eUR                  UR
                  -
  UR                  UR
                  -
  -
  UR                  -   nXP::  a  UR                  U5        M  M  UR                  U5        M     UR                  U5      $ )zEApply max_staleness, in seconds, to a Selection with a known primary.)
primaryserver_descriptionsserver_typer   RSSecondarylast_write_datelast_update_timer   appendwith_server_descriptions)r   	selectionr   sdss	stalenesss         r   _with_primaryr   ?   s    GN7
C**==K333$$)@)@@@##a&7&77++g.E.EEG//0  )

1 * JJqM + --c22r   c                   UR                  5       nU(       d  UR                  / 5      $ / nUR                   H  nUR                  [        R
                  :X  ad  UR                  (       a  UR                  (       d   eUR                  UR                  -
  UR                  -   nXP::  a  UR                  U5        M  M  UR                  U5        M     UR                  U5      $ )zFApply max_staleness, in seconds, to a Selection with no known primary.)	"secondary_with_max_last_write_dater   r   r   r   r   r   r   r   )r   r   smaxr   r   r   s         r   _no_primaryr#   W   s     779D11"55
C**==K333''A,=,===,,q/@/@@9C`C``I)

1 * JJqM + --c22r   c                    U S:X  a  U$ [        XR                  5        UR                  (       a  [        X5      $ [	        X5      $ )z0Apply max_staleness, in seconds, to a Selection.)r   r   r   r   r#   )r   r   s     r   selectr&   o   s?    
 M+H+HI]66=44r   N)r   intr   r'   returnNone)r   r'   r   r   r(   r   )__doc__
__future__r   typingr   pymongo.errorsr   pymongo.server_typer   pymongo.server_selectorsr   r   r   r   r   r#   r&    r   r   <module>r1      s@    #   - +2
   
"30305r   