Class: Mongo::Cluster::Topology::Sharded

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

Overview

Defines behaviour for when a cluster is in sharded topology.

Since:

  • 2.0.0

Constant Summary

NAME =

The display name for the topology.

Since:

  • 2.0.0

'Sharded'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Monitoring::Publishable

#publish_command, #publish_event, #publish_sdam_event

Constructor Details

#initialize(options, monitoring, seeds = []) ⇒ Sharded

Initialize the topology with the options.

Examples:

Initialize the topology.

Sharded.new(options)

Parameters:

  • options (Hash)

    The options.

  • monitoring (Monitoring)

    The monitoring.

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

    The seeds.

Since:

  • 2.0.0



99
100
101
102
# File 'lib/mongo/cluster/topology/sharded.rb', line 99

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

Instance Attribute Details

#monitoringMonitoring (readonly)

Returns monitoring The monitoring.

Returns:

Since:

  • 2.0.0



34
35
36
# File 'lib/mongo/cluster/topology/sharded.rb', line 34

def monitoring
  @monitoring
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.0.0



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

def options
  @options
end

Instance Method Details

#add_hosts?(description, servers) ⇒ 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:

  • (false)

    A description's hosts are never added to a sharded cluster.

Since:

  • 2.0.6



150
# File 'lib/mongo/cluster/topology/sharded.rb', line 150

def add_hosts?(description, servers); false; end

#display_nameString

Get the display name.

Examples:

Get the display name.

Sharded.display_name

Returns:

  • (String)

    The display name.

Since:

  • 2.0.0



44
45
46
# File 'lib/mongo/cluster/topology/sharded.rb', line 44

def display_name
  NAME
end

#elect_primary(description, servers) ⇒ Sharded

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



59
# File 'lib/mongo/cluster/topology/sharded.rb', line 59

def elect_primary(description, servers); self; end

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

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)

    A Sharded cluster always has a readable server.

Since:

  • 2.4.0



74
# File 'lib/mongo/cluster/topology/sharded.rb', line 74

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

#has_writable_server?(cluster) ⇒ true

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)

    A Sharded cluster always has a writable server.

Since:

  • 2.4.0



87
# File 'lib/mongo/cluster/topology/sharded.rb', line 87

def has_writable_server?(cluster); true; end

#member_discoveredObject

Notify the topology that a member was discovered.

Examples:

Notify the cluster that a member was discovered.

topology.member_discovered

Since:

  • 2.4.0



228
# File 'lib/mongo/cluster/topology/sharded.rb', line 228

def member_discovered; end

#remove_hosts?(description) ⇒ true

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

the cluster.

topology.remove_hosts?(description)

Examples:

Check if a description can be used to remove hosts from

Parameters:

Returns:

  • (true)

    A description can always be used to remove hosts from a sharded cluster.

Since:

  • 2.0.6



164
# File 'lib/mongo/cluster/topology/sharded.rb', line 164

def remove_hosts?(description); true; 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



177
178
179
180
# File 'lib/mongo/cluster/topology/sharded.rb', line 177

def remove_server?(description, server)
  remove_self?(description, server) ||
    !(server.mongos? || server.unknown?)
end

#replica_set?false

A sharded topology is not a replica set.

Examples:

Is the topology a replica set?

Sharded.replica_set?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



112
# File 'lib/mongo/cluster/topology/sharded.rb', line 112

def replica_set?; false; end

#replica_set_namenil

Sharded topologies have no replica set name.

Examples:

Get the replica set name.

sharded.replica_set_name

Returns:

  • (nil)

    Always nil.

Since:

  • 2.0.0



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

def replica_set_name; nil; end

#servers(servers) ⇒ Array<Server>

Select appropriate servers for this topology.

Examples:

Select the servers.

Sharded.servers(servers)

Parameters:

  • servers (Array<Server>)

    The known servers.

Returns:

  • (Array<Server>)

    The mongos servers.

Since:

  • 2.0.0



134
135
136
# File 'lib/mongo/cluster/topology/sharded.rb', line 134

def servers(servers)
  servers.select{ |server| server.mongos? }
end

#sharded?true

A sharded topology is sharded.

Examples:

Is the topology sharded?

Sharded.sharded?

Returns:

  • (true)

    Always true.

Since:

  • 2.0.0



190
# File 'lib/mongo/cluster/topology/sharded.rb', line 190

def sharded?; true; end

#single?false

A sharded topology is not single.

Examples:

Is the topology single?

Sharded.single?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



200
# File 'lib/mongo/cluster/topology/sharded.rb', line 200

def single?; false; end

#standalone_discoveredTopology::Sharded

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



220
# File 'lib/mongo/cluster/topology/sharded.rb', line 220

def standalone_discovered; self; end

#unknown?false

A sharded topology is not unknown.

Examples:

Is the topology unknown?

Sharded.unknown?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



210
# File 'lib/mongo/cluster/topology/sharded.rb', line 210

def unknown?; false; end