Class: Mongo::Cluster
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/mongo/cluster.rb, lib/mongo/cluster/periodic_executor.rb, lib/mongo/cluster/sdam_flow.rb, lib/mongo/cluster/topology.rb, lib/mongo/cluster/topology.rb, lib/mongo/cluster/reapers/cursor_reaper.rb, lib/mongo/cluster/reapers/socket_reaper.rb, lib/mongo/cluster/topology/base.rb, lib/mongo/cluster/topology/load_balanced.rb, lib/mongo/cluster/topology/no_replica_set_options.rb, lib/mongo/cluster/topology/replica_set_no_primary.rb, lib/mongo/cluster/topology/replica_set_with_primary.rb, lib/mongo/cluster/topology/sharded.rb, lib/mongo/cluster/topology/single.rb, lib/mongo/cluster/topology/unknown.rb |
Overview
Copyright © 2018-2020 MongoDB Inc.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Constant Summary
-
CLUSTER_TIME =
Deprecated.
The cluster time key in responses from mongos servers.
'clusterTime'.freeze
-
COSMOSDB_HOST_PATTERNS =
%w[ .cosmos.azure.com ]
-
COSMOSDB_LOG_MESSAGE =
'You appear to be connected to a CosmosDB cluster. ' \ 'For more information regarding feature compatibility and support please visit ' \ 'https://www.mongodb.com/supportability/cosmosdb'
-
DOCUMENTDB_HOST_PATTERNS =
%w[ .docdb.amazonaws.com .docdb-elastic.amazonaws.com ]
-
DOCUMENTDB_LOG_MESSAGE =
'You appear to be connected to a DocumentDB cluster. ' \ 'For more information regarding feature compatibility and support please visit ' \ 'https://www.mongodb.com/supportability/documentdb'
-
IDLE_WRITE_PERIOD_SECONDS =
How often an idle primary writes a no-op to the oplog.
10
-
MAX_READ_RETRIES =
The default number of legacy read retries.
1
-
MAX_WRITE_RETRIES =
The default number of legacy write retries.
1
-
READ_RETRY_INTERVAL =
The default read retry interval, in seconds, when using legacy read retries.
5
Loggable
- Included
Class Method Summary
-
.create(client, monitoring: nil) ⇒ Cluster
Internal use only
Internal use only
Create a cluster for the provided client, for use when we don’t want the client’s original cluster instance to be the same.
-
.new(seeds, monitoring, options = Options::Redacted.new) ⇒ Cluster
constructor
Internal use only
Internal use only
Instantiate the new cluster.
Instance Attribute Summary
- #app_metadata ⇒ Mongo::Server::AppMetadata readonly
-
#connected? ⇒ true|false
readonly
Internal use only
Internal use only
Whether the cluster object is connected to its cluster.
-
#connecting? ⇒ true|false
readonly
Internal use only
Internal use only
Whether the cluster object is in the process of connecting to its cluster.
-
#has_writable_server? ⇒ true, false
readonly
Determine if the cluster would select a writable server.
-
#load_balanced? ⇒ true | false
readonly
Returns whether the cluster is configured to be in the load-balanced topology.
- #monitor_app_metadata readonly Internal use only Internal use only
- #monitoring ⇒ Monitoring readonly
- #options ⇒ Hash readonly
- #push_monitor_app_metadata readonly Internal use only Internal use only
- #seeds ⇒ Array<String> readonly Internal use only Internal use only
- #server_selection_semaphore readonly Internal use only Internal use only
- #session_pool readonly Internal use only Internal use only
- #srv_monitor readonly Internal use only Internal use only
-
#topology ⇒ Integer?
readonly
The logical session timeout value in minutes.
ClusterTime::Consumer
- Included
#cluster_time | The cluster time tracked by the object including this module. |
Event::Subscriber
- Included
Monitoring::Publishable
- Included
Instance Method Summary
-
#==(other) ⇒ true, false
Determine if this cluster of servers is equal to another object.
-
#add(host, add_options = nil) ⇒ Server
Add a server to the cluster with the provided address.
-
#addresses ⇒ Array<Mongo::Address>
The addresses in the cluster.
-
#close ⇒ nil
Internal use only
Internal use only
Closes the cluster.
- #disconnect_server_if_connected(server) Internal use only Internal use only
-
#has_readable_server?(server_selector = nil) ⇒ true, false
Determine if the cluster would select a readable server for the provided read preference.
-
#heartbeat_interval ⇒ Float
Internal use only
Internal use only
Get the refresh interval for the server.
-
#inspect ⇒ String
Get the nicer formatted string for use in inspection.
- #max_read_retries ⇒ Integer deprecated Deprecated.
-
#next_primary(ping = nil, session = nil, timeout: nil) ⇒ Mongo::Server
Get the next primary server we can send an operation to.
- #pool(server) ⇒ Server::ConnectionPool deprecated Deprecated.
- #read_retry_interval ⇒ Float deprecated Deprecated.
-
#reconnect! ⇒ true
deprecated
Deprecated.
Use Client#reconnect to reconnect to the cluster instead of calling this method. This method does not send SDAM events.
-
#remove(host, disconnect: true) ⇒ Array<Server> | true | false
Remove the server from the cluster for the provided address, if it exists.
-
#run_sdam_flow(previous_desc, updated_desc, options = {})
Internal use only
Internal use only
Runs SDAM flow on the cluster.
-
#scan!(sync = true) ⇒ true
Force a scan of all known servers in the cluster.
-
#servers ⇒ Array<Server>
Get a list of server candidates from the cluster that can have operations executed on them.
- #servers_list Internal use only Internal use only
-
#set_server_list(server_address_strs)
Internal use only
Internal use only
Sets the list of servers to the addresses in the provided list of address strings.
- #summary
-
#update_cluster_time(result) ⇒ Object
Update the max cluster time seen in a response.
- #update_topology(new_topology) Internal use only Internal use only
-
#validate_session_support!(timeout: nil)
Internal use only
Internal use only
Raises Error::SessionsNotAvailable if the deployment that the driver is connected to does not support sessions.
- #fabricate_lb_sdam_events_and_set_server_type private
-
#possibly_warn_about_compatibility!
private
Compares the server hosts with address suffixes of known services that provide limited MongoDB API compatibility, and warns about them.
- #raise_sessions_not_supported private
- #recreate_topology(new_topology_template, previous_topology) private
- #start_stop_srv_monitor private Internal use only Internal use only
ClusterTime::Consumer
- Included
#advance_cluster_time | Advance the tracked cluster time document for the object including this module. |
Event::Subscriber
- Included
#subscribe_to | Subscribe to the provided event. |
Monitoring::Publishable
- Included
#publish_cmap_event, #publish_event, #publish_sdam_event, #command_completed, #command_failed, #command_started, #command_succeeded, #duration |
Loggable
- Included
#log_debug | Convenience method to log debug messages with the standard prefix. |
#log_error | Convenience method to log error messages with the standard prefix. |
#log_fatal | Convenience method to log fatal messages with the standard prefix. |
#log_info | Convenience method to log info messages with the standard prefix. |
#log_warn | Convenience method to log warn messages with the standard prefix. |
#logger | Get the logger instance. |
#_mongo_log_prefix, #format_message |
Class Method Details
.create(client, monitoring: nil) ⇒ Cluster
Create a cluster for the provided client, for use when we don’t want the client’s original cluster instance to be the same.
# File 'lib/mongo/cluster.rb', line 297
def self.create(client, monitoring: nil) cluster = Cluster.new( client.cluster.addresses.map(&:to_s), monitoring || Monitoring.new, client., ) client.instance_variable_set(:@cluster, cluster) end
Instance Attribute Details
#app_metadata ⇒ Mongo::Server::AppMetadata (readonly)
# File 'lib/mongo/cluster.rb', line 319
attr_reader :
#connected? ⇒ true
|false
(readonly)
Whether the cluster object is connected to its cluster.
# File 'lib/mongo/cluster.rb', line 426
def connected? @update_lock.synchronize do !!@connected end end
#connecting? ⇒ true
|false
(readonly)
Whether the cluster object is in the process of connecting to its cluster.
# File 'lib/mongo/cluster.rb', line 414
def connecting? @update_lock.synchronize do !!@connecting end end
#has_writable_server? ⇒ true
, false
(readonly)
Determine if the cluster would select a writable server.
# File 'lib/mongo/cluster.rb', line 769
def has_writable_server? topology.has_writable_server?(self) end
#load_balanced? ⇒ true
| false
(readonly)
Returns whether the cluster is configured to be in the load-balanced topology.
# File 'lib/mongo/cluster.rb', line 347
def load_balanced? topology.is_a?(Topology::LoadBalanced) end
#monitor_app_metadata (readonly)
# File 'lib/mongo/cluster.rb', line 322
attr_reader :
#monitoring ⇒ Monitoring (readonly)
# File 'lib/mongo/cluster.rb', line 310
attr_reader :monitoring
#options ⇒ Hash
(readonly)
# File 'lib/mongo/cluster.rb', line 307
attr_reader :
#push_monitor_app_metadata (readonly)
# File 'lib/mongo/cluster.rb', line 325
attr_reader :
#seeds ⇒ Array
<String
> (readonly)
# File 'lib/mongo/cluster.rb', line 333
attr_reader :seeds
#server_selection_semaphore (readonly)
# File 'lib/mongo/cluster.rb', line 490
attr_reader :server_selection_semaphore
#session_pool (readonly)
# File 'lib/mongo/cluster.rb', line 338
attr_reader :session_pool
#srv_monitor (readonly)
# File 'lib/mongo/cluster.rb', line 360
attr_reader :srv_monitor
#topology ⇒ Integer
? (readonly)
The logical session timeout value in minutes.
# File 'lib/mongo/cluster.rb', line 313
attr_reader :topology
Instance Method Details
#==(other) ⇒ true
, false
Determine if this cluster of servers is equal to another object. Checks the servers currently in the cluster, not what was configured.
#add(host, add_options = nil) ⇒ Server
Add a server to the cluster with the provided address. Useful in auto-discovery of new servers when an existing server executes a hello and potentially non-configured servers were included.
# File 'lib/mongo/cluster.rb', line 845
def add(host, =nil) address = Address.new(host, ) if !addresses.include?(address) opts = .merge(monitor: false) # If we aren't starting the montoring threads, we also don't want to # start the pool's populator thread. opts.merge!(populator_io: false) unless .fetch(:monitoring_io, true) # Note that in a load-balanced topology, every server must be a # load balancer (load_balancer: true is specified in the options) # but this option isn't set here because we are required by the # specifications to pretent the server started out as an unknown one # and publish server description change event into the load balancer # one. The actual correct description for this server will be set # by the fabricate_lb_sdam_events_and_set_server_type method. server = Server.new(address, self, @monitoring, event_listeners, opts) @update_lock.synchronize do # Need to recheck whether server is present in @servers, because # the previous check was not under a lock. # Since we are under the update lock here, we cannot call servers_list. return if @servers.map(&:address).include?(address) @servers.push(server) end if .nil? || [:monitor] != false server.start_monitoring end server end end
#addresses ⇒ Array
<Mongo::Address>
The addresses in the cluster.
# File 'lib/mongo/cluster.rb', line 453
def addresses servers_list.map(&:address) end
#close ⇒ nil
Applications should call Client#close to disconnect from
Closes the cluster.
the cluster rather than calling this method. This method is for internal driver use only.
Disconnects all servers in the cluster, publishing appropriate SDAM events in the process. Stops SRV monitoring if it is active. Marks the cluster disconnected.
A closed cluster is no longer usable. If the client is reconnected, it will create a new cluster instance.
# File 'lib/mongo/cluster.rb', line 508
def close @state_change_lock.synchronize do unless connecting? || connected? return nil end if [:cleanup] != false session_pool.end_sessions @periodic_executor.stop! end @srv_monitor_lock.synchronize do if @srv_monitor @srv_monitor.stop! end end @servers.each do |server| if server.connected? server.close publish_sdam_event( Monitoring::SERVER_CLOSED, Monitoring::Event::ServerClosed.new(server.address, topology) ) end end publish_sdam_event( Monitoring::TOPOLOGY_CLOSED, Monitoring::Event::TopologyClosed.new(topology) ) @update_lock.synchronize do @connecting = @connected = false end end nil end
#disconnect_server_if_connected(server)
# File 'lib/mongo/cluster.rb', line 953
def disconnect_server_if_connected(server) if server.connected? server.clear_description server.disconnect! publish_sdam_event( Monitoring::SERVER_CLOSED, Monitoring::Event::ServerClosed.new(server.address, topology) ) end end
#fabricate_lb_sdam_events_and_set_server_type (private)
# File 'lib/mongo/cluster.rb', line 1063
def fabricate_lb_sdam_events_and_set_server_type # Although there is no monitoring connection in load balanced mode, # we must emit the following series of SDAM events. server = @servers.first # We are guaranteed to have the server here. server.publish_opening_event server_desc = server.description # This is where a load balancer actually gets its correct server # description. server.update_description( Server::Description.new(server.address, {}, load_balancer: true, force_load_balancer: [:connect] == :load_balanced, ) ) publish_sdam_event( Monitoring::SERVER_DESCRIPTION_CHANGED, Monitoring::Event::ServerDescriptionChanged.new( server.address, topology, server_desc, server.description ) ) recreate_topology(topology, topology) end
#has_readable_server?(server_selector = nil) ⇒ true
, false
Determine if the cluster would select a readable server for the provided read preference.
# File 'lib/mongo/cluster.rb', line 757
def has_readable_server?(server_selector = nil) topology.has_readable_server?(self, server_selector) end
#heartbeat_interval ⇒ Float
Get the refresh interval for the server. This will be defined via an option or will default to 10.
# File 'lib/mongo/cluster.rb', line 405
def heartbeat_interval [:heartbeat_frequency] || Server::Monitor::DEFAULT_HEARTBEAT_INTERVAL end
#inspect ⇒ String
Get the nicer formatted string for use in inspection.
#max_read_retries ⇒ Integer
max_read_retries should be retrieved from the Client
instance, not from a Cluster
instance, because clusters may be shared between clients with different values for max read retries.
Get the maximum number of times the client can retry a read operation when using legacy read retries.
# File 'lib/mongo/cluster.rb', line 376
def max_read_retries [:max_read_retries] || MAX_READ_RETRIES end
#next_primary(ping = nil, session = nil, timeout: nil) ⇒ Mongo::Server
Get the next primary server we can send an operation to.
# File 'lib/mongo/cluster.rb', line 788
def next_primary(ping = nil, session = nil, timeout: nil) ServerSelector.primary.select_server( self, nil, session, timeout: timeout ) end
#pool(server) ⇒ Server::ConnectionPool
Get the connection pool for the server.
# File 'lib/mongo/cluster.rb', line 808
def pool(server) server.pool end
#possibly_warn_about_compatibility! (private)
Compares the server hosts with address suffixes of known services that provide limited MongoDB API compatibility, and warns about them.
# File 'lib/mongo/cluster.rb', line 1110
def possibly_warn_about_compatibility! if topology.server_hosts_match_any?(COSMOSDB_HOST_PATTERNS) log_info COSMOSDB_LOG_MESSAGE return end if topology.server_hosts_match_any?(DOCUMENTDB_HOST_PATTERNS) log_info DOCUMENTDB_LOG_MESSAGE return end end
#raise_sessions_not_supported (private)
# File 'lib/mongo/cluster.rb', line 1047
def raise_sessions_not_supported # Intentionally using @servers instead of +servers+ here because we # are supposed to be already holding the @update_lock and we cannot # recursively acquire it again. offending_servers = @servers.select do |server| server.description.data_bearing? && server.logical_session_timeout.nil? end reason = if offending_servers.empty? "There are no known data bearing servers (current seeds: #{@servers.map(&:address).map(&:seed).join(', ')})" else "The following servers have null logical session timeout: #{offending_servers.map(&:address).map(&:seed).join(', ')}" end msg = "The deployment that the driver is connected to does not support sessions: #{reason}" raise Error::SessionsNotSupported, msg end
#read_retry_interval ⇒ Float
read_retry_interval should be retrieved from the Client
instance, not from a Cluster
instance, because clusters may be shared between clients with different values for the read retry interval.
Get the interval, in seconds, in which read retries when using legacy read retries.
# File 'lib/mongo/cluster.rb', line 394
def read_retry_interval [:read_retry_interval] || READ_RETRY_INTERVAL end
#reconnect! ⇒ true
Use Client#reconnect to reconnect to the cluster instead of calling this method. This method does not send SDAM events.
Reconnect all servers.
# File 'lib/mongo/cluster.rb', line 552
def reconnect! @state_change_lock.synchronize do @update_lock.synchronize do @connecting = true end scan! servers.each do |server| server.reconnect! end @periodic_executor.restart! @srv_monitor_lock.synchronize do if @srv_monitor @srv_monitor.run! end end @update_lock.synchronize do @connecting = false @connected = true end end end
#recreate_topology(new_topology_template, previous_topology) (private)
# File 'lib/mongo/cluster.rb', line 1090
def recreate_topology(new_topology_template, previous_topology) @topology = topology.class.new(new_topology_template., new_topology_template.monitoring, self) publish_sdam_event( Monitoring::TOPOLOGY_CHANGED, Monitoring::Event::TopologyChanged.new(previous_topology, @topology) ) end
#remove(host, disconnect: true) ⇒ Array
<Server> | true
| false
The return value of this method is not part of the driver’s public API.
Remove the server from the cluster for the provided address, if it exists.
# File 'lib/mongo/cluster.rb', line 894
def remove(host, disconnect: true) address = Address.new(host) removed_servers = [] @update_lock.synchronize do @servers.delete_if do |server| (server.address == address).tap do |delete| if delete removed_servers << server end end end end if disconnect != false removed_servers.each do |server| disconnect_server_if_connected(server) end end if disconnect != false removed_servers.any? else removed_servers end end
#run_sdam_flow(previous_desc, updated_desc, options = {})
Runs SDAM flow on the cluster.
This method can be invoked to process a new server description returned by the server on a monitoring or non-monitoring connection, and also by the driver when it marks a server unknown as a result of a (network) error.
# File 'lib/mongo/cluster.rb', line 638
def run_sdam_flow(previous_desc, updated_desc, = {}) if load_balanced? if updated_desc.config.empty? unless [:keep_connection_pool] servers_list.each do |server| # TODO should service id be taken out of updated_desc? # We could also assert that # options[:service_id] == updated_desc.service_id err = [:scan_error] interrupt = err && (err.is_a?(Error::SocketError) || err.is_a?(Error::SocketTimeoutError)) server.clear_connection_pool(service_id: [:service_id], interrupt_in_use_connections: interrupt) end end end return end @sdam_flow_lock.synchronize do flow = SdamFlow.new(self, previous_desc, updated_desc, awaited: [:awaited]) flow.server_description_changed # SDAM flow may alter the updated description - grab the final # version for the purposes of broadcasting if a server is available updated_desc = flow.updated_desc unless [:keep_connection_pool] if flow.became_unknown? servers_list.each do |server| if server.address == updated_desc.address err = [:scan_error] interrupt = err && (err.is_a?(Error::SocketError) || err.is_a?(Error::SocketTimeoutError)) server.clear_connection_pool(interrupt_in_use_connections: interrupt) end end end end start_stop_srv_monitor end # Some updated descriptions, e.g. a mismatched me one, result in the # server whose description we are processing being removed from # the topology. When this happens, the server's monitoring thread gets # killed. As a result, any code after the flow invocation may not run # a particular monitor instance, hence there should generally not be # any code in this method past the flow invocation. # # However, this broadcast call can be here because if the monitoring # thread got killed the server should have been closed and no client # should be currently waiting for it, thus not signaling the semaphore # shouldn't cause any problems. unless updated_desc.unknown? server_selection_semaphore.broadcast end end
#scan!(sync = true) ⇒ true
In both synchronous and asynchronous scans, each monitor thread maintains a minimum interval between scans, meaning calling this method may not initiate a scan on a particular server the very next instant.
Force a scan of all known servers in the cluster.
If the sync parameter is true which is the default, the scan is performed synchronously in the thread which called this method. Each server in the cluster is checked sequentially. If there are many servers in the cluster or they are slow to respond, this can be a long running operation.
If the sync parameter is false, this method instructs all server monitor threads to perform an immediate scan and returns without waiting for scan results.
# File 'lib/mongo/cluster.rb', line 597
def scan!(sync=true) if sync servers_list.each do |server| if server.monitor server.monitor.scan! else log_warn("Synchronous scan requested on cluster #{summary} but server #{server} has no monitor") end end else servers_list.each do |server| server.scan_semaphore.signal end end true end
#servers ⇒ Array
<Server>
Get a list of server candidates from the cluster that can have operations executed on them.
# File 'lib/mongo/cluster.rb', line 441
def servers topology.servers(servers_list) end
#servers_list
# File 'lib/mongo/cluster.rb', line 946
def servers_list @update_lock.synchronize do @servers.dup end end
#set_server_list(server_address_strs)
Sets the list of servers to the addresses in the provided list of address strings.
This method is called by the SRV monitor after receiving new DNS records for the monitored hostname.
Removes servers in the cluster whose addresses are not in the passed list of server addresses, and adds servers for any addresses in the argument which are not already in the cluster.
# File 'lib/mongo/cluster.rb', line 709
def set_server_list(server_address_strs) @sdam_flow_lock.synchronize do # If one of the new addresses is not in the current servers list, # add it to the servers list. server_address_strs.each do |address_str| unless servers_list.any? { |server| server.address.seed == address_str } add(address_str) end end # If one of the servers' addresses are not in the new address list, # remove that server from the servers list. servers_list.each do |server| unless server_address_strs.any? { |address_str| server.address.seed == address_str } remove(server.address.seed) end end end end
#start_stop_srv_monitor (private)
# File 'lib/mongo/cluster.rb', line 1019
def start_stop_srv_monitor # SRV URI is either always given or not for a given cluster, if one # wasn't given we shouldn't ever have an SRV monitor to manage. return unless [:srv_uri] if topology.is_a?(Topology::Sharded) || topology.is_a?(Topology::Unknown) # Start SRV monitor @srv_monitor_lock.synchronize do unless @srv_monitor = Utils.shallow_symbolize_keys( .merge( timeout: [:connect_timeout] || Server::CONNECT_TIMEOUT)) @srv_monitor = _srv_monitor = Srv::Monitor.new(self, ** ) end @srv_monitor.run! end else # Stop SRV monitor if running. This path is taken when the client # is given an SRV URI to a standalone/replica set; when the topology # is discovered, since it's not a sharded cluster, the SRV monitor # needs to be stopped. @srv_monitor_lock.synchronize do if @srv_monitor @srv_monitor.stop! end end end end
#summary
This method is experimental and subject to change.
# File 'lib/mongo/cluster.rb', line 483
def summary "#<Cluster " + "topology=#{topology.summary} "+ "servers=[#{servers_list.map(&:summary).join(',')}]>" end
#update_cluster_time(result) ⇒ Object
Update the max cluster time seen in a response.
# File 'lib/mongo/cluster.rb', line 822
def update_cluster_time(result) if cluster_time_doc = result.cluster_time @cluster_time_lock.synchronize do advance_cluster_time(cluster_time_doc) end end end
#update_topology(new_topology)
# File 'lib/mongo/cluster.rb', line 919
def update_topology(new_topology) old_topology = nil @update_lock.synchronize do old_topology = topology @topology = new_topology end # If new topology has data bearing servers, we know for sure whether # sessions are supported - update our cached value. # If new topology has no data bearing servers, leave the old value # as it is and sessions_supported? method will perform server selection # to try to determine session support accurately, falling back to the # last known value. if topology.data_bearing_servers? sessions_supported = !!topology.logical_session_timeout @update_lock.synchronize do @sessions_supported = sessions_supported end end publish_sdam_event( Monitoring::TOPOLOGY_CHANGED, Monitoring::Event::TopologyChanged.new(old_topology, topology) ) end
#validate_session_support!(timeout: nil)
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.
# File 'lib/mongo/cluster.rb', line 988
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