From 4fb7d105cf7d74521ecbedc75139d4f97e45f89a Mon Sep 17 00:00:00 2001 From: Bulat Shakirzyanov Date: Tue, 20 Jan 2015 12:50:21 -0800 Subject: [PATCH] don't create extra connections when host flickers --- lib/cassandra/cluster/client.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/cassandra/cluster/client.rb b/lib/cassandra/cluster/client.rb index 615508a43..e985d8f07 100644 --- a/lib/cassandra/cluster/client.rb +++ b/lib/cassandra/cluster/client.rb @@ -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 @@ -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) @@ -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 @@ -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