#primary? ⇒ true, false (readonly)
Returns whether this server is a primary, per the SDAM spec.
123456789_123456789_123456789_123456789_123456789_
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Inherits: | Object |
| Defined in: | lib/mongo/server/description.rb, lib/mongo/server/description/features.rb, lib/mongo/server/description/load_balancer.rb |
Represents a description of the server, populated by the result of the hello command.
Note: Unknown servers do not have wire versions, but for legacy reasons we return 0 for min_wire_version and max_wire_version of any server that does not have them. Presently the driver sometimes constructs commands when the server is unknown, so references to min_wire_version and max_wire_version should not be nil. When driver behavior is changed (jira.mongodb.org/browse/RUBY-1805), this may no longer be necessary.
Constant for reading arbiter info from config.
'arbiterOnly'
Constant for reading arbiters info from config.
'arbiters'
Constant for reading connectionId info from config.
'connectionId'
Default max write batch size.
1000
Constant for reading electionId info from config.
'electionId'
Fields to exclude when comparing two descriptions.
[ LOCAL_TIME, LAST_WRITE, OPERATION_TIME, Operation::CLUSTER_TIME, CONNECTION_ID, ].freeze
Constant for reading hidden info from config.
'hidden'
Constant for reading hosts info from config.
'hosts'
Constant for the lastWrite subdocument.
'lastWrite'
Constant for the lastWriteDate field in the lastWrite subdocument.
'lastWriteDate'
Will be removed in 3.0.
The legacy wire protocol version.
0
Constant for reading localTime info from config.
'localTime'
Constant for reading logicalSessionTimeoutMinutes info from config.
'logicalSessionTimeoutMinutes'
Constant for reading max bson size info from config.
'maxBsonObjectSize'
Constant for reading max message size info from config.
'maxMessageSizeBytes'
Constant for the max wire version.
'maxWireVersion'
Constant for reading max write batch size.
'maxWriteBatchSize'
Constant for reading the me field.
'me'
Constant for the key for the message value.
'msg'
Constant for min wire version.
'minWireVersion'
Constant for the message that indicates a sharded cluster.
'isdbgrid'
Constant for reading operationTime info from config.
'operationTime'
Constant for reading passive info from config.
'passive'
Constant for reading the passive server list.
'passives'
Constant for reading primary info from config.
'ismaster'
Constant for reading primary host field from config.
'primary'
Constant for determining ghost servers.
'isreplicaset'
Constant for reading secondary info from config.
'secondary'
{
'8.2' => 27,
'8.0' => 25,
'7.0' => 21,
'6.0' => 17,
'5.2' => 15,
'5.1' => 14,
'5.0' => 12,
'4.4' => 9,
'4.2' => 8,
}.freeze
Constant for reading replica set name info from config.
'setName'
Constant for reading setVersion info from config.
'setVersion'
Constant for reading tags info from config.
'tags'
Instantiate the new server description from the result of the hello command or fabricate a placeholder description for Unknown and LoadBalancer servers.
Returns whether this server is an arbiter, per the SDAM spec.
Whether this description is from a data-bearing server (standalone, mongos, primary or secondary).
Whether this server is a ghost, per the SDAM spec.
Will return true if the server is hidden.
Time when this server description was created according to monotonic clock.
Time when this server description was created.
Returns whether this server is a load balancer.
Check if there is a mismatch between the address host and the me field.
Whether this description is from a mongocryptd server.
Returns whether this server is a mongos, per the SDAM spec.
Returns whether the server is an other, per the SDAM spec.
Will return true if the server is passive.
Returns whether this server is a primary, per the SDAM spec.
Does this description correspond to a replica set member.
Returns whether this server is a secondary, per the SDAM spec.
Returns whether this server is a standalone, per the SDAM spec.
Returns whether this server is an unknown, per the SDAM spec.
Check equality of two descriptions.
Get a list of all arbiters in the replica set.
Get the electionId from the config.
Alias for #==.
Get a list of all servers in the replica set.
Inspect the server description.
Get the lastWriteDate from the lastWrite subdocument in the config.
Get the logicalSessionTimeoutMinutes from the config.
Get the max BSON object size for this server version.
Get the max message size for this server version.
Get the maximum wire version.
Get the maximum batch size for writes.
Get the me field value.
Get the minimum wire version.
opTime in lastWrite subdocument of the hello response.
Get a list of the passive servers in the cluster.
Get the address of the primary host.
Get the name of the replica set the server belongs to, returns nil if none.
Returns the server type as a symbol.
Get a list of all servers known to the cluster.
Get the setVersion from the config.
Get the tags configured for the server.
Returns whether topology version in this description is potentially newer than or equal to topology version in another description.
Returns whether topology version in this description is potentially newer than topology version in another description.
Get the range of supported wire versions for the server.
# File 'lib/mongo/server/description.rb', line 281
attr_reader :address
true, false (readonly)
Returns whether this server is an arbiter, per the SDAM spec.
Float (readonly)
# File 'lib/mongo/server/description.rb', line 297
attr_reader :average_round_trip_time
Hash (readonly)
# File 'lib/mongo/server/description.rb', line 284
attr_reader :config
true, false (readonly)
Whether this description is from a data-bearing server (standalone, mongos, primary or secondary).
# File 'lib/mongo/server/description.rb', line 788
def data_bearing? mongos? || primary? || secondary? || standalone? end
# File 'lib/mongo/server/description.rb', line 294
attr_reader :features
true, false (readonly)
Whether this server is a ghost, per the SDAM spec.
Float (readonly)
Time when this server description was created according to monotonic clock.
# File 'lib/mongo/server/description.rb', line 842
attr_reader :last_update_monotime
Time (readonly)
This time does not indicate when a successful server check
Time when this server description was created.
completed, because marking a server unknown updates its description and last_update_time. Use Server#last_scan to find out when the server was last successfully checked by its Monitor.
# File 'lib/mongo/server/description.rb', line 833
attr_reader :last_update_time
true | false (readonly)
Returns whether this server is a load balancer.
# File 'lib/mongo/server/description.rb', line 289
def load_balancer? @load_balancer end
true, false (readonly)
Check if there is a mismatch between the address host and the me field.
Float (readonly)
# File 'lib/mongo/server/description.rb', line 301
attr_reader :minimum_round_trip_time
true, false (readonly)
Whether this description is from a mongocryptd server.
true, false (readonly)
Returns whether this server is a mongos, per the SDAM spec.
Boolean (readonly)
true, false (readonly)
Returns whether the server is an other, per the SDAM spec.
# File 'lib/mongo/server/description.rb', line 574
def other? # The SDAM spec is slightly confusing on what "other" means, # but it's referred to it as "RSOther" which means a non-RS member # cannot be "other". ok? && !!config['setName'] && ( config['hidden'] == true || (!primary? && !secondary? && !arbiter?) ) end
true, false (readonly)
Will return true if the server is passive.
true, false (readonly)
Returns whether this server is a primary, per the SDAM spec.
true, false (readonly)
Does this description correspond to a replica set member.
# File 'lib/mongo/server/description.rb', line 777
def replica_set_member? ok? && !(standalone? || mongos?) end
true, false (readonly)
Returns whether this server is a secondary, per the SDAM spec.
true, false (readonly)
Returns whether this server is a standalone, per the SDAM spec.
true, false (readonly)
Returns whether this server is an unknown, per the SDAM spec.
# File 'lib/mongo/server/description.rb', line 718
def unknown? return false if load_balancer? config.empty? || config.keys == %w[topologyVersion] || !ok? end
true, false
Also known as: #eql?
Check equality of two descriptions.
Array<String>
Get a list of all arbiters in the replica set.
BSON::ObjectId
Get the electionId from the config.
# File 'lib/mongo/server/description.rb', line 473
def election_id config[ELECTION_ID] end
Alias for #==.
# File 'lib/mongo/server/description.rb', line 874
alias eql? ==
Array<String>
Get a list of all servers in the replica set.
String
Inspect the server description.
# File 'lib/mongo/server/description.rb', line 374
def inspect "#<Mongo::Server:Description:0x#{object_id} config=#{config} average_round_trip_time=#{average_round_trip_time}>" end
true, false
Is this description from the given server.
Time
Get the lastWriteDate from the lastWrite subdocument in the config.
# File 'lib/mongo/server/description.rb', line 538
def last_write_date config[LAST_WRITE][LAST_WRITE_DATE] if config[LAST_WRITE] end
true, false
Is a server included in this description’s list of servers.
Integer?
Get the logicalSessionTimeoutMinutes from the config.
# File 'lib/mongo/server/description.rb', line 550
def logical_session_timeout config[LOGICAL_SESSION_TIMEOUT_MINUTES] if config[LOGICAL_SESSION_TIMEOUT_MINUTES] end
Integer
Get the max BSON object size for this server version.
# File 'lib/mongo/server/description.rb', line 386
def max_bson_object_size config[MAX_BSON_OBJECT_SIZE] end
Integer
Get the max message size for this server version.
# File 'lib/mongo/server/description.rb', line 398
def config[MAX_MESSAGE_BYTES] end
Integer
Get the maximum wire version. Defaults to zero.
# File 'lib/mongo/server/description.rb', line 422
def max_wire_version config[MAX_WIRE_VERSION] || 0 end
Integer
Get the maximum batch size for writes.
# File 'lib/mongo/server/description.rb', line 410
def max_write_batch_size config[MAX_WRITE_BATCH_SIZE] || DEFAULT_MAX_WRITE_BATCH_SIZE end
String
The value in me field may differ from the server description’s address. This can happen, for example, in split horizon configurations. The SDAM spec only requires removing servers whose me does not match their address in some of the situations (e.g. when the server in question is an RS member but not a primary).
Get the me field value.
Integer
Get the minimum wire version. Defaults to zero.
# File 'lib/mongo/server/description.rb', line 434
def min_wire_version config[MIN_WIRE_VERSION] || 0 end
BSON::Timestamp
opTime in lastWrite subdocument of the hello response.
Array<String>
Get a list of the passive servers in the cluster.
String | nil
Get the address of the primary host.
# File 'lib/mongo/server/description.rb', line 617
def primary_host config[PRIMARY_HOST] && config[PRIMARY_HOST].downcase end
String?
Get the name of the replica set the server belongs to, returns nil if none.
# File 'lib/mongo/server/description.rb', line 845
def server_connection_id config['connectionId'] end
Returns the server type as a symbol.
# File 'lib/mongo/server/description.rb', line 682
def server_type return :load_balancer if load_balancer? return :arbiter if arbiter? return :ghost if ghost? return :sharded if mongos? return :primary if primary? return :secondary if secondary? return :standalone if standalone? return :other if other? :unknown end
Boolean
# File 'lib/mongo/server/description.rb', line 890
def server_version_gte?(version) if load_balancer? # If we are talking to a load balancer, there is no monitoring # and we don't know what server is behind the load balancer. # Assume everything is supported. # TODO remove this when RUBY-2220 is implemented. return true end required_wv = SERVER_VERSION_WIRE_VERSION_MAP[version] raise NotImplementedError, "Unexpected server version #{version.inspect}" unless required_wv required_wv <= max_wire_version end
Array<String>
Get a list of all servers known to the cluster.
nil | Object
# File 'lib/mongo/server/description.rb', line 852
def service_id config['serviceId'] end
Integer
Get the setVersion from the config.
# File 'lib/mongo/server/description.rb', line 485
def set_version config[SET_VERSION] end
Hash
Get the tags configured for the server.
nil
# File 'lib/mongo/server/description.rb', line 490
def topology_version unless defined?(@topology_version) @topology_version = config['topologyVersion'] && TopologyVersion.new(config['topologyVersion']) end @topology_version end
true | false
Returns whether topology version in this description is potentially newer than or equal to topology version in another description.
# File 'lib/mongo/server/description.rb', line 506
def topology_version_gt?(other_desc) if topology_version.nil? || other_desc.topology_version.nil? true else topology_version.gt?(other_desc.topology_version) end end
true | false
Returns whether topology version in this description is potentially newer than topology version in another description.
# File 'lib/mongo/server/description.rb', line 522
def topology_version_gte?(other_desc) if topology_version.nil? || other_desc.topology_version.nil? true else topology_version.gte?(other_desc.topology_version) end end
Range
Get the range of supported wire versions for the server.
# File 'lib/mongo/server/description.rb', line 737
def wire_versions min_wire_version..max_wire_version end