Class: Mongo::Server::Description
- Inherits:
-
Object
- Object
- Mongo::Server::Description
- Defined in:
- lib/mongo/server/description.rb,
lib/mongo/server/description/features.rb,
lib/mongo/server/description/inspector.rb,
lib/mongo/server/description/inspector/primary_elected.rb,
lib/mongo/server/description/inspector/member_discovered.rb,
lib/mongo/server/description/inspector/description_changed.rb,
lib/mongo/server/description/inspector/standalone_discovered.rb
Overview
Represents a description of the server, populated by the result of the ismaster command.
Defined Under Namespace
Constant Summary collapse
- ARBITER =
Constant for reading arbiter info from config.
'arbiterOnly'.freeze
- ARBITERS =
Constant for reading arbiters info from config.
'arbiters'.freeze
- HIDDEN =
Constant for reading hidden info from config.
'hidden'.freeze
- HOSTS =
Constant for reading hosts info from config.
'hosts'.freeze
- MESSAGE =
Constant for the key for the message value.
'msg'.freeze
- MONGOS_MESSAGE =
Constant for the message that indicates a sharded cluster.
'isdbgrid'.freeze
- REPLICA_SET =
Constant for determining ghost servers.
'isreplicaset'.freeze
- MAX_BSON_OBJECT_SIZE =
Constant for reading max bson size info from config.
'maxBsonObjectSize'.freeze
- MAX_MESSAGE_BYTES =
Constant for reading max message size info from config.
'maxMessageSizeBytes'.freeze
- MAX_WIRE_VERSION =
Constant for the max wire version.
'maxWireVersion'.freeze
- MIN_WIRE_VERSION =
Constant for min wire version.
'minWireVersion'.freeze
- MAX_WRITE_BATCH_SIZE =
Constant for reading max write batch size.
'maxWriteBatchSize'.freeze
- LAST_WRITE =
Constant for the lastWrite subdocument.
'lastWrite'.freeze
- LAST_WRITE_DATE =
Constant for the lastWriteDate field in the lastWrite subdocument.
'lastWriteDate'.freeze
- ME =
Constant for reading the me field.
'me'.freeze
- DEFAULT_MAX_WRITE_BATCH_SIZE =
Default max write batch size.
1000.freeze
- LEGACY_WIRE_VERSION =
The legacy wire protocol version.
0.freeze
- PASSIVE =
Constant for reading passive info from config.
'passive'.freeze
- PASSIVES =
Constant for reading the passive server list.
'passives'.freeze
- PRIMARY =
Constant for reading primary info from config.
'ismaster'.freeze
- SECONDARY =
Constant for reading secondary info from config.
'secondary'.freeze
- SET_NAME =
Constant for reading replica set name info from config.
'setName'.freeze
- TAGS =
Constant for reading tags info from config.
'tags'.freeze
- ELECTION_ID =
Constant for reading electionId info from config.
'electionId'.freeze
- SET_VERSION =
Constant for reading setVersion info from config.
'setVersion'.freeze
- LOCAL_TIME =
Constant for reading localTime info from config.
'localTime'.freeze
- EXCLUDE_FOR_COMPARISON =
Fields to exclude when comparing two descriptions.
[ LOCAL_TIME ].freeze
Instance Attribute Summary collapse
-
#address ⇒ Address
readonly
Address The server’s address.
-
#average_round_trip_time ⇒ Float
readonly
The moving average time the ismaster call took to complete.
-
#config ⇒ Hash
readonly
The actual result from the ismaster command.
-
#features ⇒ Features
readonly
Features The features for the server.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Check equality of two descriptions.
-
#arbiter? ⇒ true, false
Will return true if the server is an arbiter.
-
#arbiters ⇒ Array<String>
Get a list of all arbiters in the replica set.
-
#election_id ⇒ BSON::ObjectId
Get the electionId from the config.
-
#ghost? ⇒ true, false
Is the server a ghost in a replica set?.
-
#hidden? ⇒ true, false
Will return true if the server is hidden.
-
#hosts ⇒ Array<String>
Get a list of all servers in the replica set.
-
#initialize(address, config = {}, average_round_trip_time = 0) ⇒ Description
constructor
Instantiate the new server description from the result of the ismaster command.
-
#inspect ⇒ String
Inspect the server description.
-
#is_server?(server) ⇒ true, false
Is this description from the given server.
-
#last_write_date ⇒ Time
Get the lastWriteDate from the lastWrite subdocument in the config.
-
#lists_server?(server) ⇒ true, false
Is a server included in this description’s list of servers.
-
#max_bson_object_size ⇒ Integer
Get the max BSON object size for this server version.
-
#max_message_size ⇒ Integer
Get the max message size for this server version.
-
#max_wire_version ⇒ Integer
Get the maximum wire version.
-
#max_write_batch_size ⇒ Integer
Get the maximum batch size for writes.
-
#me ⇒ String
Get the me field value.
-
#me_mismatch? ⇒ true, false
Check if there is a mismatch between the address host and the me field.
-
#min_wire_version ⇒ Integer
Get the minimum wire version.
-
#mongos? ⇒ true, false
Is the server a mongos?.
-
#other? ⇒ true, false
Is the description of type other.
-
#passive? ⇒ true, false
Will return true if the server is passive.
-
#passives ⇒ Array<String>
Get a list of the passive servers in the cluster.
-
#primary? ⇒ true, false
Will return true if the server is a primary.
-
#replica_set_member? ⇒ true, false
Does this description correspond to a replica set member.
-
#replica_set_name ⇒ String?
Get the name of the replica set the server belongs to, returns nil if none.
-
#secondary? ⇒ true, false
Will return true if the server is a secondary.
-
#server_type ⇒ Symbol
Returns the server type as a symbol.
-
#servers ⇒ Array<String>
Get a list of all servers known to the cluster.
-
#set_version ⇒ Integer
Get the setVersion from the config.
-
#standalone? ⇒ true, false
Is this server a standalone server?.
-
#tags ⇒ Hash
Get the tags configured for the server.
-
#unknown! ⇒ true
A result from another server’s ismaster command before this server has refreshed causes the need for this description to become unknown before the next refresh.
-
#unknown? ⇒ true, false
Is the server description currently unknown?.
-
#wire_versions ⇒ Range
Get the range of supported wire versions for the server.
Constructor Details
#initialize(address, config = {}, average_round_trip_time = 0) ⇒ Description
Instantiate the new server description from the result of the ismaster command.
246 247 248 249 250 251 |
# File 'lib/mongo/server/description.rb', line 246 def initialize(address, config = {}, average_round_trip_time = 0) @address = address @config = config @features = Features.new(wire_versions) @average_round_trip_time = average_round_trip_time end |
Instance Attribute Details
#address ⇒ Address (readonly)
Returns address The server’s address.
163 164 165 |
# File 'lib/mongo/server/description.rb', line 163 def address @address end |
#average_round_trip_time ⇒ Float (readonly)
Returns The moving average time the ismaster call took to complete.
172 173 174 |
# File 'lib/mongo/server/description.rb', line 172 def average_round_trip_time @average_round_trip_time end |
#config ⇒ Hash (readonly)
Returns The actual result from the ismaster command.
166 167 168 |
# File 'lib/mongo/server/description.rb', line 166 def config @config end |
#features ⇒ Features (readonly)
Returns features The features for the server.
169 170 171 |
# File 'lib/mongo/server/description.rb', line 169 def features @features end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Check equality of two descriptions.
612 613 614 615 616 |
# File 'lib/mongo/server/description.rb', line 612 def ==(other) return false if self.class != other.class return false if unknown? || other.unknown? compare_config(other) end |
#arbiter? ⇒ true, false
Will return true if the server is an arbiter.
182 183 184 |
# File 'lib/mongo/server/description.rb', line 182 def arbiter? !!config[ARBITER] && !replica_set_name.nil? end |
#arbiters ⇒ Array<String>
Get a list of all arbiters in the replica set.
194 195 196 |
# File 'lib/mongo/server/description.rb', line 194 def arbiters @arbiters ||= (config[ARBITERS] || []).map { |s| s.downcase } end |
#election_id ⇒ BSON::ObjectId
Get the electionId from the config.
357 358 359 |
# File 'lib/mongo/server/description.rb', line 357 def election_id config[ELECTION_ID] end |
#ghost? ⇒ true, false
Is the server a ghost in a replica set?
206 207 208 |
# File 'lib/mongo/server/description.rb', line 206 def ghost? !!config[REPLICA_SET] end |
#hidden? ⇒ true, false
Will return true if the server is hidden.
218 219 220 |
# File 'lib/mongo/server/description.rb', line 218 def hidden? !!config[HIDDEN] end |
#hosts ⇒ Array<String>
Get a list of all servers in the replica set.
230 231 232 |
# File 'lib/mongo/server/description.rb', line 230 def hosts @hosts ||= (config[HOSTS] || []).map { |s| s.downcase } end |
#inspect ⇒ String
Inspect the server description.
261 262 263 |
# File 'lib/mongo/server/description.rb', line 261 def inspect "#<Mongo::Server:Description:0x#{object_id} config=#{config} average_round_trip_time=#{average_round_trip_time}>" end |
#is_server?(server) ⇒ true, false
Is this description from the given server.
560 561 562 |
# File 'lib/mongo/server/description.rb', line 560 def is_server?(server) address == server.address end |
#last_write_date ⇒ Time
Get the lastWriteDate from the lastWrite subdocument in the config.
381 382 383 |
# File 'lib/mongo/server/description.rb', line 381 def last_write_date config[LAST_WRITE][LAST_WRITE_DATE] if config[LAST_WRITE] end |
#lists_server?(server) ⇒ true, false
Is a server included in this description’s list of servers.
573 574 575 |
# File 'lib/mongo/server/description.rb', line 573 def lists_server?(server) servers.include?(server.address.to_s) end |
#max_bson_object_size ⇒ Integer
Get the max BSON object size for this server version.
273 274 275 |
# File 'lib/mongo/server/description.rb', line 273 def max_bson_object_size config[MAX_BSON_OBJECT_SIZE] end |
#max_message_size ⇒ Integer
Get the max message size for this server version.
285 286 287 |
# File 'lib/mongo/server/description.rb', line 285 def config[MAX_MESSAGE_BYTES] end |
#max_wire_version ⇒ Integer
Get the maximum wire version.
309 310 311 |
# File 'lib/mongo/server/description.rb', line 309 def max_wire_version config[MAX_WIRE_VERSION] || LEGACY_WIRE_VERSION end |
#max_write_batch_size ⇒ Integer
Get the maximum batch size for writes.
297 298 299 |
# File 'lib/mongo/server/description.rb', line 297 def max_write_batch_size config[MAX_WRITE_BATCH_SIZE] || DEFAULT_MAX_WRITE_BATCH_SIZE end |
#me ⇒ String
Get the me field value.
333 334 335 |
# File 'lib/mongo/server/description.rb', line 333 def me config[ME] end |
#me_mismatch? ⇒ true, false
Check if there is a mismatch between the address host and the me field.
598 599 600 |
# File 'lib/mongo/server/description.rb', line 598 def me_mismatch? !!(address.to_s != me if me) end |
#min_wire_version ⇒ Integer
Get the minimum wire version.
321 322 323 |
# File 'lib/mongo/server/description.rb', line 321 def min_wire_version config[MIN_WIRE_VERSION] || LEGACY_WIRE_VERSION end |
#mongos? ⇒ true, false
Is the server a mongos?
393 394 395 |
# File 'lib/mongo/server/description.rb', line 393 def mongos? config[MESSAGE] == MONGOS_MESSAGE end |
#other? ⇒ true, false
Is the description of type other.
405 406 407 408 |
# File 'lib/mongo/server/description.rb', line 405 def other? (!primary? && !secondary? && !passive? && !arbiter?) || (hidden? && !replica_set_name.nil?) end |
#passive? ⇒ true, false
Will return true if the server is passive.
418 419 420 |
# File 'lib/mongo/server/description.rb', line 418 def passive? !!config[PASSIVE] end |
#passives ⇒ Array<String>
Get a list of the passive servers in the cluster.
430 431 432 |
# File 'lib/mongo/server/description.rb', line 430 def passives @passives ||= (config[PASSIVES] || []).map { |s| s.downcase } end |
#primary? ⇒ true, false
Will return true if the server is a primary.
442 443 444 |
# File 'lib/mongo/server/description.rb', line 442 def primary? !!config[PRIMARY] && !replica_set_name.nil? end |
#replica_set_member? ⇒ true, false
Does this description correspond to a replica set member.
586 587 588 |
# File 'lib/mongo/server/description.rb', line 586 def replica_set_member? !(standalone? || mongos?) end |
#replica_set_name ⇒ String?
Get the name of the replica set the server belongs to, returns nil if none.
455 456 457 |
# File 'lib/mongo/server/description.rb', line 455 def replica_set_name config[SET_NAME] end |
#secondary? ⇒ true, false
Will return true if the server is a secondary.
479 480 481 |
# File 'lib/mongo/server/description.rb', line 479 def secondary? !!config[SECONDARY] && !replica_set_name.nil? end |
#server_type ⇒ Symbol
Returns the server type as a symbol.
491 492 493 494 495 496 497 498 499 |
# File 'lib/mongo/server/description.rb', line 491 def server_type return :arbiter if arbiter? return :ghost if ghost? return :sharded if mongos? return :primary if primary? return :secondary if secondary? return :standalone if standalone? :unknown end |
#servers ⇒ Array<String>
Get a list of all servers known to the cluster.
467 468 469 |
# File 'lib/mongo/server/description.rb', line 467 def servers hosts + arbiters + passives end |
#set_version ⇒ Integer
Get the setVersion from the config.
369 370 371 |
# File 'lib/mongo/server/description.rb', line 369 def set_version config[SET_VERSION] end |
#standalone? ⇒ true, false
Is this server a standalone server?
509 510 511 |
# File 'lib/mongo/server/description.rb', line 509 def standalone? replica_set_name.nil? && !mongos? && !ghost? && !unknown? end |
#tags ⇒ Hash
Get the tags configured for the server.
345 346 347 |
# File 'lib/mongo/server/description.rb', line 345 def config[TAGS] || {} end |
#unknown! ⇒ true
A result from another server’s ismaster command before this server has refreshed causes the need for this description to become unknown before the next refresh.
536 537 538 |
# File 'lib/mongo/server/description.rb', line 536 def unknown! @config = {} and true end |
#unknown? ⇒ true, false
Is the server description currently unknown?
521 522 523 524 |
# File 'lib/mongo/server/description.rb', line 521 def unknown? config.empty? || (config[Operation::Result::OK] && config[Operation::Result::OK] != 1) end |
#wire_versions ⇒ Range
Get the range of supported wire versions for the server.
548 549 550 |
# File 'lib/mongo/server/description.rb', line 548 def wire_versions min_wire_version..max_wire_version end |