Class: Mongo::Cluster::Topology::Base
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Forwardable
|
|
|
Instance Chain:
|
|
| Inherits: | Object |
| Defined in: | lib/mongo/cluster/topology/base.rb |
Overview
Defines behavior common to all topologies.
Constant Summary
::Mongo::Loggable - Included
Class Method Summary
-
.new(options, monitoring, cluster) ⇒ Base
constructor
Internal use only
Initialize the topology with the options.
Instance Attribute Summary
- #compatibility_error ⇒ Exception readonly
- #compatible? ⇒ true|false readonly
- #data_bearing_servers? ⇒ true | false readonly Internal use only
-
#logical_session_timeout ⇒ Integer?
readonly
The logical session timeout value in minutes.
- #monitoring ⇒ monitoring readonly
- #options ⇒ Hash readonly
- #server_descriptions ⇒ Hash readonly
- #cluster ⇒ Cluster readonly private Internal use only
::Mongo::Monitoring::Publishable - Included
Instance Method Summary
- #addresses ⇒ Array<String>
-
#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) Internal use only
- #new_max_set_version(description) Internal use only
-
#replica_set_name ⇒ String
Get the replica set name configured for this topology.
-
#server_hosts_match_any?(patterns) ⇒ true | false
Internal use only
Compares each server address against the list of patterns.
-
#validate_options(options, _cluster) ⇒ Hash
private
Validates and/or transforms options as necessary for the topology.
::Mongo::Monitoring::Publishable - Included
| #publish_cmap_event, #publish_event, #publish_sdam_event, #command_completed, #command_failed, #command_started, #command_succeeded, #duration |
::Mongo::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 | |
Constructor Details
.new(options, monitoring, cluster) ⇒ Base
Initialize the topology with the options.
# 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
#cluster ⇒ Cluster (readonly, private)
# File 'lib/mongo/cluster/topology/base.rb', line 106
attr_reader :cluster
#compatibility_error ⇒ Exception (readonly)
# File 'lib/mongo/cluster/topology/base.rb', line 148
attr_reader :compatibility_error
#compatible? ⇒ true|false (readonly)
# File 'lib/mongo/cluster/topology/base.rb', line 139
def compatible? @compatible end
#data_bearing_servers? ⇒ true | false (readonly)
# File 'lib/mongo/cluster/topology/base.rb', line 165
def data_bearing_servers? @have_data_bearing_servers 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.
# File 'lib/mongo/cluster/topology/base.rb', line 158
attr_reader :logical_session_timeout
#monitoring ⇒ monitoring (readonly)
# File 'lib/mongo/cluster/topology/base.rb', line 115
attr_reader :monitoring
#options ⇒ Hash (readonly)
# File 'lib/mongo/cluster/topology/base.rb', line 102
attr_reader :
#server_descriptions ⇒ Hash (readonly)
# File 'lib/mongo/cluster/topology/base.rb', line 133
attr_reader :server_descriptions
Instance Method Details
#addresses ⇒ Array<String>
# File 'lib/mongo/cluster/topology/base.rb', line 110
def addresses cluster.addresses.map(&:seed) end
#max_election_id ⇒ BSON::ObjectId
The largest electionId ever reported by a primary. May be nil.
# 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.
# File 'lib/mongo/cluster/topology/base.rb', line 185
def max_set_version [:max_set_version] end
#new_max_election_id(description)
# 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)
# 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.
# File 'lib/mongo/cluster/topology/base.rb', line 125
def replica_set_name [:replica_set_name] end
#server_hosts_match_any?(patterns) ⇒ true | false
Compares each server address against the list of patterns.
# 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
#validate_options(options, _cluster) ⇒ Hash (private)
Validates and/or transforms options as necessary for the topology.
# File 'lib/mongo/cluster/topology/base.rb', line 232
def (, _cluster) end