Class: Mongo::Cluster::Topology::Base
- Inherits:
-
Object
- Object
- Mongo::Cluster::Topology::Base
- Extended by:
- Forwardable
- Includes:
- Loggable, Monitoring::Publishable
- Defined in:
- lib/mongo/cluster/topology/base.rb
Overview
Defines behavior common to all topologies.
Direct Known Subclasses
Constant Summary
Constants included from Loggable
Instance Attribute Summary collapse
-
#compatibility_error ⇒ Exception
readonly
Compatibility_error If topology is incompatible with the driver, an exception with information regarding the incompatibility.
-
#logical_session_timeout ⇒ Integer?
readonly
The logical session timeout value in minutes.
-
#monitoring ⇒ monitoring
readonly
Monitoring the monitoring.
-
#options ⇒ Hash
readonly
Options The options.
-
#server_descriptions ⇒ Hash
readonly
Server_descriptions The map of address strings to server descriptions, one for each server in the cluster.
Instance Method Summary collapse
-
#addresses ⇒ Array<String>
Addresses Server addresses.
-
#compatible? ⇒ true|false
Compatible Whether topology is compatible with the driver.
-
#data_bearing_servers? ⇒ true | false
private
Have_data_bearing_servers Whether the topology has any data bearing servers, for the purposes of logical session timeout calculation.
-
#initialize(options, monitoring, cluster) ⇒ Base
constructor
private
Initialize the topology with the options.
-
#max_election_id ⇒ BSON::ObjectId
The largest electionId ever reported by a primary.
-
#max_set_version ⇒ Integer
The largest setVersion ever reported by a primary.
- #new_max_election_id(description) ⇒ Object private
- #new_max_set_version(description) ⇒ Object private
-
#replica_set_name ⇒ String
Get the replica set name configured for this topology.
-
#server_hosts_match_any?(patterns) ⇒ true | false
private
Compares each server address against the list of patterns.
Methods included from Monitoring::Publishable
#publish_cmap_event, #publish_event, #publish_sdam_event
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger
Constructor Details
#initialize(options, monitoring, cluster) ⇒ Base
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.
Initialize the topology with the options.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mongo/cluster/topology/base.rb', line 54 def initialize(, monitoring, cluster) = (, cluster) @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 = {} cluster.servers_list.each do |server| @server_descriptions[server.address.to_s] = server.description end if is_a?(LoadBalanced) @compatible = true else begin server_descriptions.each do |_address_str, desc| desc.features.check_driver_support! unless desc.unknown? end rescue Error::UnsupportedFeatures => e @compatible = false @compatibility_error = e else @compatible = true end 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 return unless Mongo::Lint.enabled? freeze end |
Instance Attribute Details
#compatibility_error ⇒ Exception (readonly)
Returns compatibility_error If topology is incompatible with the driver, an exception with information regarding the incompatibility. If topology is compatible with the driver, nil.
148 149 150 |
# File 'lib/mongo/cluster/topology/base.rb', line 148 def compatibility_error @compatibility_error end |
#logical_session_timeout ⇒ Integer? (readonly)
The value is in minutes, unlike most other times in the driver which are returned in seconds.
The logical session timeout value in minutes.
158 159 160 |
# File 'lib/mongo/cluster/topology/base.rb', line 158 def logical_session_timeout @logical_session_timeout end |
#monitoring ⇒ monitoring (readonly)
Returns monitoring the monitoring.
115 116 117 |
# File 'lib/mongo/cluster/topology/base.rb', line 115 def monitoring @monitoring end |
#options ⇒ Hash (readonly)
Returns options The options.
102 103 104 |
# File 'lib/mongo/cluster/topology/base.rb', line 102 def @options end |
#server_descriptions ⇒ Hash (readonly)
Returns server_descriptions The map of address strings to server descriptions, one for each server in the cluster.
133 134 135 |
# File 'lib/mongo/cluster/topology/base.rb', line 133 def server_descriptions @server_descriptions end |
Instance Method Details
#addresses ⇒ Array<String>
Returns addresses Server addresses.
110 111 112 |
# File 'lib/mongo/cluster/topology/base.rb', line 110 def addresses cluster.addresses.map(&:seed) end |
#compatible? ⇒ true|false
Returns compatible Whether topology is compatible with the driver.
139 140 141 |
# File 'lib/mongo/cluster/topology/base.rb', line 139 def compatible? @compatible end |
#data_bearing_servers? ⇒ true | false
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.
Returns have_data_bearing_servers Whether the topology has any data bearing servers, for the purposes of logical session timeout calculation.
165 166 167 |
# File 'lib/mongo/cluster/topology/base.rb', line 165 def data_bearing_servers? @have_data_bearing_servers end |
#max_election_id ⇒ BSON::ObjectId
The largest electionId ever reported by a primary. May be nil.
175 176 177 |
# File 'lib/mongo/cluster/topology/base.rb', line 175 def max_election_id [:max_election_id] end |
#max_set_version ⇒ Integer
The largest setVersion ever reported by a primary. May be nil.
185 186 187 |
# File 'lib/mongo/cluster/topology/base.rb', line 185 def max_set_version [:max_set_version] end |
#new_max_election_id(description) ⇒ 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.
190 191 192 193 194 195 196 197 198 |
# File 'lib/mongo/cluster/topology/base.rb', line 190 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 |
#new_max_set_version(description) ⇒ 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.
201 202 203 204 205 206 207 208 209 |
# File 'lib/mongo/cluster/topology/base.rb', line 201 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 |
#replica_set_name ⇒ String
Get the replica set name configured for this topology.
125 126 127 |
# File 'lib/mongo/cluster/topology/base.rb', line 125 def replica_set_name [:replica_set_name] end |
#server_hosts_match_any?(patterns) ⇒ true | false
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.
Compares each server address against the list of patterns.
220 221 222 223 224 225 |
# File 'lib/mongo/cluster/topology/base.rb', line 220 def server_hosts_match_any?(patterns) server_descriptions.any? do |addr_spec, _desc| addr, _port = addr_spec.split(':') patterns.any? { |pattern| addr.end_with?(pattern) } end end |