类:Mongo::ServerSelector::Base
- 继承:
-
对象
- 对象
- Mongo::ServerSelector::Base
- 定义于:
- lib/ Mongo/server_selector/base.rb
Overview
直接已知子类
Nearest 、 Primary 、 PrimaryPreferred 、 secondary 、 secondaryPreferred
实例属性摘要折叠
-
#hedge ⇒ Hash | nil
只读
已弃用
已弃用。
MongoDB Server 8.0 中已弃用对冲读,并将在未来版本中将其删除。
-
#max_staleness ⇒ Integer
只读
从节点(secondary node from replica set)从节点可能遭受但仍有资格进行读取的最大复制延迟(以秒为单位)。
-
# options ⇒ 哈希
只读
选项 选项。
-
# tag_sets ⇒ 数组
只读
Tag_sets 用于选择服务器的标签集。
实例方法摘要折叠
-
# == (other) ⇒ true, false
检查两个服务器选择器的相等性。
-
#candidates(集群, deprioritized = []) ⇒ 数组<Server>
private
从集群中返回可接受类型的服务器。
-
#initialize(options = nil) ⇒ Base
构造函数
private
初始化服务器选择器。
-
#检查⇒ string
检查服务器选择器。
-
# local_threshold ⇒ 浮点
已弃用
已弃用。
现在,当选择服务器时,会从集群选项中获取此设置。 将在版本3.0中删除。
- # local_threshold_with_cluster (集群) ⇒ 对象 private
-
# select_server (集群, 网络探测(ping) = nil, session = nil, write_aggregation: false, deprioritized: [], timeout: nil) ⇒ Mongo::Server
从指定集群中选择一台服务器,同时考虑指定会话的mongos固定。
-
# server_selection_timeout ⇒ 浮点
已弃用
已弃用。
现在,当选择服务器时,会从集群选项中获取此设置。 将在版本3.0中删除。
-
#合适的_servers (集群, deprioritized = []) ⇒ 数组<Server>
private
从集群中返回满足服务器选择器的服务器。
-
# try_select_server (集群, write_aggregation: false, deprioritized: []) ⇒ Server | nil
private
尝试查找合适的服务器,如果有可用的服务器,则返回该服务器;如果没有合适的服务器,则返回 nil。
构造函数详情
#initialize(options = nil) ⇒ Base
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
初始化服务器选择器。
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ Mongo/server_selector/base.rb', line 47 def 初始化( = nil) = ? .dup : {} .删除(:max_staleness) if [:max_staleness] == -1 @options = @tag_sets = [:tag_sets] || [] @max_staleness = [:max_staleness] @hedge = [:hedge] validate! return if @hedge.nil? mongo::弃用.WARN( :hedge_read_preference, '对冲读取偏好(read preference)选项已弃用。对冲读在 ' \ 'MongoDB Server 8.0 中已弃用,并将在未来版本中删除。' ) end |
实例属性详细信息
#对冲⇒哈希 | nil (只读)
MongoDB Server 8.0 中已弃用对冲读,并将在未来版本中将其删除。
返回对冲 指定是否启用对冲读的文档。
83 84 85 |
# File 'lib/ Mongo/server_selector/base.rb', line 83 def 对冲 @hedge end |
# max_staleness ⇒整数(只读)
返回从节点(secondary node from replica set)从节点可能遭受但仍有资格进行读取的最大复制延迟(以秒为单位)。
76 77 78 |
# File 'lib/ Mongo/server_selector/base.rb', line 76 def max_staleness @max_staleness end |
# options ⇒哈希(只读)
返回 options 选项。
67 68 69 |
# File 'lib/ Mongo/server_selector/base.rb', line 67 def @options end |
# tag_sets ⇒数组(只读)
返回用于选择服务器的标签集。
70 71 72 |
# File 'lib/ Mongo/server_selector/base.rb', line 70 def tag_sets @tag_sets end |
实例方法详细信息
# == (other) ⇒ true , false
检查两个服务器选择器的相等性。
143 144 145 146 |
# File 'lib/ Mongo/server_selector/base.rb', line 143 def ==(其他) 名称 == 其他.名称 && 对冲 == 其他.对冲 && max_staleness == 其他.max_staleness && tag_sets == 其他.tag_sets end |
#candidates(集群, deprioritized = []) ⇒ 数组<服务器>
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
从集群中返回可接受类型的服务器。
不执行过时性验证、过时性筛选或延迟筛选。
399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/ Mongo/server_selector/base.rb', line 399 def 候选(集群, deprioritized = []) 服务器 = 集群.服务器.拒绝 { |s| deprioritized.包括?(s) } if 集群.单身? || 集群.分片的? 服务器 elsif 集群.replica_set? select_in_replica_set(服务器) else # 未知集群 - 无服务器 [] end end |
#检查⇒ string
检查服务器选择器。
129 130 131 |
# File 'lib/ Mongo/server_selector/base.rb', line 129 def 检查 " #< #{ self . class . name } :0 x #{ object_id } tag_sets= #{ tag_sets .inspect } } max_staleness = # { max_staleness .inspect } } href= " } > " end |
# local_threshold ⇒浮点
现在,当选择服务器时,会从集群选项中获取此设置。 将在版本3.0中删除。
获取最近选择的本地阈值边界(以秒为单位)。
112 113 114 |
# File 'lib/ Mongo/server_selector/base.rb', line 112 def local_threshold @local_threshold ||= [:local_threshold] || ServerSelector::LOCAL_THRESHOLD end |
# local_threshold_with_cluster (集群) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
117 118 119 |
# File 'lib/ Mongo/server_selector/base.rb', line 117 def local_threshold_with_cluster(集群) [:local_threshold] || 集群.[:local_threshold] || LOCAL_THRESHOLD end |
# select_server (集群, 网络探测(ping) = nil, session = nil, write_aggregation: false, deprioritized: [], timeout: nil) ⇒ Mongo::Server
从指定集群中选择一台服务器,同时考虑指定会话的mongos固定。
如果已给定会话且具有固定的服务器,则该服务器是考虑选择的唯一服务器。 如果服务器类型为mongos ,则立即返回;否则将启动对此服务器的监控检查以更新其状态,如果服务器在服务器选择超时时间内成为mongos ,则返回。
如果没有给出会话或会话没有固定的服务器,则在指定集群中与此服务器选择器对象的偏好匹配的所有服务器之间执行正常的服务器选择进程。 对集群中的服务器启动监控检查,直到找到合适的服务器,直到服务器选择超时。
如果在服务器选择超时时间内未找到合适的服务器,则此方法将引发 Error::NoServerAvailable。
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ Mongo/server_selector/base.rb', line 189 def select_server( 集群, ping = nil, 会话 = nil, write_aggregation: false, 取消优先级: [], timeout: nil ) select_server_impl(集群, ping, 会话, write_aggregation, deprioritized, 超时).点击 do |server| if Lint.已启用? && !server.池.准备好了吗? 提高 错误::LintError, '服务器选择器返回带有未就绪池的服务器' end end end |
# server_selection_timeout ⇒浮点
现在,当选择服务器时,会从集群选项中获取此设置。 将在版本3.0中删除。
获取服务器选择的超时时间。
96 97 98 99 |
# File 'lib/ Mongo/server_selector/base.rb', line 96 def server_selection_timeout @server_selection_timeout ||= [:server_selection_timeout] || ServerSelector::SERVER_SELECTION_TIMEOUT end |
#suitable_servers(集群, deprioritized = []) ⇒ 数组<服务器>
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
从集群中返回满足服务器选择器的服务器。
420 421 422 423 424 |
# File 'lib/ Mongo/server_selector/base.rb', line 420 def 合适的服务器(集群, deprioritized = []) 结果 = Suitable_servers_impl(集群, deprioritized) 结果 = Suitable_servers_impl(集群, []) if 结果.空? && deprioritized.任何? 结果 end |
# try_select_server (集群, write_aggregation: false, deprioritized: []) ⇒ Server | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
尝试查找合适的服务器,如果有可用的服务器,则返回该服务器;如果没有合适的服务器,则返回 nil。
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/ Mongo/server_selector/base.rb', line 350 def try_select_server(集群, write_aggregation: false, 取消优先级: []) 服务器 = if write_aggregation && 集群.replica_set? # 1 . 检查集群从节点(secondary node from replica set)的所有服务器是否都支持从节点写入。 is_write_supported = 集群.服务器.化简(reduce)(true) do |res, server| res && server.功能.merge_out_on_secondary_enabled? end if is_write_supported # 2 . 如果所有服务器都支持从从节点(secondary node from replica set)写入,则我们会尊重读取偏好(read preference)。 合适的服务器(集群, deprioritized) else # 3 . 否则,我们将回退到副本集的主节点。 [ 集群.服务器.检测(和:主节点 (primary node in the replica set)?) ] end else 合适的服务器(集群, deprioritized) end # 此服务器列表可以按特定方式排序 # 通过选择器(例如,对于从节点(secondary node from replica set)首选,第一个 # 服务器可能是从节点,第二个服务器可能是主节点) # 我们应该按照顺序选择这里的第一台服务器 server = 合适的服务器(服务器) if server && Lint.已启用? && server.average_round_trip_time.nil? # 此处服务器的平均 RTT 可能为零 # 因为 ARTT 来自可能更新的描述 # 在服务器选择运行时由后台线程执行。 # 目前 lint模式不是公共功能,如果/当此 # 项更改 (https://jira.mongodb.org/browse/RUBY- 1576 ) the # 需要删除对 ARTT 不为零的要求。 提高 错误::LintError, "MongoDB Server #{ server .address } has nil average rtt " end server end |