RUBY-416 fixes for current thread manager state
This commit is contained in:
parent
68f19039d2
commit
03eb8a8c96
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
@ -200,7 +201,9 @@ module Mongo
|
|||||||
log(:info, "Initiating hard refresh...")
|
log(:info, "Initiating hard refresh...")
|
||||||
discovered_seeds = @manager ? @manager.seeds : []
|
discovered_seeds = @manager ? @manager.seeds : []
|
||||||
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
|
||||||
@ -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)
|
||||||
socket.pool.checkin(socket)
|
if socket && socket.pool
|
||||||
|
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)
|
||||||
socket.pool.checkin(socket)
|
if socket && socket.pool
|
||||||
|
socket.pool.checkin(socket)
|
||||||
|
end
|
||||||
sync_refresh
|
sync_refresh
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -374,7 +381,7 @@ module Mongo
|
|||||||
if Thread.current[:manager] != @manager
|
if Thread.current[:manager] != @manager
|
||||||
Thread.current[:manager] = @manager
|
Thread.current[:manager] = @manager
|
||||||
end
|
end
|
||||||
|
|
||||||
pool = case pool_type
|
pool = case pool_type
|
||||||
when :primary
|
when :primary
|
||||||
primary_pool
|
primary_pool
|
||||||
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user