Skip to content

Commit

Permalink
don't create extra connections when host flickers
Browse files Browse the repository at this point in the history
  • Loading branch information
Bulat Shakirzyanov committed Jan 20, 2015
1 parent 05aa156 commit 4fb7d10
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/cassandra/cluster/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def host_up(host)
return Ione::Future.resolved
end

@pending_connections[host] = 0
@pending_connections[host] ||= 0
@prepared_statements[host] = {}
@preparing_statements[host] = {}
@connections[host] = ConnectionPool.new
Expand All @@ -173,7 +173,7 @@ def host_down(host)
synchronize do
return Ione::Future.resolved unless @connections.has_key?(host)

@pending_connections.delete(host)
@pending_connections.delete(host) unless @pending_connections[host] > 0
@prepared_statements.delete(host)
@preparing_statements.delete(host)
pool = @connections.delete(host)
Expand Down Expand Up @@ -383,9 +383,12 @@ def connect_to_host(host, pool_size)
pool = nil

synchronize do
@pending_connections[host] -= size

if @connections.include?(host)
@pending_connections[host] -= size
pool = @connections[host]
else
@pending_connections.delete(host) unless @pending_connections[host] > 0
end
end

Expand All @@ -404,9 +407,8 @@ def connect_to_host(host, pool_size)

f.on_failure do |error|
synchronize do
if @connections.include?(host)
@pending_connections[host] -= size
end
@pending_connections[host] -= size
@pending_connections.delete(host) unless @pending_connections[host] > 0 || @connections.include?(host)
end
end

Expand Down

0 comments on commit 4fb7d10

Please sign in to comment.