Method: Mongo::Cluster#validate_session_support!

Defined in:
lib/mongo/cluster.rb

#validate_session_support!(timeout: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises Error::SessionsNotAvailable if the deployment that the driver is connected to does not support sessions.

Session support may change over time, for example due to servers in the deployment being upgraded or downgraded. If the client isn’t connected to any servers and doesn’t find any servers for the duration of server selection timeout, this method will raise NoServerAvailable. This method is called from the operation execution flow, and if it raises NoServerAvailable the entire operation will fail with that exception, since the operation execution has waited for the server selection timeout for any server to become available (which would be a superset of the servers suitable for the operation being attempted) and none materialized.

Parameters:

  • :timeout (Float | nil)

    Timeout for the validation. Since the validation process involves server selection,

Raises:

  • (Error::SessionsNotAvailable)

    If the deployment that the driver is connected to does not support sessions.

  • (Error::NoServerAvailable)

    If the client isn’t connected to any servers and doesn’t find any servers for the duration of server selection timeout.

Since:

  • 2.0.0



991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
# File 'lib/mongo/cluster.rb', line 991

def validate_session_support!(timeout: nil)
  if topology.is_a?(Topology::LoadBalanced)
    return
  end

  @state_change_lock.synchronize do
    @sdam_flow_lock.synchronize do
      if topology.data_bearing_servers?
        unless topology.logical_session_timeout
          raise_sessions_not_supported
        end
      end
    end
  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, timeout: timeout)
  @state_change_lock.synchronize do
    @sdam_flow_lock.synchronize do
      unless topology.logical_session_timeout
        raise_sessions_not_supported
      end
    end
  end
end