@@ -56,11 +56,10 @@ class ReplSetConnection < Connection
56
56
# @option opts [Float] :connect_timeout (nil) The number of seconds to wait before timing out a
57
57
# connection attempt.
58
58
# @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.
64
63
# @option opts [Integer] :refresh_interval (90) If :refresh_mode is enabled, this is the number of seconds
65
64
# between calls to check the replica set's state.
66
65
# @option opts [Boolean] :require_primary (true) If true, require a primary node for the connection
@@ -107,9 +106,12 @@ def initialize(*args)
107
106
@manager = nil
108
107
@pool_mutex = Mutex . new
109
108
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 )
111
113
raise MongoArgumentError ,
112
- "Refresh mode must be one of :sync, :async, or false."
114
+ "Refresh mode must be either :sync or false."
113
115
end
114
116
115
117
# Are we allowing reads from secondaries?
@@ -124,15 +126,8 @@ def initialize(*args)
124
126
end
125
127
126
128
@connected = false
127
-
128
- # Store the refresher thread
129
- @refresh_thread = nil
130
129
@refresh_version = 0
131
130
132
- # Maps
133
- @threads_to_sockets = Hash . new { |h , k | h [ k ] = Hash . new }
134
- @tag_map = nil
135
-
136
131
# Replica set name
137
132
if opts [ :rs_name ]
138
133
warn ":rs_name option has been deprecated and will be removed in v2.0. " +
@@ -161,7 +156,6 @@ def connect
161
156
manager . connect
162
157
163
158
update_config ( manager )
164
- initiate_refresh_mode
165
159
166
160
if @require_primary && self . primary . nil? #TODO: in v2.0, we'll let this be optional and do a lazy connect.
167
161
close
@@ -213,7 +207,6 @@ def hard_refresh!
213
207
old_manager = @manager
214
208
update_config ( background_manager )
215
209
old_manager . close ( :soft => true )
216
- initiate_refresh_mode
217
210
218
211
return true
219
212
end
@@ -265,7 +258,6 @@ def read_preference
265
258
def close
266
259
@connected = false
267
260
@manager . close ( :soft => true ) if @manager
268
- @threads_to_sockets . clear
269
261
end
270
262
271
263
# If a ConnectionFailure is raised, this method will be called
@@ -470,6 +462,8 @@ def setup(opts)
470
462
write_logging_startup_message
471
463
end
472
464
465
+ @last_refresh = Time . now
466
+
473
467
should_connect = opts . fetch ( :connect , true )
474
468
connect if should_connect
475
469
end
@@ -482,24 +476,6 @@ def update_config(new_manager)
482
476
@refresh_version += 1
483
477
end
484
478
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
-
503
479
# Checkout a socket connected to a node with one of
504
480
# the provided tags. If no such node exists, raise
505
481
# an exception.
0 commit comments