lib/mongo/cluster.rb in mongo-2.20.1 vs lib/mongo/cluster.rb in mongo-2.21.0

- old
+ new

@@ -777,16 +777,23 @@ # # @param [ true, false ] ping Whether to ping the server before selection. # Deprecated and ignored. # @param [ Session | nil ] session Optional session to take into account # for mongos pinning. + # @param [ Float | nil ] :timeout Timeout in seconds for the operation, + # if any. # # @return [ Mongo::Server ] A primary server. # # @since 2.0.0 - def next_primary(ping = nil, session = nil) - ServerSelector.primary.select_server(self, nil, session) + def next_primary(ping = nil, session = nil, timeout: nil) + ServerSelector.primary.select_server( + self, + nil, + session, + timeout: timeout + ) end # Get the connection pool for the server. # # @example Get the connection pool. @@ -972,12 +979,15 @@ # is connected to does not support sessions. # @raise [ Error::NoServerAvailable ] If the client isn't connected to # any servers and doesn't find any servers for the duration of # server selection timeout. # + # @param [ Float | nil ] :timeout Timeout for the validation. Since the + # validation process involves server selection, + # # @api private - def validate_session_support! + def validate_session_support!(timeout: nil) if topology.is_a?(Topology::LoadBalanced) return end @state_change_lock.synchronize do @@ -991,10 +1001,10 @@ end # No data bearing servers known - perform server selection to try to # get a response from at least one of them, to return an accurate # assessment of whether sessions are currently supported. - ServerSelector.get(mode: :primary_preferred).select_server(self) + ServerSelector.get(mode: :primary_preferred).select_server(self, timeout: timeout) @state_change_lock.synchronize do @sdam_flow_lock.synchronize do unless topology.logical_session_timeout raise_sessions_not_supported end