class Mongo::Cluster::Topology::Base
Defines behavior common to all topologies.
@since 2.7.0
Attributes
@return [ Cluster
] The cluster. @api private
@return [ Exception ] compatibility_error
If topology is incompatible
with the driver, an exception with information regarding the incompatibility. If topology is compatible with the driver, nil.
@since 2.7.0
The logical session timeout value in minutes.
@note The value is in minutes, unlike most other times in the
driver which are returned in seconds.
@return [ Integer, nil ] The logical session timeout.
@since 2.7.0
@return [ monitoring ] monitoring the monitoring.
@return [ Hash ] options The options.
@return [ Hash ] server_descriptions
The map of address strings to
server descriptions, one for each server in the cluster.
@since 2.7.0
Public Class Methods
Initialize the topology with the options.
@param [ Hash ] options The options. @param [ Monitoring
] monitoring The monitoring. @param [ Cluster
] cluster The cluster.
@option options [ Symbol
] :replica_set Name of the replica set to
connect to. Can be left blank (either nil or the empty string are accepted) to discover the name from the cluster. If the addresses belong to different replica sets there is no guarantee which replica set is selected - in particular, the driver may choose the replica set name of a secondary if it returns its response prior to a primary belonging to a different replica set. This option can only be specified when instantiating a replica set topology.
@option options [ BSON::ObjectId ] :max_election_id Max election id
per the SDAM specification. This option can only be specified when instantiating a replica set topology.
@option options [ Integer ] :max_set_version Max set version
per the SDAM specification. This option can only be specified when instantiating a replica set topology.
@since 2.7.0 @api private
# File lib/mongo/cluster/topology/base.rb, line 53 def initialize(options, monitoring, cluster) options = validate_options(options, cluster) @options = options @monitoring = monitoring @cluster = cluster # The list of server descriptions is simply fixed at the time of # topology creation. If server description change later, a # new topology instance should be created. @server_descriptions = {} (servers = cluster.servers_list).each do |server| @server_descriptions[server.address.to_s] = server.description end begin server_descriptions.each do |address_str, desc| unless desc.unknown? desc.features.check_driver_support! end end rescue Error::UnsupportedFeatures => e @compatible = false @compatibility_error = e else @compatible = true end @have_data_bearing_servers = false @logical_session_timeout = server_descriptions.inject(nil) do |min, (address_str, desc)| # LST is only read from data-bearing servers if desc.data_bearing? @have_data_bearing_servers = true break unless timeout = desc.logical_session_timeout [timeout, (min || timeout)].min else min end end if Mongo::Lint.enabled? freeze end end
Public Instance Methods
@return [ Array<String> ] addresses Server
addresses.
# File lib/mongo/cluster/topology/base.rb, line 106 def addresses cluster.addresses.map(&:seed) end
@return [ true|false ] compatible Whether topology is compatible
with the driver.
@since 2.7.0
# File lib/mongo/cluster/topology/base.rb, line 135 def compatible? @compatible end
@return [ true | false ] have_data_bearing_servers Whether the
topology has any data bearing servers, for the purposes of logical session timeout calculation.
@api private
# File lib/mongo/cluster/topology/base.rb, line 161 def data_bearing_servers? @have_data_bearing_servers end
The largest electionId ever reported by a primary. May be nil.
@return [ BSON::ObjectId ] The election id.
@since 2.7.0
# File lib/mongo/cluster/topology/base.rb, line 171 def max_election_id options[:max_election_id] end
The largest setVersion ever reported by a primary. May be nil.
@return [ Integer ] The set version.
@since 2.7.0
# File lib/mongo/cluster/topology/base.rb, line 181 def max_set_version options[:max_set_version] end
@api private
# File lib/mongo/cluster/topology/base.rb, line 186 def new_max_election_id(description) if description.election_id && (max_election_id.nil? || description.election_id > max_election_id) description.election_id else max_election_id end end
@api private
# File lib/mongo/cluster/topology/base.rb, line 197 def new_max_set_version(description) if description.set_version && (max_set_version.nil? || description.set_version > max_set_version) description.set_version else max_set_version end end
Get the replica set name configured for this topology.
@example Get the replica set name.
topology.replica_set_name
@return [ String ] The name of the configured replica set.
@since 2.0.0
# File lib/mongo/cluster/topology/base.rb, line 121 def replica_set_name options[:replica_set_name] end
Private Instance Methods
Validates and/or transforms options as necessary for the topology.
@return [ Hash ] New options
# File lib/mongo/cluster/topology/base.rb, line 212 def validate_options(options, cluster) options end