Skip to content

Commit

Permalink
fix(connection) synchronize agents pool
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Oct 2, 2013
1 parent a9f5953 commit bd21a92
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/sphinx/integration/mysql/connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ def self.master_pool
end

def self.agents_pool(agent_name)
@agents_pool ||= {}
@agents_pool[agent_name] ||= Innertube::Pool.new(
Proc.new { Sphinx::Integration::Mysql::ConnectionPool.slave_connection(agent_name) },
Proc.new { |connection| connection.close }
)
return @agents_pool[agent_name] if @agents_pool.key?(agent_name)

@take_slaves_mutex.synchronize do
return @agents_pool[agent_name] if @agents_pool.key?(agent_name)

@agents_pool[agent_name] ||= Innertube::Pool.new(
Proc.new { Sphinx::Integration::Mysql::ConnectionPool.slave_connection(agent_name) },
Proc.new { |connection| connection.close }
)
end
end

def self.take
Expand All @@ -79,6 +84,9 @@ def self.take
end

def self.take_slaves(silent = true)
@take_slaves_mutex ||= Mutex.new
@agents_pool ||= {}

threads = []

ThinkingSphinx::Configuration.instance.agents.each do |agent_name, _|
Expand Down

0 comments on commit bd21a92

Please sign in to comment.