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

Inherits:
Object
  • Object
show all
Includes:
Loggable
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 collapse

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 Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger

Constructor Details

#initialize(options, seeds = []) ⇒ Unknown

Initialize the topology with the options.

Examples:

Initialize the topology.

Unknown.new(options)

Parameters:

  • options (Hash)

    The options.

Since:

  • 2.0.0



73
74
75
76
# File 'lib/mongo/cluster/topology/unknown.rb', line 73

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

Instance Attribute Details

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.0.0



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

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



154
155
156
# File 'lib/mongo/cluster/topology/unknown.rb', line 154

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



41
42
43
# File 'lib/mongo/cluster/topology/unknown.rb', line 41

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



56
57
58
59
60
61
62
63
# File 'lib/mongo/cluster/topology/unknown.rb', line 56

def elect_primary(description, servers)
  if description.mongos?
    log_debug("Mongos #{description.address.to_s} discovered.")
    Sharded.new(options)
  else
    initialize_replica_set(description, servers)
  end
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



168
169
170
# File 'lib/mongo/cluster/topology/unknown.rb', line 168

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



183
184
185
# File 'lib/mongo/cluster/topology/unknown.rb', line 183

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



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

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



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

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



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

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



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

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



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

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



196
197
198
199
200
201
202
# File 'lib/mongo/cluster/topology/unknown.rb', line 196

def standalone_discovered
  if @seeds.size == 1
    Single.new(options, @seeds)
  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



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

def unknown?; true; end