lib/mongo/mongo_sharded_client.rb in mongo-1.8.5 vs lib/mongo/mongo_sharded_client.rb in mongo-1.8.6
- old
+ new
@@ -39,18 +39,13 @@
@manager = nil
# Lock for request ids.
@id_lock = Mutex.new
- @pool_mutex = Mutex.new
@connected = false
- @safe_mutex_lock = Mutex.new
- @safe_mutexes = Hash.new {|hash, key| hash[key] = Mutex.new}
-
@connect_mutex = Mutex.new
- @refresh_mutex = Mutex.new
@mongos = true
check_opts(opts)
setup(opts)
@@ -64,11 +59,11 @@
"<Mongo::MongoShardedClient:0x#{self.object_id.to_s(16)} @seeds=#{@seeds.inspect} " +
"@connected=#{@connected}>"
end
# Initiate a connection to the sharded cluster.
- def connect(force = !@connected)
+ def connect(force = !connected?)
return unless force
log(:info, "Connecting...")
# Prevent recursive connection attempts from the same thread.
# This is done rather than using a Monitor to prevent potentially recursing
@@ -77,14 +72,15 @@
@connect_mutex.synchronize do
begin
thread_local[:locks][:connecting] = true
if @manager
+ thread_local[:managers][self] = @manager
@manager.refresh! @seeds
else
@manager = ShardingPoolManager.new(self, @seeds)
- thread_local[:managers][self] = @manager
+ ensure_manager
@manager.connect
end
ensure
thread_local[:locks][:connecting] = false
end
@@ -106,11 +102,11 @@
connect(true)
return true
end
def connected?
- @connected && @manager.primary_pool
+ !!(@connected && @manager.primary_pool)
end
# Returns +true+ if it's okay to read from a secondary node.
# Since this is a sharded cluster, this must always be false.
#
@@ -138,10 +134,11 @@
# mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]
#
# @param opts [ Hash ] Any of the options available for MongoShardedClient.new
#
# @return [ Mongo::MongoShardedClient ] The sharded client.
- def self.from_uri(uri = ENV['MONGODB_URI'], options = {})
+ def self.from_uri(uri, options = {})
+ uri ||= ENV['MONGODB_URI']
URIParser.new(uri).connection(options, false, true)
end
end
end