RUBY-416 fixes for current thread manager state

This commit is contained in:
Tyler Brock 2012-03-06 22:20:28 -05:00
parent 68f19039d2
commit 03eb8a8c96
2 changed files with 20 additions and 14 deletions

View File

@ -508,8 +508,8 @@ module Mongo
# Check a socket back into its pool. # Check a socket back into its pool.
def checkin(socket) def checkin(socket)
if @primary_pool if @primary_pool && socket
@primary_pool.checkin(socket) socket.pool.checkin(socket)
end end
end end

View File

@ -149,6 +149,7 @@ module Mongo
discovered_seeds = @manager ? @manager.seeds : [] discovered_seeds = @manager ? @manager.seeds : []
@manager = PoolManager.new(self, discovered_seeds) @manager = PoolManager.new(self, discovered_seeds)
Thread.current[:manager] = @manager Thread.current[:manager] = @manager
@manager.connect @manager.connect
@ -202,6 +203,8 @@ module Mongo
new_manager = PoolManager.new(self, discovered_seeds | @seeds) new_manager = PoolManager.new(self, discovered_seeds | @seeds)
new_manager.connect new_manager.connect
Thread.current[:manager] = new_manager
# TODO: make sure that connect has succeeded # TODO: make sure that connect has succeeded
@old_managers << @manager @old_managers << @manager
@manager = new_manager @manager = new_manager
@ -284,15 +287,15 @@ module Mongo
end end
def authenticate_pools def authenticate_pools
self.primary_pool.authenticate_existing primary_pool.authenticate_existing
self.secondary_pools.each do |pool| secondary_pools.each do |pool|
pool.authenticate_existing pool.authenticate_existing
end end
end end
def logout_pools(db) def logout_pools(db)
self.primary_pool.logout_existing(db) primary_pool.logout_existing(db)
self.secondary_pools.each do |pool| secondary_pools.each do |pool|
pool.logout_existing(db) pool.logout_existing(db)
end end
end end
@ -317,7 +320,7 @@ module Mongo
socket socket
else else
@connected = false @connected = false
raise ConnectionFailure.new("Could not checkout a socket") raise ConnectionFailure.new("Could not checkout a socket.")
end end
end end
@ -352,13 +355,17 @@ module Mongo
# Checkin a socket used for reading. # Checkin a socket used for reading.
def checkin_reader(socket) def checkin_reader(socket)
if socket && socket.pool
socket.pool.checkin(socket) socket.pool.checkin(socket)
end
sync_refresh sync_refresh
end end
# Checkin a socket used for writing. # Checkin a socket used for writing.
def checkin_writer(socket) def checkin_writer(socket)
if socket && socket.pool
socket.pool.checkin(socket) socket.pool.checkin(socket)
end
sync_refresh sync_refresh
end end
@ -386,8 +393,7 @@ module Mongo
begin begin
if pool if pool
socket = pool.checkout pool.checkout
socket
end end
rescue ConnectionFailure => ex rescue ConnectionFailure => ex
log(:info, "Failed to checkout from #{pool} with #{ex.class}; #{ex.message}") log(:info, "Failed to checkout from #{pool} with #{ex.class}; #{ex.message}")
@ -525,8 +531,8 @@ module Mongo
if @refresh_mutex.try_lock if @refresh_mutex.try_lock
begin begin
prune_managers
refresh refresh
prune_managers
ensure ensure
@refresh_mutex.unlock @refresh_mutex.unlock
end end