Class: Mongo::Cluster::Topology::ReplicaSet
- Inherits:
-
Object
- Object
- Mongo::Cluster::Topology::ReplicaSet
- Includes:
- Loggable
- Defined in:
- lib/mongo/cluster/topology/replica_set.rb
Overview
Defines behaviour when a cluster is in replica set topology.
Constant Summary collapse
- REPLICA_SET_NAME =
Constant for the replica set name configuration option.
:replica_set.freeze
- NAME =
The display name for the topology.
'Replica Set'.freeze
Constants included from Loggable
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Options The options.
Instance Method Summary collapse
-
#add_hosts?(description, servers) ⇒ true, false
Whether a server description’s hosts may be added to the cluster.
-
#display_name ⇒ String
Get the display name.
-
#elect_primary(description, servers) ⇒ ReplicaSet
Elect a primary server within this topology.
-
#initialize(options, seeds = []) ⇒ ReplicaSet
constructor
Initialize the topology with the options.
-
#remove_hosts?(description) ⇒ true, false
Whether a description can be used to remove hosts from the cluster.
-
#remove_server?(description, server) ⇒ true, false
Whether a specific server in the cluster can be removed, given a description.
-
#replica_set? ⇒ true
A replica set topology is a replica set.
-
#replica_set_name ⇒ String
Get the replica set name configured for this topology.
-
#servers(servers) ⇒ Array<Server>
Select appropriate servers for this topology.
-
#sharded? ⇒ false
A replica set topology is not sharded.
-
#single? ⇒ false
A replica set topology is not single.
-
#standalone_discovered ⇒ Topology::ReplicaSet
Notify the topology that a standalone was discovered.
-
#unknown? ⇒ false
A replica set topology is not unknown.
Methods included from Loggable
#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger
Constructor Details
#initialize(options, seeds = []) ⇒ ReplicaSet
Initialize the topology with the options.
90 91 92 93 94 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 90 def initialize(, seeds = []) @options = @max_election_id = nil @max_set_version = nil end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns options The options.
31 32 33 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 31 def @options end |
Instance Method Details
#add_hosts?(description, servers) ⇒ true, false
Whether a server description’s hosts may be added to the cluster.
146 147 148 149 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 146 def add_hosts?(description, servers) !!(member_of_this_set?(description) && (!has_primary?(servers) || description.primary?)) end |
#display_name ⇒ String
Get the display name.
46 47 48 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 46 def display_name NAME end |
#elect_primary(description, servers) ⇒ ReplicaSet
Elect a primary server within this topology.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 61 def elect_primary(description, servers) if description.replica_set_name == replica_set_name unless detect_stale_primary!(description) log_debug("Server #{description.address.to_s} elected as primary in #{replica_set_name}.") servers.each do |server| if server.primary? && server.address != description.address server.description.unknown! end end update_max_election_id(description) update_max_set_version(description) end else log_warn( "Server #{description.address.to_s} has incorrect replica set name: " + "'#{description.replica_set_name}'. The current replica set name is '#{replica_set_name}'." ) end self end |
#remove_hosts?(description) ⇒ true, false
Whether a description can be used to remove hosts from the cluster.
161 162 163 164 165 166 167 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 161 def remove_hosts?(description) !description.config.empty? && (description.primary? || description.me_mismatch? || description.hosts.empty? || !member_of_this_set?(description)) end |
#remove_server?(description, server) ⇒ true, false
Whether a specific server in the cluster can be removed, given a description.
180 181 182 183 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 180 def remove_server?(description, server) remove_self?(description, server) || (member_of_this_set?(description) && !description.lists_server?(server)) end |
#replica_set? ⇒ true
A replica set topology is a replica set.
104 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 104 def replica_set?; true; end |
#replica_set_name ⇒ String
Get the replica set name configured for this topology.
114 115 116 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 114 def replica_set_name @replica_set_name ||= [REPLICA_SET_NAME] end |
#servers(servers) ⇒ Array<Server>
Select appropriate servers for this topology.
128 129 130 131 132 133 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 128 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.
193 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 193 def sharded?; false; end |
#single? ⇒ false
A replica set topology is not single.
203 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 203 def single?; false; end |
#standalone_discovered ⇒ Topology::ReplicaSet
Notify the topology that a standalone was discovered.
223 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 223 def standalone_discovered; self; end |
#unknown? ⇒ false
A replica set topology is not unknown.
213 |
# File 'lib/mongo/cluster/topology/replica_set.rb', line 213 def unknown?; false; end |