123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Srv::Monitor Private

Do not use. This class is for internal use only.
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

::Mongo::Loggable - Included

PREFIX

Class Method Summary

Instance Attribute Summary

::Mongo::BackgroundThread - Included

Instance Method Summary

::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_resultSrv::Result (readonly)

Returns:

  • (Srv::Result)

    Last known SRV lookup result. Used for determining intervals between SRV lookups, which depend on SRV DNS records’ TTL values.

[ GitHub ]

  
# 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 :options

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
  options[:timeout] || DEFAULT_TIMEOUT
end