类:Mongo::Server::Description

继承:
对象
  • 对象
显示全部
定义于:
lib/ Mongo/ 服务器/description.rb
lib/ Mongo/ 服务器/description/features.rb、
lib/ Mongo/ 服务器/description/load_balancer.rb

Overview

表示服务器的描述,由 hello 命令的结果填充。

注意:未知的服务器没有传输版本,但由于旧版原因,我们会为任何没有传输版本的服务器的 min_wire_version 和 max_wire_version 返回 0。目前,驱动程序有时会在服务器未知的情况下构造命令,因此对 min_wire_version 和 max_wire_version 的引用不应为零。当驱动程序行为发生更改时 (https://jira.mongodb.org/browse/RUBY-1805),这可能不再是必要的。

由于:

  • 2.0.0

在命名空间下定义

类: 功能, LoadBalancer

常量摘要折叠

ARBITER =
已弃用。

用于从配置中读取仲裁节点信息的常量。

由于:

  • 2.0.0

'arbiterOnly'
ARBITERS =

用于从配置中读取仲裁节点信息的常量。

由于:

  • 2.0.0

'仲裁节点'
HIDDEN =

用于从配置中读取隐藏信息的常量。

由于:

  • 2.0.0

'隐藏'
HOSTS =

用于从配置中读取主机信息的常量。

由于:

  • 2.0.0

'主机'
MESSAGE =
已弃用。

消息值的键常量。

由于:

  • 2.0.0

'msg'
MONGOS_MESSAGE =
已弃用。

指示分分片集群的消息常量。

由于:

  • 2.0.0

'isdbgrid'
REPLICA_SET =
已弃用。

用于确定虚拟服务器的常量。

由于:

  • 2.0.0

'isreplicaset'
MAX_BSON_OBJECT_SIZE =

用于从配置中读取最大BSON大小信息的常量。

由于:

  • 2.0.0

'maxBsonObjectSize'
MAX_MESSAGE_BYTES =

用于从配置中读取最大消息大小信息的常量。

由于:

  • 2.0.0

'maxMessageSizeBytes'
MAX_WIRE_VERSION =

最大线路版本常量。

由于:

  • 2.0.0

'maxWireVersion'
MIN_WIRE_VERSION =

最小线路版本常量。

由于:

  • 2.0.0

'minWireVersion'
MAX_WRITE_BATCH_SIZE =

读取最大写入批处理大小的常量。

由于:

  • 2.0.0

'maxWriteBatchSize'
LAST_WRITE =

lastWrite 子文档的常量。

由于:

  • 2.4.0

'lastWrite'
LAST_WRITE_DATE =

lastWrite 子文档中 lastWriteDate 字段的常量。

由于:

  • 2.4.0

'lastWriteDate'
ME =

用于读取 me字段的常量。

由于:

  • 2.1.0

'me'
DEFAULT_MAX_WRITE_BATCH_SIZE =

默认最大写入批处理大小。

由于:

  • 2.0.0

1000
LEGACY_WIRE_VERSION =
已弃用。

将在3.0中删除。

传统传输协议版本。

由于:

  • 2.0.0

0
被动 =

用于从配置中读取被动信息的常量。

由于:

  • 2.0.0

'PASSIVE'
被动 =

用于读取无源服务器列表的常量。

由于:

  • 2.0.0

'被动语态'
主节点 =
已弃用。

用于从配置中读取主节点 (primary node in the replica set)节点信息的常量。

由于:

  • 2.0.0

'isMaster'
PRIMARY_HOST =

用于从配置中读取主节点 (primary node in the replica set)托管字段的常量。

由于:

  • 2.5.0

'主节点'
SECONDARY =
已弃用。

用于从配置从节点(secondary node from replica set)读取从节点信息的常量。

由于:

  • 2.0.0

'从节点'
SET_NAME =

用于从配置中读取副本集名称信息的常量。

由于:

  • 2.0.0

'集名称'
标签 =

用于从配置中读取标签信息的常量。

由于:

  • 2.0.0

'标记'
ELECTION_ID =

用于从配置中读取选举 ID 信息的常量。

由于:

  • 2.1.0

'electionId'
SET_VERSION =

用于从配置中读取 setVersion 信息的常量。

由于:

  • 2.2.2

'setVersion'
LOCAL_TIME =

用于从配置中读取 localTime 信息的常量。

由于:

  • 2.1.0

'localTime'
OPERATION_TIME =

用于从配置中读取 operationTime 信息的常量。

由于:

  • 2.5.0

'ops/sec'
LOGICAL_SESSION_TIMEOUT_MINUTES =

用于从配置中读取 LogicalSessionTimeoutMinutes 信息的常量。

由于:

  • 2.5.0

'logicalSessionTimeoutMinutes'
CONNECTION_ID =

此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。

用于从配置中读取 connectionId 信息的常量。

由于:

  • 2.0.0

'connectionId'
IS_WRITABLE_PRIMARY =

此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。

用于从配置中读取现代主节点 (primary node in the replica set)标志的常量。

由于:

  • 2.0.0

'isWritablePrimary'
HELLO_OK =

此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。

用于从配置中读取 helloOk 功能标志的常量。

由于:

  • 2.0.0

'helloOk'
EXCLUDE_FOR_COMPARISON =

比较两个描述时要排除的字段。

排除 主节点 (primary node in the replica set)(旧版 ismaster)、IS_WRITABLE_主节点 (primary node in the replica set)(现代 hello)和 HELLO_OK 密钥,因为驱动程序在初始握手时会进行一次性的旧版 isMaster 到现代 hello 协议切换(根据 SDAM 服务器监控规格)。同一逻辑角色的两个响应仅在填充了哪些密钥方面有所不同。角色本身仍然通过 从节点(secondary node from replica set) 标志和剩余的副本集元数据进行区分。

由于:

  • 2.0.6

[ LOCAL_TIME,
LAST_WRITE,
OPERATION_TIME,
操作::CLUSTER_TIME,
CONNECTION_ID,
主节点,
IS_WRITABLE_PRIMARY,
HELLO_OK, ].冻结
SERVER_VERSION_WIRE_VERSION_MAP =

此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。

由于:

  • 2.0.0

{
  ' 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,
}.冻结

实例属性摘要折叠

实例方法摘要折叠

构造函数详情

#initialize (解决, config = {}, average_round_trip_time: nil, minimum_round_trip_time:,0 load_balancer: false, force_load_balancer: false) ⇒ 说明

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

根据 hello 命令的结果实例化新的服务器描述,或为未知服务器和 LoadBalancer 服务器制作占位符描述。

例子:

实例化新描述。

Description.new(address, { 'isWritablePrimary' => true }, 0.5)

参数:

  • 地址 (地址)

    服务器解决。

  • config 哈希 (默认为: {}

    hello 命令的结果。

  • average_round_trip_time 浮点 (默认为: nil

    hello 命令完成所需的移动平均时间(秒)。

  • minimum_round_trip_time 浮点 (默认为: 0

    十个 last hello 命令的最小往返时间。

  • load_balancer ( true | false ) (默认为: false

    是否将服务器视为负载负载均衡器。

  • force_load_balancer ( true | false ) (默认为: false

    是否强制服务器充当负载负载均衡器。

由于:

  • 2.0.0



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/ Mongo/ 服务器/description.rb', line 237

def 初始化(地址, config = {}, average_round_trip_time: nil,
               minimum_round_trip_time: 0, load_balancer: false,
               force_load_balancer: false)
  @address = 地址
  @config = config
  @load_balancer = !!load_balancer
  @force_load_balancer = !!force_load_balancer
  @features = 功能.new(wire_versions, me || @address.to_s)
  @average_round_trip_time = average_round_trip_time
  @minimum_round_trip_time = minimum_round_trip_time
  @last_update_time = 时间.now.冻结
  @last_update_monotime = Utils.monotic_time

  # 当设立了loadBalanced=true URI 选项时,驱动程序将拒绝
  # 在与其通信的服务器未设立serviceId 的情况下运行
  # 在 ismaster/hello 响应中。
  #
  # 目前,我们无法在常青树上运行适当的负载负载均衡器设置
  #
  # 因此,当使用 connect=:load_balanced Ruby选项时
  # loadBalanced=true URI 选项的值(如果未在 中设立serviceId)
  # ismaster/hello 响应,驱动程序会制造一个 serviceId 和
  # 将未报告自身的服务器视为
  #在负载均衡器后面作为位于负载负载均衡器负载均衡器的服务器。
  #
  # 5.0 + 服务器应提供topologyVersion.processId,其中
  # 特定于特定进程实例。 我们可以使用
  #字段作为 serviceId 的代理。
  #
  # 如果由于某种原因未提供拓扑版本,我们将
  # 在本地创建一个 serviceId。
  #
  # 无论哪种情况,后面的实际服务器提供的 serviceId
  # 负载负载均衡器应该是BSON::ObjectId。 捏造的
  # 服务 ID 是字符串,用于将其与真实服务区分开来。
  # 特别是,processId 也是BSON::ObjectId,但会
  # 映射到string ,以便清楚地看出这是一个假服务ID 。
  #
  # TODO:完成 https://jira.mongodb.org/browse/RUBY-{0 2881后将其删除。
  if load_balancer && 确定吗? && !service_id
    除非 force_load_balancer
      提高 错误::MissingServiceId,
            “ 服务器 #{ address.seed} 服务器 未 在握手响应中提供服务 ID”
    end

    false_service_id = if (process_id = topology_version && topology_version['processId'])
                        " 进程: #{ process_id } "
                      else
                        " false: #{ rand ( ( 2 ** 32 ) - 1 ) + 1 } "
                      end
    @config = @config.合并(merge)(' serviceId ' => false_service_id)
  end

  return 除非 mongo::Lint.已启用?

  # 预填充缓存实例变量
  主机
  仲裁节点
  被动语态
  topology_version

  冻结
end

实例属性详细信息

#解决地址(只读)

返回解决服务器的解决。

返回:

  • (地址)

    解决服务器的解决。

由于:

  • 2.0.0



302
303
304
# File 'lib/ Mongo/ 服务器/description.rb', line 302

def 地址
  @address
end

# average_round_trip_time浮点(只读)

返回 hello 调用完成所需的移动平均时间。

返回:

  • (浮点)

    完成 hello 调用所需的移动平均时间。

由于:

  • 2.0.0



318
319
320
# File 'lib/ Mongo/ 服务器/description.rb', line 318

def average_round_trip_time
  @average_round_trip_time
end

# config哈希(只读)

返回 hello 命令的实际结果。

返回:

  • (哈希)

    hello 命令的实际结果。

由于:

  • 2.0.0



305
306
307
# File 'lib/ Mongo/ 服务器/description.rb', line 305

def config
  @config
end

#个功能功能 (只读)

返回功能服务器的功能。

返回:

  • (功能)

    features 服务器的功能。

由于:

  • 2.0.0



315
316
317
# File 'lib/ Mongo/ 服务器/description.rb', line 315

def 功能
  @features
end

# last_update_monotime浮点(只读)

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

根据单调时钟创建此服务器描述的时间。

返回:

  • (浮点)

    MongoDB Server描述创建单调时间。

另请参阅:

  • 了解更多详情

由于:

  • 2.0.0



863
864
865
# File 'lib/ Mongo/ 服务器/description.rb', line 863

def last_update_monotime
  @last_update_monotime
end

# last_update_time时间(只读)

注意:

该时间并不表示服务器何时成功检查

创建此服务器描述的时间。

已完成,因为将服务器标记为未知会更新其描述和 last_update_time。 使用 Server#last_scan 查明监视器上次成功检查服务器的时间。

返回:

  • 时间

    MongoDB Server描述创建时间。

由于:

  • 2.7.0



854
855
856
# File 'lib/ Mongo/ 服务器/description.rb', line 854

def last_update_time
  @last_update_time
end

# minimum_round_trip_time 浮点(只读)

返回最后十次 hello 调用完成所需的最短时间。

返回:

  • (浮点)

    最后十次 hello 调用完成所需的最短时间。

由于:

  • 2.0.0



322
323
324
# File 'lib/ Mongo/ 服务器/description.rb', line 322

def minimum_round_trip_time
  @minimum_round_trip_time
end

实例方法详细信息

# == (other) ⇒ true , false也称为: eql?

检查两个描述是否相等。

例子:

检查描述相等性。

description == other

参数:

  • 其他 ( Object )

    其他描述。

返回:

  • ( true , false )

    对象是否相等。

由于:

  • 2.0.6



887
888
889
890
891
892
893
894
895
# File 'lib/ Mongo/ 服务器/description.rb', line 887

def ==(其他)
  return false if self.class != 其他.class
  return false if 未知? || 其他.未知?
  return false if server_type != 其他.server_type

  (config.密钥 + 其他.config.密钥).uniq.全部? do |k|
    config[k] == 其他.config[k] || EXCLUDE_FOR_COMPARISON.包括?(k)
  end
end

#仲裁节点?true , false

根据 SDAM 规范,返回此服务器是否为仲裁节点节点。

例子:

服务器是仲裁节点吗?

description.arbiter?

返回:

  • ( true , false )

    如果服务器是仲裁节点。

由于:

  • 2.0.0



332
333
334
335
336
# File 'lib/ Mongo/ 服务器/description.rb', line 332

def 仲裁节点?
  确定吗? &&
    config[' arbiterOnly '] == true &&
    !!config['setName']
end

#仲裁节点Array<String>

获取副本集所有仲裁节点的列表。

例子:

获取副本集的仲裁节点。

description.arbiters

返回:

  • ( Array<String> )

    集合中的仲裁节点。

由于:

  • 2.0.0



346
347
348
# File 'lib/ Mongo/ 服务器/description.rb', line 346

def 仲裁节点
  @arbiters ||= (config[仲裁节点] || []).map { |s| s.Downcase }
end

# data_ Bearing?true , false

此描述是否来自数据承载服务器(独立运行运行、 mongos、主节点 (primary node in the replica set)节点或从从节点(secondary node from replica set))。

返回:

  • ( true , false )

    描述是否来自承载数据的服务器。

由于:

  • 2.7.0



809
810
811
# File 'lib/ Mongo/ 服务器/description.rb', line 809

def data_ Bearing?
  mongos? || 主节点? || 从节点(secondary node from replica set)? || 独立运行?
end

#election_id =" BSON::ObjectId "

从配置中获取选举 ID。

例子:

获取选举 ID。

description.election_id

返回:

  • ( BSON::ObjectId )

    选举 ID。

由于:

  • 2.1.0



494
495
496
# File 'lib/ Mongo/ 服务器/description.rb', line 494

def election_id
  config[ELECTION_ID]
end

#幽灵?true , false

根据 SDAM 规范,此服务器是否为虚拟服务器。

例子:

服务器是幽灵吗?

description.ghost?

返回:

  • ( true , false )

    如果服务器是幽灵。

由于:

  • 2.0.0



358
359
360
361
# File 'lib/ Mongo/ 服务器/description.rb', line 358

def ghost?
  确定吗? &&
    config[' isreplicaset '] == true
end

#隐藏?true , false

如果服务器处于隐藏状态,则返回 true。

例子:

服务器是隐藏的吗?

description.hidden?

返回:

  • ( true , false )

    如果服务器处于隐藏状态。

由于:

  • 2.0.0



371
372
373
# File 'lib/ Mongo/ 服务器/description.rb', line 371

def 隐藏?
  确定吗? && !!config[Hidden]
end

#hostsArray<String>

获取副本集中所有服务器的列表。

例子:

获取副本集的服务器。

description.hosts

返回:

  • ( Array<String> )

    设立中的服务器。

由于:

  • 2.0.0



383
384
385
# File 'lib/ Mongo/ 服务器/description.rb', line 383

def 主机
  @hosts ||= (config[HOSTS] || []).map { |s| s.Downcase }
end

#检查string

检查服务器描述。

例子:

检查服务器描述

description.inspect

返回:

  • ( string )

    检查。

由于:

  • 2.0.0



395
396
397
# File 'lib/ Mongo/ 服务器/description.rb', line 395

def 检查
  " #<Mongo::Server:Description: 0 x #{ object_id } config= #{ config } average_round_trip_time= #{ average_round_trip_time } > "
end

# is_server? (服务器) ⇒ true , false

已弃用。

这是来自给定服务器的描述吗?

例子:

检查描述是否来自给定服务器。

description.is_server?(server)

返回:

  • ( true , false )

    如果描述来自服务器。

由于:

  • 2.0.6



771
772
773
# File 'lib/ Mongo/ 服务器/description.rb', line 771

def is_server?(server)
  地址 == server.地址
end

# last_write_date时间

从配置中的 lastWrite 子文档获取 lastWriteDate。

例子:

获取 lastWriteDate 值。

description.last_write_date

返回:

  • 时间

    上次写入日期。

由于:

  • 2.4.0



559
560
561
# File 'lib/ Mongo/ 服务器/description.rb', line 559

def last_write_date
  config[LAST_WRITE][LAST_WRITE_DATE] if config[LAST_WRITE]
end

#lists_server? (服务器) ⇒ true , false

已弃用。

服务器是否包含在此说明的服务器列表中。

例子:

检查服务器是否在服务器描述列表中。

description.lists_server?(server)

返回:

  • ( true , false )

    如果服务器位于说明的服务器列表中。

由于:

  • 2.0.6



785
786
787
# File 'lib/ Mongo/ 服务器/description.rb', line 785

def lists_server?(server)
  服务器.包括?(server.地址.to_s)
end

# load_balancer?true | false

返回此服务器是否为负载负载均衡器。

返回:

  • ( true | false )

    此服务器是否为负载负载均衡器。

由于:

  • 2.0.0



310
311
312
# File 'lib/ Mongo/ 服务器/description.rb', line 310

def load_balancer?
  @load_balancer
end

#logic_session_timeout整数?

从配置中获取logicSessionTimeoutMinutes。

例子:

获取logicSessionTimeoutMinutes(以分钟为单位)值。

description.logical_session_timeout

返回:

  • ( Integer , nil )

    逻辑会话超时(以分钟为单位)。

由于:

  • 2.5.0



571
572
573
# File 'lib/ Mongo/ 服务器/description.rb', line 571

def logic_session_timeout
  config[LOGICAL_SESSION_TIMEOUT_MINUTES] if config[LOGICAL_SESSION_TIMEOUT_MINUTES]
end

# max_bson_object_size整数

获取此服务器版本的最大BSON对象大小。

例子:

获取最大BSON对象大小。

description.max_bson_object_size

返回:

  • ( Integer )

    最大对象大小(以字节为单位)。

由于:

  • 2.0.0



407
408
409
# File 'lib/ Mongo/ 服务器/description.rb', line 407

def max_bson_object_size
  config[MAX_BSON_OBJECT_SIZE]
end

# max_message_size整数

获取此服务器版本的最大消息大小。

例子:

获取最大消息大小。

description.max_message_size

返回:

  • ( Integer )

    最大消息大小(以字节为单位)。

由于:

  • 2.0.0



419
420
421
# File 'lib/ Mongo/ 服务器/description.rb', line 419

def max_message_size
  config[MAX_MESSAGE_BYTES]
end

#max_wire_versionInteger

获取最大线路版本。 默认为零。

例子:

获取最大线路版本。

description.max_wire_version

返回:

  • ( Integer )

    支持的最大线路版本。

由于:

  • 2.0.0



443
444
445
# File 'lib/ Mongo/ 服务器/description.rb', line 443

def max_wire_version
  config[MAX_WIRE_VERSION] || 0
end

# max_write_batch_size整数

获取写入的最大批处理大小。

例子:

获取最大批处理大小。

description.max_write_batch_size

返回:

  • ( Integer )

    最大批处理大小。

由于:

  • 2.0.0



431
432
433
# File 'lib/ Mongo/ 服务器/description.rb', line 431

def max_write_batch_size
  config[MAX_WRITE_BATCH_SIZE] || DEFAULT_MAX_WRITE_BATCH_SIZE
end

# mestring

注意:

me字段中的值可能与服务器说明的地址不同。示例,这可能发生在水平分割配置中。SDAM 规范仅要求在某些情况下删除 me 与其解决不匹配的服务器(例如,当相关服务器是 RS 节点但不是主节点 (primary node in the replica set))。

获取 me字段值。

返回:

  • ( string )

    me字段。

由于:

  • 2.1.0



470
471
472
# File 'lib/ Mongo/ 服务器/description.rb', line 470

def me
  config[ME]
end

# me_mismatch?true , false

检查解决托管和 me字段是否不匹配。

例子:

检查是否存在不匹配的情况。

description.me_mismatch?

返回:

  • ( true , false )

    如果 me字段与解决托管不匹配。

由于:

  • 2.0.6



821
822
823
# File 'lib/ Mongo/ 服务器/description.rb', line 821

def me_mismatch?
  !!(地址.to_s.Downcase != me.Downcase if me)
end

# min_wire_version整数

获取最低传输版本。 默认为零。

例子:

获取最低传输版本。

description.min_wire_version

返回:

  • ( Integer )

    支持的最低线路版本。

由于:

  • 2.0.0



455
456
457
# File 'lib/ Mongo/ 服务器/description.rb', line 455

def min_wire_version
  config[MIN_WIRE_VERSION] || 0
end

# mongocryptd? true , false

此描述是否来自 mongocryptd服务器。

返回:

  • ( true , false )

    此描述是否来自 mongocryptd服务器。

由于:

  • 2.0.0



829
830
831
# File 'lib/ Mongo/ 服务器/description.rb', line 829

def mongocryptd?
  确定吗? && config['iscryptd'] == true
end

# mongos?true , false

根据 SDAM 规范,返回此服务器是否为mongos。

例子:

服务器是 mongos 吗?

description.mongos?

返回:

  • ( true , false )

    如果服务器是mongos.

由于:

  • 2.0.0



583
584
585
# File 'lib/ Mongo/ 服务器/description.rb', line 583

def mongos?
  确定吗? && config['msg'] == ' isdbgrid '
end

#可以吗?布尔

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回:

  • 布尔值

由于:

  • 2.0.0



746
747
748
# File 'lib/ Mongo/ 服务器/description.rb', line 746

def 确定吗?
  config[操作::结果::正常] == 1
end

#op_timeBSON::Timestamp

hello 响应的 lastWrite 子文档中的optime 。

返回:

  • ( BSON::Timestamp )

    时间戳。

由于:

  • 2.7.0



838
839
840
841
842
# File 'lib/ Mongo/ 服务器/description.rb', line 838

def op_time
  return 除非 config[' lastWrite '] && config[' lastWrite '][' optime ']

  config[' lastWrite '][' optime ']['ts']
end

# other?true , false

根据 SDAM 规范,返回服务器是否为其他服务器。

例子:

是 other 类型的描述。

description.other?

返回:

  • ( true , false )

    如果描述的是其他。

由于:

  • 2.0.0



595
596
597
598
599
600
601
602
603
604
# File 'lib/ Mongo/ 服务器/description.rb', line 595

def 其他?
  # SDAM 规范对“其他”的含义有点令人困惑,
  # 但它被称为“RSOTHER”,意思是非 RS 成员
  # 不能是“其他”。
  确定吗? &&
    !!config['setName'] && (
    config[' hidden '] == true ||
    (!主节点? && !从节点(secondary node from replica set)? && !仲裁节点?)
  )
end

# Passive?true , false

如果服务器处于被动状态,则返回 true。

例子:

服务器是被动的吗?

description.passive?

返回:

  • ( true , false )

    如果服务器处于被动状态。

由于:

  • 2.0.0



614
615
616
# File 'lib/ Mongo/ 服务器/description.rb', line 614

def 被动?
  确定吗? && !!config[PASSIVE]
end

# PassivesArray<String>

获取集群中无源服务器的列表。

例子:

获取被动语态。

description.passives

返回:

  • ( Array<String> )

    被动列表。

由于:

  • 2.0.0



626
627
628
# File 'lib/ Mongo/ 服务器/description.rb', line 626

def 被动语态
  @passives ||= (config[PASSIVES] || []).map { |s| s.Downcase }
end

#主节点?true , false

根据 SDAM 规范,返回此服务器是否主节点 (primary node in the replica set)节点。

例子:

服务器是主节点 (primary node in the replica set)吗?

description.primary?

返回:

  • ( true , false )

    如果服务器是主节点 (primary node in the replica set).

由于:

  • 2.0.0



650
651
652
653
654
# File 'lib/ Mongo/ 服务器/description.rb', line 650

def 主节点?
  确定吗? &&
    (config[' ismaster '] == true || config[' isWritablePrimary '] == true) &&
    !!config['setName']
end

#primary_hoststring | nil

获取主节点 (primary node in the replica set)托管的解决。

例子:

获取主节点 (primary node in the replica set)节点的解决。

description.primary_host

返回:

  • ( string | nil )

    主节点的地址。

由于:

  • 2.6.0



638
639
640
# File 'lib/ Mongo/ 服务器/description.rb', line 638

def primary_host
  config[PRIMARY_HOST] && config[PRIMARY_HOST].Downcase
end

# replica_set_member?true , false

此描述是否对应于副本集成员。

例子:

检查描述是否来自副本集节点。

description.replica_set_member?

返回:

  • ( true , false )

    如果描述来自副本集成员。

由于:

  • 2.0.6



798
799
800
# File 'lib/ Mongo/ 服务器/description.rb', line 798

def replica_set_member?
  确定吗? && !(独立运行? || mongos?)
end

# replica_set_namestring ?

获取服务器所属副本集的名称,如果没有,则返回 nil。

例子:

获取副本集名称。

description.replica_set_name

返回:

  • ( string , nil )

    副本集的名称。

由于:

  • 2.0.0



665
666
667
# File 'lib/ Mongo/ 服务器/description.rb', line 665

def replica_set_name
  config[SET_NAME]
end

# secondary?true , false

根据从节点(secondary node from replica set)规范,返回此服务器是否为从节点。

例子:

服务器是从从节点(secondary node from replica set)吗?

description.secondary?

返回:

  • ( true , false )

    如果服务器是从从节点(secondary node from replica set).

由于:

  • 2.0.0



689
690
691
692
693
# File 'lib/ Mongo/ 服务器/description.rb', line 689

def 从节点(secondary node from replica set)?
  确定吗? &&
    config[' secondary '] == true &&
    !!config['setName']
end

# server_connection_id对象

由于:

  • 2.0.0



866
867
868
# File 'lib/ Mongo/ 服务器/description.rb', line 866

def server_connection_id
  config[' connectionId ']
end

# server_type符号

以符号形式返回服务器类型。

例子:

获取服务器类型。

description.server_type

返回:

  • (符号)

    服务器类型。

由于:

  • 2.4.0



703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/ Mongo/ 服务器/description.rb', line 703

def server_type
  return :load_balancer if load_balancer?
  return :仲裁节点 if 仲裁节点?
  return :ghost if ghost?
  return :sharded if mongos?
  return :primary if 主节点?
  return :secondary if 从节点(secondary node from replica set)?
  return :独立运行 if 独立运行?
  return :other if 其他?

  :unknown
end

#server_version_gte?(version) ⇒ Boolean

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回:

  • 布尔值

引发:

  • ( NotImplementedError )

由于:

  • 2.0.0



912
913
914
915
916
917
918
919
920
921
922
923
924
925
# File 'lib/ Mongo/ 服务器/description.rb', line 912

def server_version_gte?(版本)
  if load_balancer?
    # 如果我们正在与负载均衡器通信,则没有监控
    # 并且我们不知道负载负载均衡器后面是哪台服务器。
    # 假设一切都受支持。
    # TODO 在实施 RUBY- 2220时删除此项。
    return true
  end

  required_wv = SERVER_VERSION_WIRE_VERSION_MAP[版本]
  提高 NotImplementedError, " Unexpected 服务器 version #{version.inspect} " 除非 required_wv

  required_wv <= max_wire_version
end

#serversArray<String>

获取集群已知的所有服务器的列表。

例子:

获取所有服务器。

description.servers

返回:

  • ( Array<String> )

    所有服务器的列表。

由于:

  • 2.0.0



677
678
679
# File 'lib/ Mongo/ 服务器/description.rb', line 677

def 服务器
  主机 + 仲裁节点 + 被动语态
end

# service_id =" nil |对象

返回 服务 ID(如果有)。

返回:

  • ( nil | Object )

    服务 ID(如果有)。

由于:

  • 2.0.0



873
874
875
# File 'lib/ Mongo/ 服务器/description.rb', line 873

def service_id
  config[' serviceId ']
end

#set_versionInteger

从配置中获取 setVersion。

例子:

获取 setVersion。

description.set_version

返回:

  • ( Integer )

    设立的版本。

由于:

  • 2.2.2



506
507
508
# File 'lib/ Mongo/ 服务器/description.rb', line 506

def set_version
  config[SET_VERSION]
end

#独立运行?true , false

根据 SDAM 规范,返回此服务器是否为独立运行运行的服务器。

例子:

服务器是独立运行的吗?

description.standalone?

返回:

  • ( true , false )

    如果服务器是独立运行的。

由于:

  • 2.0.0



724
725
726
727
728
729
# File 'lib/ Mongo/ 服务器/description.rb', line 724

def 独立运行?
  确定吗? &&
    config['msg'] != ' isdbgrid ' &&
    config['setName'].nil? &&
    config[' isreplicaset '] != true
end

#个标签哈希

获取为服务器配置的标签。

例子:

获取标签。

description.tags

返回:

  • (哈希)

    服务器的标签。

由于:

  • 2.0.0



482
483
484
# File 'lib/ Mongo/ 服务器/description.rb', line 482

def 标记
  config[标记] || {}
end

# topology_versionTopologyVersion | nil

返回 拓扑版本。

返回:

由于:

  • 2.0.0



511
512
513
514
515
516
517
# File 'lib/ Mongo/ 服务器/description.rb', line 511

def topology_version
  除非 定义?(@topology_version)
    @topology_version = config['topologyVersion'] &&
                        TopologyVersion.new(config['topologyVersion'])
  end
  @topology_version
end

# topology_version_gt? (other_desc) ⇒ true | false

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回此描述中的拓扑结构版本是否可能晚于或等于其他描述中的拓扑结构版本。

参数:

返回:

  • ( true | false )

    此描述中的拓扑结构版本是否可能更新或相同。

由于:

  • 2.0.0



527
528
529
530
531
532
533
# File 'lib/ Mongo/ 服务器/description.rb', line 527

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

# topology_version_gte? (other_desc) ⇒ true | false

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

返回此描述中的拓扑版本是否可能比其他描述中的拓扑版本新。

参数:

返回:

  • ( true | false )

    此描述中的拓扑结构版本是否可能较新。

由于:

  • 2.0.0



543
544
545
546
547
548
549
# File 'lib/ Mongo/ 服务器/description.rb', line 543

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

#未知?true , false

根据 SDAM 规范,返回此服务器是否为未知服务器。

例子:

服务器描述未知?

description.unknown?

返回:

  • ( true , false )

    如果服务器描述未知。

由于:

  • 2.0.0



739
740
741
742
743
# File 'lib/ Mongo/ 服务器/description.rb', line 739

def 未知?
  return false if load_balancer?

  config.空? || config.密钥 == %w[拓扑版本] || !确定吗?
end

#wire_versions范围

获取服务器支持的传输版本范围。

例子:

获取传输版本范围。

description.wire_versions

返回:

  • (范围)

    传输版本范围。

由于:

  • 2.0.0



758
759
760
# File 'lib/ Mongo/ 服务器/description.rb', line 758

def wire_versions
  min_wire_version..max_wire_version
end