类:Mongo::Server::PushMonitor Private
- 继承:
-
对象
- 对象
- Mongo::Server::PushMonitor
- 扩展方式:
- 可转发
- 包括:
- 背景线程
- 定义于:
- lib/ Mongo/ 服务器/push_monitor.rb 、
lib/ Mongo/ 服务器/push_monitor/connection.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
利用服务器推送的 hello 请求的监视器。
当监控器与4.4 + 服务器握手时,它会创建一个 PushMonitor 实例。 PushMonitor 随后执行服务器推送的 hello(即 已等待并耗尽 hello)以尽快从服务器接收拓扑更改。 监控器仍会监控服务器的往返时间计算,并根据应用程序的请求立即执行检查。
在命名空间下定义
类: 连接
常量摘要
Loggable中包含的常量
实例属性摘要折叠
-
#monitor ⇒ Server
只读
private
正在监控的服务器。
-
#监控⇒ 监控
只读
private
监控 监控。
-
# options ⇒ 哈希
只读
private
推送监控选项。
-
#topology_version ⇒ TopologyVersion
只读
private
最近收到的拓扑版本。
实例方法摘要折叠
- # check ⇒ 对象 private
- # do_work ⇒ 对象 private
-
#initialize (monitor,topology_version,monitoring,**options) ⇒ PushMonitor
构造函数
private
PushMonitor 的新实例。
- # read_response ⇒ 对象 private
- # start! ⇒ 对象 private
- # stop! ⇒ 对象 private
- # to_s ⇒ 对象 private
- # write_check_command ⇒ 对象 private
包含在BackgroundThread中的方法
Loggable中包含的方法
#log_debug 、 #log_error 、 #log_ Fatal 、 #log_info 、 #log_warn 、 #logger
构造函数详情
#initialize (监控,topology_version, 监控,**options) ⇒ PushMonitor
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 PushMonitor 的新实例。
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 33 def 初始化(监控, topology_version, 监控, **) 提高 ArgumentError, “必须提供拓扑版本,但它为零” if topology_version.nil? 提高 ArgumentError, ' App 元数据 is required ' 除非 [:app_metadata] 提高 ArgumentError, '检查文档是否为必填项' 除非 [:check_document] @app_metadata = [:app_metadata] @check_document = [:check_document] 监控 = 监控 @topology_version = topology_version @monitoring = 监控 @options = 锁 = 互斥锁.new end |
实例属性详细信息
#监控⇒服务器(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 正在监控的服务器。
48 49 50 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 48 def 监控 监控 end |
# Monitoring ⇒监控(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回监控 监控。
54 55 56 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 54 def 监控 @monitoring end |
# options ⇒哈希(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回推送监视器选项。
57 58 59 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 57 def @options end |
# topology_version =" TopologyVersion " (只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回最近收到的拓扑版本。
51 52 53 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 51 def topology_version @topology_version end |
实例方法详细信息
# check ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 138 def 检查 锁.同步 do if @connection && @connection.进程 ID (PID) != 处理.进程 ID (PID) log_warn("检测到PID更改 - mongo客户端应已重新连接(旧PID #{ @connection . PID } ,新PID #{ Process . PID } ") @connection.断开连接! @connection = nil end end 锁.同步 do 除非 @connection @server_pushing = false 连接 = PushMonitor::连接.new(server.地址, ) 连接.连接! # 使用元数据标识与服务器的流媒体连接 # 在流媒体之前进行握手(携带 appName),反映了 # 监控器和服务器监控规范的轮询,其中建立 # 在发出监控连接之前进行握手 # 可等待 hello。如果没有此,appName 范围的服务器行为 # 从不应用于流媒体 hello。 连接.握手! @connection = 连接 end end resp_msg = 开始 write_check_command 除非 @server_pushing read_response 救援 mongo::错误 锁.同步 do @connection.断开连接! @connection = nil end 提高 end @server_pushing = resp_msg.flags.包括?(:more_to_come) 结果 = 操作::结果.new(resp_msg) 结果.validate! 结果.文档.first end |
# do_work ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 91 def do_work 锁.同步 do return if @stop_requested end 结果 = 监控.publish_heartbeat(server, 等待: true) do 检查 end new_description = 监控.run_sdam_flow(结果, 等待: true) # 当 hello 由于故障点而失败时,响应不会 # include 拓扑版本。 在这种情况下,我们需要保留现有的 #拓扑结构版本,以便我们可以恢复监控。 # 该规范似乎并未直接解决这种情况,但 # https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-monitoring.md#streamable-hello-or-legacy-hello-command # 表示拓扑版本只能在成功更新 # hello 响应。 @topology_version = new_description.topology_version if new_description.topology_version 救援 IOError, SocketError, SystemCallError, mongo::错误 => e stop_requested = 锁.同步 { @stop_requested } if stop_requested # 忽略异常,请参阅 RUBY- 2771 。 return end msg = " Error 运行 awaited hello on #{ 服务器.address} " Utils.warn_bg_Exception(msg, e, 记录器: [:logger], log_prefix: [:log_prefix], bg_error_backtrace: [:bg_error_backtrace]) # 流媒体检查是权威 SDAM 来源,因此,失败 # 必须将服务器标记为 Unknown 并清空此处的池。流式传输时 # 活动的投票监控仅测量 RTT 并忽略错误 #(根据服务器监控规格),因此不再能依赖它来 # 注意失败。 监控.run_sdam_flow({}, scan_error: e, 等待: true) # 如果连接请求失败,则停止推送监控。 # 如果服务器死机,我们不希望有两个连接 # 同时尝试连接但未成功。 停止! # 请求立即检查监控以将其恢复为 # 尽快,以防服务器实际处于活动状态。 server.scan_semaphore.信号 end |
# read_response ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 190 def read_response if (超时 = [:connect_timeout]) if 超时 < 0 提高 mongo::SocketTimeoutError, ' 请求使用负超时读取: ' elsif 超时 > 0 超时 += [:heartbeat_Frequency] || 监控::DEFAULT_HEARTBEAT_INTERVAL end end # 我们设立超时设置两次:一次是传递给适用的 read_socket # 到每个单独的读取操作,然后再到整个读取。 超时.超时(超时, 错误::SocketTimeoutError, "未能在#{ timeout }秒内读取等待的 hello 响应") do 锁.同步 { @connection }.read_response(socket_timeout: 超时) end end |
# start! ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
62 63 64 65 66 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 62 def 开始! 锁.同步 do 超 end end |
# stop! ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 68 def 停止! 锁.同步 do @stop_requested = true if @connection # 中断任何正在进行的耗尽 hello 读取 # 断开连接。 开始 @connection.interrupt_socket 救援 StandardError nil end end end 超.点击 do 锁.同步 do if @connection @connection.断开连接! @connection = nil end end end end |
# to_s ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
206 207 208 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 206 def to_s " #< #{ self . class . name } : #{ object_id } #{ 服务器 .解决} > " end |
# write_check_command ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
179 180 181 182 183 184 185 186 187 188 |
# File 'lib/ Mongo/ 服务器/push_monitor.rb', line 179 def write_check_command 文档 = @check_document.合并(merge)( topologyVersion: topology_version.to_doc, maxAwaitTimeMS: 监控.heartbeat_interval * 1000 ) 命令 = protocol::消息.new( [ :exhaust_allowed ], {}, 文档.合并(merge)({ ' $db ' => Database::ADMIN }) ) 锁.同步 { @connection }.write_bytes(命令.序列化.to_s) end |