Skip to content

Commit 9a93a7e

Browse files
author
Bulat Shakirzyanov
committed
prevent infinite looping during token map building
1 parent 969902c commit 9a93a7e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/cassandra/cluster/schema/replication_strategies/network_topology.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,21 @@ def replication_map(token_hosts, token_ring, replication_options)
4646
skipped = ::Hash.new
4747

4848
replication_options.each do |datacenter, factor|
49-
ring = datacenter_token_rings.fetch(datacenter) { next }
49+
ring = datacenter_token_rings[datacenter]
50+
next unless ring
5051
factor = [Integer(factor), ring.size].min rescue next
5152

53+
5254
total_racks = racks[datacenter].size
5355
visited_racks = visited[datacenter] ||= ::Set.new
5456
skipped_hosts = skipped[datacenter] ||= ::Set.new
5557
added_replicas = ::Set.new
5658

57-
j = -1
58-
59-
loop do
59+
size.times do |j|
6060
break if added_replicas.size >= factor
6161

62-
j += 1
6362
tk = ring[(i + j) % size]
64-
6563
next unless tk
66-
6764
host = token_hosts[tk]
6865
rack = host.rack
6966

0 commit comments

Comments
 (0)