#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'.freeze
Constant for reading arbiters info from config.
'arbiters'.freeze
Constant for reading connectionId info from config.
'connectionId'.freeze
Default max write batch size.
1000.freeze
Constant for reading electionId info from config.
'electionId'.freeze
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'.freeze
Constant for reading hosts info from config.
'hosts'.freeze
Constant for the lastWrite subdocument.
'lastWrite'.freeze
Constant for the lastWriteDate field in the lastWrite subdocument.
'lastWriteDate'.freeze
Will be removed in 3.0.
The legacy wire protocol version.
0.freeze
Constant for reading localTime info from config.
'localTime'.freeze
Constant for reading logicalSessionTimeoutMinutes info from config.
'logicalSessionTimeoutMinutes'.freeze
Constant for reading max bson size info from config.
'maxBsonObjectSize'.freeze
Constant for reading max message size info from config.
'maxMessageSizeBytes'.freeze
Constant for the max wire version.
'maxWireVersion'.freeze
Constant for reading max write batch size.
'maxWriteBatchSize'.freeze
Constant for reading the me field.
'me'.freeze
Constant for the key for the message value.
'msg'.freeze
Constant for min wire version.
'minWireVersion'.freeze
Constant for the message that indicates a sharded cluster.
'isdbgrid'.freeze
Constant for reading operationTime info from config.
'operationTime'.freeze
Constant for reading passive info from config.
'passive'.freeze
Constant for reading the passive server list.
'passives'.freeze
Constant for reading primary info from config.
'ismaster'.freeze
Constant for reading primary host field from config.
'primary'.freeze
Constant for determining ghost servers.
'isreplicaset'.freeze
Constant for reading secondary info from config.
'secondary'.freeze
Constant for reading replica set name info from config.
'setName'.freeze
Constant for reading setVersion info from config.
'setVersion'.freeze
Constant for reading tags info from config.
'tags'.freeze
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 287
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 305
attr_reader :average_round_trip_time
Hash
(readonly)
# File 'lib/mongo/server/description.rb', line 290
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 794
def data_bearing? mongos? || primary? || secondary? || standalone? end
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 848
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 839
attr_reader :last_update_time
true
| false
(readonly)
Returns whether this server is a load balancer.
# File 'lib/mongo/server/description.rb', line 295
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 309
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 582
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 783
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 725
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 481
def election_id config[ELECTION_ID] end
Alias for #==.
# File 'lib/mongo/server/description.rb', line 880
alias_method :eql?, :==
# File 'lib/mongo/server/description.rb', line 300
def features @features end
Array
<String
>
Get a list of all servers in the replica set.
String
Inspect the server description.
# File 'lib/mongo/server/description.rb', line 382
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 546
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 558
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 394
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 406
def config[MAX_MESSAGE_BYTES] end
Integer
Get the maximum wire version. Defaults to zero.
# File 'lib/mongo/server/description.rb', line 430
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 418
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 442
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 625
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 851
def server_connection_id config['connectionId'] end
Returns the server type as a symbol.
# File 'lib/mongo/server/description.rb', line 690
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 883
def server_version_gte?(version) required_wv = case version when '7.0' 21 when '6.0' 17 when '5.2' 15 when '5.1' 14 when '5.0' 12 when '4.4' 9 when '4.2' 8 when '4.0' 7 when '3.6' 6 when '3.4' 5 when '3.2' 4 when '3.0' 3 when '2.6' 2 else raise ArgumentError, "Bogus required version #{version}" end 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 >= min_wire_version && 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 858
def service_id config['serviceId'] end
Integer
Get the setVersion from the config.
# File 'lib/mongo/server/description.rb', line 493
def set_version config[SET_VERSION] end
Hash
Get the tags configured for the server.
nil
# File 'lib/mongo/server/description.rb', line 498
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 514
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 530
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 743
def wire_versions min_wire_version..max_wire_version end