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

Inherits:
Base
  • Object
show all
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

Direct Known Subclasses

ReplicaSetWithPrimary

Constant Summary collapse

NAME =
Deprecated.

The display name for the topology.

Since:

  • 2.0.0

'Replica Set'

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary

Attributes inherited from Base

#compatibility_error, #logical_session_timeout, #monitoring, #options, #server_descriptions

Attributes included from Monitoring::Publishable

#monitoring

Instance Method Summary collapse

Methods inherited from Base

#addresses, #compatible?, #data_bearing_servers?, #initialize, #max_election_id, #max_set_version, #new_max_election_id, #new_max_set_version, #replica_set_name, #server_hosts_match_any?

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

This class inherits a constructor from Mongo::Cluster::Topology::Base

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



40
41
42
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 40

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



71
72
73
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 71

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



86
87
88
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 86

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

#replica_set?true

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



98
99
100
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 98

def replica_set?
  true
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



112
113
114
115
116
117
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 112

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

#sharded?false

A replica set topology is not sharded.

Examples:

Is the topology sharded?

ReplicaSet.sharded?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



127
128
129
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 127

def sharded?
  false
end

#single?false

A replica set topology is not single.

Examples:

Is the topology single?

ReplicaSet.single?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



139
140
141
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 139

def single?
  false
end

#summaryObject

Note:

This method is experimental and subject to change.

Since:

  • 2.7.0



48
49
50
51
52
53
54
55
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 48

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

#unknown?false

A replica set topology is not unknown.

Examples:

Is the topology unknown?

ReplicaSet.unknown?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



151
152
153
# File 'lib/mongo/cluster/topology/replica_set_no_primary.rb', line 151

def unknown?
  false
end