Skip to content

Commit 220942f

Browse files
author
Bulat Shakirzyanov
committed
[CASSANDRA-7825] skip ghost nodes in system.peers table
1 parent d472834 commit 220942f

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/cassandra/cluster/control_connection.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ def refresh_hosts_async
277277
ips = ::Set.new
278278

279279
peers.each do |data|
280-
ips << ip = peer_ip(data)
280+
ip = peer_ip(data)
281+
next unless ip
282+
ips << ip
281283
@registry.host_found(ip, data)
282284
end
283285

spec/cassandra/cluster/control_connection_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,46 @@ def handle_request(&handler)
300300
end
301301
end
302302

303+
context 'with empty peers' do
304+
it 'skips empty peers' do
305+
additional_rpc_addresses = additional_nodes.dup
306+
307+
handle_request do |request|
308+
case request
309+
when Protocol::QueryRequest
310+
case request.cql
311+
when /FROM system\.peers/
312+
rows = min_peers[0].times.map do |host_id|
313+
ip = additional_rpc_addresses.shift
314+
{
315+
'peer' => ip,
316+
'rack' => racks[ip],
317+
'data_center' => data_centers[ip],
318+
'host_id' => host_ids[ip],
319+
'rpc_address' => bind_all_rpc_addresses ? IPAddr.new('0.0.0.0') : ip,
320+
'release_version' => release_versions[ip]
321+
}
322+
end
323+
324+
rows << {
325+
'peer' => nil,
326+
'rack' => nil,
327+
'data_center' => nil,
328+
'host_id' => nil,
329+
'rpc_address' => nil,
330+
'release_version' => nil
331+
}
332+
Protocol::RowsResultResponse.new(rows, peer_metadata, nil, nil)
333+
end
334+
end
335+
end
336+
337+
control_connection.connect_async.value
338+
339+
expect(cluster_registry).to have(3).hosts
340+
end
341+
end
342+
303343
context 'with logging' do
304344
it 'logs when fetching cluster state' do
305345
logger.stub(:debug)

0 commit comments

Comments
 (0)