@@ -56,11 +56,10 @@ class ReplSetConnection < Connection
5656 # @option opts [Float] :connect_timeout (nil) The number of seconds to wait before timing out a
5757 # connection attempt.
5858 # @option opts [Boolean] :ssl (false) If true, create the connection to the server using SSL.
59- # @option opts [Boolean] :refresh_mode (false) Set this to :async to enable a background thread that
60- # periodically updates the state of the connection. If, for example, you initially connect while a secondary
61- # is down, this will reconnect to that secondary behind the scenes to
62- # prevent you from having to reconnect manually. If set to :sync, refresh will happen
63- # synchronously. If +false+, no automatic refresh will occur unless there's a connection failure.
59+ # @option opts [Boolean] :refresh_mode (false) Set this to :sync to periodically update the
60+ # state of the connection every :refresh_interval seconds. Replica set connection failures
61+ # will always trigger a complete refresh. This option is useful when you want to add new nodes
62+ # or remove replica set nodes not currently in use by the driver.
6463 # @option opts [Integer] :refresh_interval (90) If :refresh_mode is enabled, this is the number of seconds
6564 # between calls to check the replica set's state.
6665 # @option opts [Boolean] :require_primary (true) If true, require a primary node for the connection
@@ -107,9 +106,12 @@ def initialize(*args)
107106 @manager = nil
108107 @pool_mutex = Mutex . new
109108
110- if ![ :sync , :async , false ] . include? ( @refresh_mode )
109+ if @refresh_mode == :async
110+ warn ":async refresh mode has been deprecated. Refresh
111+ mode will be disabled."
112+ elsif ![ :sync , false ] . include? ( @refresh_mode )
111113 raise MongoArgumentError ,
112- "Refresh mode must be one of :sync, :async, or false."
114+ "Refresh mode must be either :sync or false."
113115 end
114116
115117 # Are we allowing reads from secondaries?
@@ -124,15 +126,8 @@ def initialize(*args)
124126 end
125127
126128 @connected = false
127-
128- # Store the refresher thread
129- @refresh_thread = nil
130129 @refresh_version = 0
131130
132- # Maps
133- @threads_to_sockets = Hash . new { |h , k | h [ k ] = Hash . new }
134- @tag_map = nil
135-
136131 # Replica set name
137132 if opts [ :rs_name ]
138133 warn ":rs_name option has been deprecated and will be removed in v2.0. " +
@@ -161,7 +156,6 @@ def connect
161156 manager . connect
162157
163158 update_config ( manager )
164- initiate_refresh_mode
165159
166160 if @require_primary && self . primary . nil? #TODO: in v2.0, we'll let this be optional and do a lazy connect.
167161 close
@@ -213,7 +207,6 @@ def hard_refresh!
213207 old_manager = @manager
214208 update_config ( background_manager )
215209 old_manager . close ( :soft => true )
216- initiate_refresh_mode
217210
218211 return true
219212 end
@@ -265,7 +258,6 @@ def read_preference
265258 def close
266259 @connected = false
267260 @manager . close ( :soft => true ) if @manager
268- @threads_to_sockets . clear
269261 end
270262
271263 # If a ConnectionFailure is raised, this method will be called
@@ -470,6 +462,8 @@ def setup(opts)
470462 write_logging_startup_message
471463 end
472464
465+ @last_refresh = Time . now
466+
473467 should_connect = opts . fetch ( :connect , true )
474468 connect if should_connect
475469 end
@@ -482,24 +476,6 @@ def update_config(new_manager)
482476 @refresh_version += 1
483477 end
484478
485- # If we're using async refresh, start
486- # a background thread to run the refresh method
487- # every @refresh_interval seconds.
488- def initiate_refresh_mode
489- if @refresh_mode == :async
490- return if @refresh_thread && @refresh_thread . alive?
491- @refresh_thread = Thread . new do
492- while true do
493- sleep ( @refresh_interval )
494- refresh
495- end
496- end
497- @refresh_thread . priority = 1000
498- end
499-
500- @last_refresh = Time . now
501- end
502-
503479 # Checkout a socket connected to a node with one of
504480 # the provided tags. If no such node exists, raise
505481 # an exception.
0 commit comments