Class: Mongo::Srv::Monitor Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/mongo/srv/monitor.rb |
Overview
Periodically retrieves SRV records for the cluster’s SRV URI, and sets the cluster’s server list to the SRV lookup result.
If an error is encountered during SRV lookup or an SRV record is invalid or disallowed for security reasons, a warning is logged and monitoring continues.
Constant Summary
-
DEFAULT_TIMEOUT =
# File 'lib/mongo/srv/monitor.rb', line 3510
-
MIN_SCAN_INTERVAL =
# File 'lib/mongo/srv/monitor.rb', line 3360
::Mongo::Loggable
- Included
Class Method Summary
-
.new(cluster, **opts) ⇒ Monitor
constructor
Internal use only
Creates the SRV monitor.
Instance Attribute Summary
- #cluster readonly Internal use only
- #last_result ⇒ Srv::Result readonly Internal use only
- #options readonly Internal use only
::Mongo::BackgroundThread
- Included
Instance Method Summary
- #do_work private Internal use only
- #scan! private Internal use only
- #scan_interval private Internal use only
- #timeout private Internal use only
::Mongo::BackgroundThread
- Included
#run! | Start the background thread. |
#stop! | Stop the background thread and wait for to terminate for a reasonable amount of time. |
#do_work | Override this method to do the work in the background thread. |
#pre_stop | Override this method to perform additional signaling for the background thread to stop. |
#start!, | |
#wait_for_stop | Waits for the thread to die, with a timeout. |
::Mongo::Loggable
- Included
#log_debug | Convenience method to log debug messages with the standard prefix. |
#log_error | Convenience method to log error messages with the standard prefix. |
#log_fatal | Convenience method to log fatal messages with the standard prefix. |
#log_info | Convenience method to log info messages with the standard prefix. |
#log_warn | Convenience method to log warn messages with the standard prefix. |
#logger | Get the logger instance. |
#_mongo_log_prefix, #format_message |
Instance Attribute Details
#cluster (readonly)
[ GitHub ]# File 'lib/mongo/srv/monitor.rb', line 58
attr_reader :cluster
#last_result ⇒ Srv::Result (readonly)
# File 'lib/mongo/srv/monitor.rb', line 63
attr_reader :last_result
#options (readonly)
[ GitHub ]# File 'lib/mongo/srv/monitor.rb', line 56
attr_reader :
Instance Method Details
#do_work (private)
[ GitHub ]# File 'lib/mongo/srv/monitor.rb', line 67
def do_work scan! @stop_semaphore.wait(scan_interval) end
#scan! (private)
[ GitHub ]# File 'lib/mongo/srv/monitor.rb', line 72
def scan! begin last_result = Timeout.timeout(timeout) do @resolver.get_records(@srv_uri.query_hostname) end rescue Resolv::ResolvTimeout => e log_warn("SRV monitor: timed out trying to resolve hostname #{@srv_uri.query_hostname}: #{e.class}: #{e}") return rescue ::Timeout::Error log_warn("SRV monitor: timed out trying to resolve hostname #{@srv_uri.query_hostname} (timeout=#{timeout})") return rescue Resolv::ResolvError => e log_warn("SRV monitor: unable to resolve hostname #{@srv_uri.query_hostname}: #{e.class}: #{e}") return end if last_result.empty? log_warn("SRV monitor: hostname #{@srv_uri.query_hostname} resolved to zero records") return end @cluster.set_server_list(last_result.address_strs) end
#scan_interval (private)
[ GitHub ]# File 'lib/mongo/srv/monitor.rb', line 96
def scan_interval if last_result.empty? [cluster.heartbeat_interval, MIN_SCAN_INTERVAL].min elsif last_result.min_ttl.nil? MIN_SCAN_INTERVAL else [last_result.min_ttl, MIN_SCAN_INTERVAL].max end end
#timeout (private)
[ GitHub ]# File 'lib/mongo/srv/monitor.rb', line 106
def timeout [:timeout] || DEFAULT_TIMEOUT end