lib/mongo/cluster.rb in mongo-2.15.0.alpha vs lib/mongo/cluster.rb in mongo-2.15.0

- old
+ new

@@ -1,5 +1,8 @@ +# frozen_string_literal: true +# encoding: utf-8 + # Copyright (C) 2014-2020 MongoDB Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -102,11 +105,11 @@ # Set to false to prevent endSessions command being sent to the server # to clean up server sessions when the cluster is disconnected, and to # to not start the periodic executor. If :monitoring_io is false, # :cleanup automatically defaults to false as well. # @option options [ Float ] :heartbeat_frequency The interval, in seconds, - # for the server monitor to refresh its description via ismaster. + # for the server monitor to refresh its description via hello. # @option options [ Hash ] :resolv_options For internal driver use only. # Options to pass through to Resolv::DNS constructor for SRV lookups. # @option options [ Hash ] :server_api The requested server API version. # This hash can have the following items: # - *:version* -- string @@ -208,11 +211,11 @@ @periodic_executor.run! end # Need to record start time prior to starting monitoring - start_time = Time.now + start_monotime = Utils.monotonic_time servers.each do |server| server.start_monitoring end @@ -224,25 +227,25 @@ # then aborts the scan before it can process even local servers. # Therefore, allow at least 3 seconds for the scan here. if server_selection_timeout < 3 server_selection_timeout = 3 end - deadline = start_time + server_selection_timeout + deadline = start_monotime + server_selection_timeout # Wait for the first scan of each server to complete, for # backwards compatibility. # If any servers are discovered during this SDAM round we are going to # wait for these servers to also be queried, and so on, up to the # server selection timeout or the 3 second minimum. loop do # Ensure we do not try to read the servers list while SDAM is running servers = @sdam_flow_lock.synchronize do servers_list.dup end - if servers.all? { |server| server.last_scan && server.last_scan >= start_time } + if servers.all? { |server| server.last_scan_monotime && server.last_scan_monotime >= start_monotime } break end - if (time_remaining = deadline - Time.now) <= 0 + if (time_remaining = deadline - Utils.monotonic_time) <= 0 break end log_debug("Waiting for up to #{'%.2f' % time_remaining} seconds for servers to be scanned: #{summary}") # Since the semaphore may have been signaled between us checking # the servers list above and the wait call below, we should not @@ -593,11 +596,11 @@ # new server description is unknown, the connection pool on the # respective server is cleared. Set this option to true to keep the # existing connection pool (required when handling not master errors # on 4.2+ servers). # @option aptions [ true | false ] :awaited Whether the updated description - # was a result of processing an awaited ismaster. + # was a result of processing an awaited hello. # # @api private def run_sdam_flow(previous_desc, updated_desc, options = {}) @sdam_flow_lock.synchronize do flow = SdamFlow.new(self, previous_desc, updated_desc, @@ -760,10 +763,10 @@ end end end # Add a server to the cluster with the provided address. Useful in - # auto-discovery of new servers when an existing server executes an ismaster + # auto-discovery of new servers when an existing server executes a hello # and potentially non-configured servers were included. # # @example Add the server for the address to the cluster. # cluster.add('127.0.0.1:27018') #