123456789_123456789_123456789_123456789_123456789_

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.

Since:

  • 2.7.0

Constant Summary

::Mongo::Loggable - Included

PREFIX

Class Method Summary

Instance Attribute Summary

::Mongo::Monitoring::Publishable - Included

Instance Method Summary

::Mongo::Monitoring::Publishable - Included

::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

Instance Attribute Details

#clusterCluster (readonly, private)

This method is for internal use only.

Returns:

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 109

attr_reader :cluster

#compatibility_errorException (readonly)

Returns:

  • (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

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 151

attr_reader :compatibility_error

#compatible?true|false (readonly)

Returns:

  • (true|false)

    compatible Whether topology is compatible with the driver.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 142

def compatible?
  @compatible
end

#data_bearing_servers?true | false (readonly)

This method is for internal use only.

Returns:

  • (true | false)

    have_data_bearing_servers Whether the topology has any data bearing servers, for the purposes of logical session timeout calculation.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 168

def data_bearing_servers?
  @have_data_bearing_servers
end

#logical_session_timeoutInteger? (readonly)

Note:

The value is in minutes, unlike most other times in the driver which are returned in seconds.

The logical session timeout value in minutes.

Returns:

  • (Integer, nil)

    The logical session timeout.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 161

attr_reader :logical_session_timeout

#monitoring ⇒ monitoring (readonly)

Returns:

  • (monitoring)

    monitoring the monitoring.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 118

attr_reader :monitoring

#optionsHash (readonly)

Returns:

  • (Hash)

    options The options.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 105

attr_reader :options

#server_descriptionsHash (readonly)

Returns:

  • (Hash)

    server_descriptions The map of address strings to server descriptions, one for each server in the cluster.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 136

attr_reader :server_descriptions

Instance Method Details

#addressesArray<String>

Returns:

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 113

def addresses
  cluster.addresses.map(&:seed)
end

#max_election_idBSON::ObjectId

The largest electionId ever reported by a primary. May be nil.

Returns:

  • (BSON::ObjectId)

    The election id.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 178

def max_election_id
  options[:max_election_id]
end

#max_set_versionInteger

The largest setVersion ever reported by a primary. May be nil.

Returns:

  • (Integer)

    The set version.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 188

def max_set_version
  options[:max_set_version]
end

#new_max_election_id(description)

This method is for internal use only.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 193

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)

This method is for internal use only.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 204

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_nameString

Get the replica set name configured for this topology.

Examples:

Get the replica set name.

topology.replica_set_name

Returns:

  • (String)

    The name of the configured replica set.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 128

def replica_set_name
  options[:replica_set_name]
end

#server_hosts_match_any?(patterns) ⇒ true | false

This method is for internal use only.

Compares each server address against the list of patterns.

Parameters:

  • patterns (Array<String>)

    the URL suffixes to compare each server against.

Returns:

  • (true | false)

    whether any of the addresses match any of the patterns or not.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 223

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.

Returns:

  • (Hash)

    New options

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/base.rb', line 235

def validate_options(options, cluster)
  options
end