Added thread-local sockets to ReplSetConnection
This commit is contained in:
parent
54433502f5
commit
01d1231373
@ -304,33 +304,36 @@ module Mongo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_local_reader
|
def get_local_reader
|
||||||
Thread.current[:connections] ||= {}
|
self.connections ||= {}
|
||||||
Thread.current[:connections][self.object_id] ||= {}
|
self.connections[self.object_id] ||= {}
|
||||||
Thread.current[:connections][self.object_id][:version] ||= self.refresh_version
|
self.connections[self.object_id][:reader] ||= checkout_reader
|
||||||
Thread.current[:connections][self.object_id][:reader] ||= checkout_reader
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_local_writer
|
def get_local_writer
|
||||||
Thread.current[:connections] ||= {}
|
self.connections ||= {}
|
||||||
Thread.current[:connections][self.object_id] ||= {}
|
self.connections[self.object_id] ||= {}
|
||||||
Thread.current[:connections][self.object_id][:version] ||= self.refresh_version
|
self.connections[self.object_id][:writer] ||= checkout_writer
|
||||||
Thread.current[:connections][self.object_id][:writer] ||= checkout_writer
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Used to close, check in, or refresh sockets held
|
# Used to close, check in, or refresh sockets held
|
||||||
# in thread-local variables.
|
# in thread-local variables.
|
||||||
def local_socket_done
|
def local_socket_done(socket)
|
||||||
if Thread.current[:connections][self.object_id][:version] != self.refresh_version
|
puts "Done. Threads: #{Thread.list.size}, pool_size: #{self.pool_size}"
|
||||||
checkin(Thread.current[:connections][self.object_id][:reader])
|
if self.connections[self.object_id][:reader] == socket
|
||||||
Thread.current[:connections][self.object_id][:reader] ||= checkout_reader
|
if self.read_pool.sockets_low?
|
||||||
end
|
puts "***SOCKETS ARE LOW! READER****"
|
||||||
end
|
checkin(socket)
|
||||||
|
self.connections[self.object_id][:reader] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def checkin_sockets
|
if self.connections[self.object_id][:writer] == socket
|
||||||
checkin(Thread.current[:connections][self.object_id][:reader])
|
if self.primary_pool && self.primary_pool.sockets_low?
|
||||||
checkin(Thread.current[:connections][self.object_id][:writer])
|
puts "***SOCKETS ARE LOW! WRITER****"
|
||||||
Thread.current[:connections][self.object_id][:writer] = nil
|
checkin(socket)
|
||||||
Thread.current[:connections][self.object_id][:reader] = nil
|
self.connections[self.object_id][:writer] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checkout a socket for reading (i.e., a secondary node).
|
# Checkout a socket for reading (i.e., a secondary node).
|
||||||
|
Loading…
Reference in New Issue
Block a user