minor: cleanup

This commit is contained in:
Kyle Banker 2011-11-04 13:25:13 -04:00
parent a2a307c45d
commit f224df45aa
2 changed files with 21 additions and 41 deletions

View File

@ -308,34 +308,37 @@ module Mongo
def get_local_reader def get_local_reader
self.connections ||= {} self.connections ||= {}
self.connections[self.object_id] ||= {} self.connections[self.object_id] ||= {}
self.connections[self.object_id][:reader] ||= checkout_reader socket = self.connections[self.object_id][:reader] ||= checkout_reader
threads_to_sockets[Thread.current] ||= {}
threads_to_sockets[Thread.current][:reader] = socket
end end
def get_local_writer def get_local_writer
self.connections ||= {} self.connections ||= {}
self.connections[self.object_id] ||= {} self.connections[self.object_id] ||= {}
self.connections[self.object_id][:writer] ||= checkout_writer self.connections[self.object_id][:writer] ||= checkout_writer
threads_to_sockets[Thread.current] ||= {}
threads_to_sockets[Thread.current][:reader] = socket
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(socket) def local_socket_done(socket)
puts "Done. Threads: #{Thread.list.size}, pool_size: #{self.pool_size}" if self.connections[self.object_id][:reader] == socket
if self.connections[self.object_id][:reader] == socket if self.read_pool.sockets_low? ||
if self.read_pool.sockets_low? self.read_pool != @sockets_to_pools[socket]
puts "***SOCKETS ARE LOW! READER****" checkin(socket)
checkin(socket) self.connections[self.object_id][:reader] = nil
self.connections[self.object_id][:reader] = nil end
end end
end
if self.connections[self.object_id][:writer] == socket if self.connections[self.object_id][:writer] == socket
if self.primary_pool && self.primary_pool.sockets_low? if self.primary_pool && (self.primary_pool.sockets_low? ||
puts "***SOCKETS ARE LOW! WRITER****" self.primary_pool != @sockets_to_pools[socket])
checkin(socket) checkin(socket)
self.connections[self.object_id][:writer] = nil self.connections[self.object_id][:writer] = nil
end end
end end
end end
# Checkout a socket for reading (i.e., a secondary node). # Checkout a socket for reading (i.e., a secondary node).
@ -384,6 +387,8 @@ module Mongo
close_socket(socket) close_socket(socket)
end end
@sockets_to_pools.delete(socket)
# Refresh synchronously every @refresh_interval seconds # Refresh synchronously every @refresh_interval seconds
# if synchronous refresh mode is enabled. # if synchronous refresh mode is enabled.
if @refresh_mode == :sync && if @refresh_mode == :sync &&

View File

@ -235,31 +235,6 @@ module Mongo
end end
end end
def cleanup
return unless @sockets.size > @size
puts "-----CLEANUP*****"
alive = {}
Thread.list.each do |t|
if t.alive?
alive[t.object_id] = true
end
end
@checked_out.each do |socket|
if !alive[@threads[socket]]
@checked_out.delete(socket)
if @sockets.size > @size
puts "CLEANING: #{socket}"
socket.close
@sockets.delete(socket)
end
end
end
end
# Check out an existing socket or create a new socket if the maximum # Check out an existing socket or create a new socket if the maximum
# pool size has not been exceeded. Otherwise, wait for the next # pool size has not been exceeded. Otherwise, wait for the next
# available socket. # available socket.