RUBY-444 keep multiple replica set connections separate
This commit is contained in:
parent
3e04550e34
commit
5591e3dfe3
@ -25,7 +25,7 @@ module Mongo
|
|||||||
:read_secondary, :rs_name, :name]
|
:read_secondary, :rs_name, :name]
|
||||||
|
|
||||||
attr_reader :replica_set_name, :seeds, :refresh_interval, :refresh_mode,
|
attr_reader :replica_set_name, :seeds, :refresh_interval, :refresh_mode,
|
||||||
:refresh_version
|
:refresh_version, :manager
|
||||||
|
|
||||||
# Create a connection to a MongoDB replica set.
|
# Create a connection to a MongoDB replica set.
|
||||||
#
|
#
|
||||||
@ -150,7 +150,8 @@ 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[:managers] ||= Hash.new
|
||||||
|
Thread.current[:managers][self] = @manager
|
||||||
|
|
||||||
@manager.connect
|
@manager.connect
|
||||||
@refresh_version += 1
|
@refresh_version += 1
|
||||||
@ -203,7 +204,7 @@ 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
|
Thread.current[:managers][self] = new_manager
|
||||||
|
|
||||||
# TODO: make sure that connect has succeeded
|
# TODO: make sure that connect has succeeded
|
||||||
@old_managers << @manager
|
@old_managers << @manager
|
||||||
@ -263,6 +264,12 @@ module Mongo
|
|||||||
else
|
else
|
||||||
@manager.close if @manager
|
@manager.close if @manager
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clear the reference to this object.
|
||||||
|
if Thread.current[:managers]
|
||||||
|
Thread.current[:managers].delete(self)
|
||||||
|
end
|
||||||
|
|
||||||
@connected = false
|
@connected = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -395,8 +402,8 @@ module Mongo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_socket_from_pool(pool_type)
|
def get_socket_from_pool(pool_type)
|
||||||
if Thread.current[:manager] != @manager
|
if Thread.current[:managers][self] != @manager
|
||||||
Thread.current[:manager] = @manager
|
Thread.current[:managers][self] = @manager
|
||||||
end
|
end
|
||||||
|
|
||||||
pool = case pool_type
|
pool = case pool_type
|
||||||
@ -419,7 +426,7 @@ module Mongo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def local_manager
|
def local_manager
|
||||||
Thread.current[:manager]
|
Thread.current[:managers][self]
|
||||||
end
|
end
|
||||||
|
|
||||||
def arbiters
|
def arbiters
|
||||||
|
@ -25,6 +25,16 @@ class BasicTest < Test::Unit::TestCase
|
|||||||
assert @conn.connected?
|
assert @conn.connected?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_multiple_concurrent_replica_set_connection
|
||||||
|
@conn1 = ReplSetConnection.new(build_seeds(3), :name => @rs.name)
|
||||||
|
@conn2 = ReplSetConnection.new(build_seeds(3), :name => @rs.name)
|
||||||
|
assert @conn1.connected?
|
||||||
|
assert @conn2.connected?
|
||||||
|
|
||||||
|
assert @conn1.manager != @conn2.manager
|
||||||
|
assert @conn1.local_manager != @conn2.local_manager
|
||||||
|
end
|
||||||
|
|
||||||
def test_cache_original_seed_nodes
|
def test_cache_original_seed_nodes
|
||||||
seeds = build_seeds(3) << "#{@rs.host}:19356"
|
seeds = build_seeds(3) << "#{@rs.host}:19356"
|
||||||
@conn = ReplSetConnection.new(seeds, :name => @rs.name)
|
@conn = ReplSetConnection.new(seeds, :name => @rs.name)
|
||||||
|
Loading…
Reference in New Issue
Block a user