Class: Mongo::Cluster::Topology::Unknown

Inherits:
Object
  • Object
show all
Includes:
Loggable, Monitoring::Publishable
Defined in:
lib/mongo/cluster/topology/unknown.rb

Overview

Defines behaviour for when a cluster is in an unknown state.

Since:

  • 2.0.0

Constant Summary

NAME =

The display name for the topology.

Since:

  • 2.0.0

'Unknown'.freeze

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Monitoring::Publishable

#publish_command, #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, seeds = []) ⇒ Unknown

Initialize the topology with the options.

Examples:

Initialize the topology.

Unknown.new(options)

Parameters:

  • options (Hash)

    The options.

  • monitoring (Monitoring)

    The monitoring.

  • seeds (Array<String>) (defaults to: [])

    The seeds.

Since:

  • 2.0.0



108
109
110
111
112
# File 'lib/mongo/cluster/topology/unknown.rb', line 108

def initialize(options, monitoring, seeds = [])
  @options = options
  @monitoring = monitoring
  @seeds = seeds
end

Instance Attribute Details

#monitoringMonitoring (readonly)

Returns monitoring The monitoring.

Returns:

Since:

  • 2.0.0



35
36
37
# File 'lib/mongo/cluster/topology/unknown.rb', line 35

def monitoring
  @monitoring
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.0.0



32
33
34
# File 'lib/mongo/cluster/topology/unknown.rb', line 32

def options
  @options
end

Instance Method Details

#add_hosts?(description, servers) ⇒ true, false

Whether a server description's hosts may be added to the cluster.

Examples:

Check if a description's hosts may be added to the cluster.

topology.add_hosts?(description, servers)

Parameters:

Returns:

  • (true, false)

    Whether a description's hosts may be added.

Since:

  • 2.0.6



190
191
192
# File 'lib/mongo/cluster/topology/unknown.rb', line 190

def add_hosts?(description, servers)
  !(description.unknown? || description.ghost?)
end

#display_nameString

Get the display name.

Examples:

Get the display name.

Unknown.display_name

Returns:

  • (String)

    The display name.

Since:

  • 2.0.0



45
46
47
# File 'lib/mongo/cluster/topology/unknown.rb', line 45

def display_name
  NAME
end

#elect_primary(description, servers) ⇒ Sharded, ReplicaSet

Elect a primary server within this topology.

Examples:

Elect a primary server.

topology.elect_primary(description, servers)

Parameters:

  • description (Server::Description)

    The description of the elected primary.

  • servers (Array<Server>)

    The list of known servers to the cluster.

Returns:

Since:

  • 2.0.0



60
61
62
63
64
65
66
67
68
# File 'lib/mongo/cluster/topology/unknown.rb', line 60

def elect_primary(description, servers)
  if description.mongos?
    sharded = Sharded.new(options, monitoring)
    topology_changed(sharded)
    sharded
  else
    initialize_replica_set(description, servers)
  end
end

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

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:

  • (false)

    An Unknown topology will never have a readable server.

Since:

  • 2.4.0



83
# File 'lib/mongo/cluster/topology/unknown.rb', line 83

def has_readable_server?(cluster, server_selector = nil); false; end

#has_writable_server?(cluster) ⇒ 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:

  • (false)

    An Unknown topology will never have a writable server.

Since:

  • 2.4.0



96
# File 'lib/mongo/cluster/topology/unknown.rb', line 96

def has_writable_server?(cluster); false; end

#member_discoveredObject

Notify the topology that a member was discovered.

Examples:

Notify the topology that a member was discovered.

topology.member_discovered

Since:

  • 2.4.0



248
249
250
251
252
253
# File 'lib/mongo/cluster/topology/unknown.rb', line 248

def member_discovered
  publish_sdam_event(
    Monitoring::TOPOLOGY_CHANGED,
    Monitoring::Event::TopologyChanged.new(self, self)
  )
end

#remove_hosts?(description) ⇒ true, false

Whether a description can be used to remove hosts from the cluster.

Examples:

Check if a description can be used to remove hosts from the cluster.

topology.remove_hosts?(description)

Parameters:

Returns:

  • (true, false)

    Whether hosts may be removed from the cluster.

Since:

  • 2.0.6



204
205
206
# File 'lib/mongo/cluster/topology/unknown.rb', line 204

def remove_hosts?(description)
  description.standalone?
end

#remove_server?(description, server) ⇒ true, false

Whether a specific server in the cluster can be removed, given a description.

Examples:

Check if a specific server can be removed from the cluster.

topology.remove_server?(description, server)

Parameters:

Returns:

  • (true, false)

    Whether the server can be removed from the cluster.

Since:

  • 2.0.6



219
220
221
# File 'lib/mongo/cluster/topology/unknown.rb', line 219

def remove_server?(description, server)
  description.standalone? && description.is_server?(server)
end

#replica_set?false

An unknown topology is not a replica set.

Examples:

Is the topology a replica set?

Unknown.replica_set?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



122
# File 'lib/mongo/cluster/topology/unknown.rb', line 122

def replica_set?; false; end

#replica_set_namenil

Unknown topologies have no replica set name.

Examples:

Get the replica set name.

unknown.replica_set_name

Returns:

  • (nil)

    Always nil.

Since:

  • 2.0.0



132
# File 'lib/mongo/cluster/topology/unknown.rb', line 132

def replica_set_name; nil; end

#servers(servers) ⇒ Object

Select appropriate servers for this topology.

Examples:

Select the servers.

Unknown.servers(servers)

Parameters:

  • servers (Array<Server>)

    The known servers.

Raises:

  • (Unknown)

    Cannot select servers when the topology is unknown.

Since:

  • 2.0.0



145
146
147
# File 'lib/mongo/cluster/topology/unknown.rb', line 145

def servers(servers)
  []
end

#sharded?false

An unknown topology is not sharded.

Examples:

Is the topology sharded?

Unknown.sharded?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



157
# File 'lib/mongo/cluster/topology/unknown.rb', line 157

def sharded?; false; end

#single?true

An unknown topology is not single.

Examples:

Is the topology single?

Unknown.single?

Returns:

  • (true)

    Always false.

Since:

  • 2.0.0



167
# File 'lib/mongo/cluster/topology/unknown.rb', line 167

def single?; false; end

#standalone_discoveredTopology::Unknown, Topology::Single

Notify the topology that a standalone was discovered.

Examples:

Notify the topology that a standalone was discovered.

topology.standalone_discovered

Returns:

Since:

  • 2.0.6



232
233
234
235
236
237
238
239
240
# File 'lib/mongo/cluster/topology/unknown.rb', line 232

def standalone_discovered
  if @seeds.size == 1
    single = Single.new(options, monitoring, @seeds)
    topology_changed(single)
    single
  else
    self
  end
end

#unknown?true

An unknown topology is unknown.

Examples:

Is the topology unknown?

Unknown.unknown?

Returns:

  • (true)

    Always true.

Since:

  • 2.0.0



177
# File 'lib/mongo/cluster/topology/unknown.rb', line 177

def unknown?; true; end