123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Cluster::Topology::ReplicaSetNoPrimary

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base, Forwardable
Instance Chain:
Inherits: Mongo::Cluster::Topology::Base
Defined in: lib/mongo/cluster/topology/replica_set_no_primary.rb

Overview

Defines behavior when a cluster is in replica set topology, and there is no primary or the primary has not yet been discovered by the driver.

Since:

  • 2.0.0

Constant Summary

::Mongo::Loggable - Included

PREFIX

Class Method Summary

Base - Inherited

.new

Initialize the topology with the options.

Instance Attribute Summary

Base - Inherited

::Mongo::Monitoring::Publishable - Included

Instance Method Summary

Base - Inherited

#addresses,
#max_election_id

The largest electionId ever reported by a primary.

#max_set_version

The largest setVersion ever reported by a primary.

#new_max_election_id, #new_max_set_version,
#replica_set_name

Get the replica set name configured for this topology.

#server_hosts_match_any?

Compares each server address against the list of patterns.

#validate_options

Validates and/or transforms options as necessary for the topology.

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

#replica_set?true (readonly)

A replica set topology is a replica set.

Examples:

Is the topology a replica set?

topology.replica_set?

Returns:

  • (true)

    Always true.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 107

def replica_set?; true; end

#sharded?false (readonly)

A replica set topology is not sharded.

Examples:

Is the topology sharded?

ReplicaSet.sharded?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 134

def sharded?; false; end

#single?false (readonly)

A replica set topology is not single.

Examples:

Is the topology single?

ReplicaSet.single?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 144

def single?; false; end

#unknown?false (readonly)

A replica set topology is not unknown.

Examples:

Is the topology unknown?

ReplicaSet.unknown?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 154

def unknown?; false; end

Instance Method Details

#display_nameString

Get the display name.

Examples:

Get the display name.

ReplicaSet.display_name

Returns:

  • (String)

    The display name.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 43

def display_name
  self.class.name.gsub(/.*::/, '')
end

#has_readable_server?(cluster, server_selector = nil) ⇒ true, false

Deprecated.

Determine if the topology would select a readable server for the provided candidates and read preference.

Examples:

Is a readable server present?

topology.has_readable_server?(cluster, server_selector)

Parameters:

  • cluster (Cluster)

    The cluster.

  • server_selector (ServerSelector) (defaults to: nil)

    The server selector.

Returns:

  • (true, false)

    If a readable server is present.

Since:

  • 2.4.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 80

def has_readable_server?(cluster, server_selector = nil)
  !(server_selector || ServerSelector.primary).try_select_server(cluster).nil?
end

#has_writable_server?(cluster) ⇒ true, false

Determine if the topology would select a writable server for the provided candidates.

Examples:

Is a writable server present?

topology.has_writable_server?(servers)

Parameters:

  • cluster (Cluster)

    The cluster.

Returns:

  • (true, false)

    If a writable server is present.

Since:

  • 2.4.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 95

def has_writable_server?(cluster)
  !ServerSelector.primary.try_select_server(cluster).nil?
end

#servers(servers) ⇒ Array<Server>

Select appropriate servers for this topology.

Examples:

Select the servers.

ReplicaSet.servers(servers)

Parameters:

  • servers (Array<Server>)

    The known servers.

Returns:

  • (Array<Server>)

    The servers in the replica set.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 119

def servers(servers)
  servers.select do |server|
    (replica_set_name.nil? || server.replica_set_name == replica_set_name) &&
      server.primary? || server.secondary?
  end
end

#summary

Note:

This method is experimental and subject to change.

Since:

  • 2.7.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 51

def summary
  details = server_descriptions.keys.join(',')
  if details != ''
    details << ','
  end
  details << "name=#{replica_set_name}"
  if max_set_version
    details << ",v=#{max_set_version}"
  end
  if max_election_id
    details << ",e=#{max_election_id && max_election_id.to_s.sub(/^0+/, '')}"
  end
  "#{display_name}[#{details}]"
end

#validate_options(options, cluster) (private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 158

def validate_options(options, cluster)
  if options[:replica_set_name] == ''
    options = options.merge(replica_set_name: nil)
  end

  unless options[:replica_set_name]
    raise ArgumentError, 'Cannot instantiate a replica set topology without a replica set name'
  end

  super(options, cluster)
end