From 220942f650f6eab4817d37b0b58e253a0e548086 Mon Sep 17 00:00:00 2001 From: Bulat Shakirzyanov Date: Sat, 4 Oct 2014 13:40:34 -0700 Subject: [PATCH] [CASSANDRA-7825] skip ghost nodes in system.peers table --- lib/cassandra/cluster/control_connection.rb | 4 +- .../cluster/control_connection_spec.rb | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/cassandra/cluster/control_connection.rb b/lib/cassandra/cluster/control_connection.rb index d9ca9b1d2..6d9285eca 100644 --- a/lib/cassandra/cluster/control_connection.rb +++ b/lib/cassandra/cluster/control_connection.rb @@ -277,7 +277,9 @@ def refresh_hosts_async ips = ::Set.new peers.each do |data| - ips << ip = peer_ip(data) + ip = peer_ip(data) + next unless ip + ips << ip @registry.host_found(ip, data) end diff --git a/spec/cassandra/cluster/control_connection_spec.rb b/spec/cassandra/cluster/control_connection_spec.rb index 7d7038bb7..d82625ec8 100644 --- a/spec/cassandra/cluster/control_connection_spec.rb +++ b/spec/cassandra/cluster/control_connection_spec.rb @@ -300,6 +300,46 @@ def handle_request(&handler) end end + context 'with empty peers' do + it 'skips empty peers' do + additional_rpc_addresses = additional_nodes.dup + + handle_request do |request| + case request + when Protocol::QueryRequest + case request.cql + when /FROM system\.peers/ + rows = min_peers[0].times.map do |host_id| + ip = additional_rpc_addresses.shift + { + 'peer' => ip, + 'rack' => racks[ip], + 'data_center' => data_centers[ip], + 'host_id' => host_ids[ip], + 'rpc_address' => bind_all_rpc_addresses ? IPAddr.new('0.0.0.0') : ip, + 'release_version' => release_versions[ip] + } + end + + rows << { + 'peer' => nil, + 'rack' => nil, + 'data_center' => nil, + 'host_id' => nil, + 'rpc_address' => nil, + 'release_version' => nil + } + Protocol::RowsResultResponse.new(rows, peer_metadata, nil, nil) + end + end + end + + control_connection.connect_async.value + + expect(cluster_registry).to have(3).hosts + end + end + context 'with logging' do it 'logs when fetching cluster state' do logger.stub(:debug)