Fixed threaded replica set reconnection.

This commit is contained in:
Kyle Banker 2012-02-27 17:11:14 -05:00
parent 6301a41254
commit ebfe279784
2 changed files with 31 additions and 22 deletions

View File

@ -123,6 +123,8 @@ module Mongo
@safe_mutex_lock = Mutex.new
@safe_mutexes = Hash.new {|hash, key| hash[key] = Mutex.new}
@connect_mutex = Mutex.new
check_opts(opts)
setup(opts)
end
@ -139,6 +141,7 @@ module Mongo
# Initiate a connection to the replica set.
def connect
log(:info, "Connecting...")
@connect_mutex.synchronize do
return if @connected
discovered_seeds = @manager ? @manager.seeds : []
@ -157,6 +160,7 @@ module Mongo
@connected = true
end
end
end
# Determine whether a replica set refresh is
# required. If so, run a hard refresh. You can
@ -312,6 +316,7 @@ module Mongo
if socket
socket
else
@connected = false
raise ConnectionFailure.new("Could not connect to a node for reading.")
end
end
@ -332,6 +337,7 @@ module Mongo
if socket
socket
else
@connected = false
raise ConnectionFailure.new("Could not connect to a secondary for reading.")
end
end
@ -358,6 +364,7 @@ module Mongo
if socket
socket
else
@connected = false
raise ConnectionFailure.new("Could not connect to primary node.")
end
end
@ -507,6 +514,7 @@ module Mongo
end
def sync_refresh
@connect_mutex.synchronize do
if @refresh_mode == :sync &&
((Time.now - @last_refresh) > @refresh_interval)
@last_refresh = Time.now
@ -515,3 +523,4 @@ module Mongo
end
end
end
end

View File

@ -7,7 +7,7 @@ class ReplicaSetPooledInsertTest < Test::Unit::TestCase
def setup
ensure_rs
@conn = ReplSetConnection.new(build_seeds(3), :pool_size => 5, :timeout => 5, :refresh_mode => false)
@conn = ReplSetConnection.new(build_seeds(3), :pool_size => 10, :timeout => 5, :refresh_mode => false)
@db = @conn.db(MONGO_TEST_DB)
@db.drop_collection("test-sets")
@coll = @db.collection("test-sets")