diff --git a/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb b/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb index 93ae67902..cbcbde0b0 100644 --- a/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +++ b/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb @@ -46,9 +46,11 @@ def replication_map(token_hosts, token_ring, replication_options) datacenter = host.datacenter next if datacenter.nil? - factor = Integer(replication_options[datacenter]) + factor = replication_options[datacenter] next unless factor + factor = Integer(factor) rescue next + replicas_in_datacenter = all_replicas[datacenter] ||= ::Set.new next if replicas_in_datacenter.size >= factor diff --git a/spec/cassandra/cluster/schema/replication_strategies/network_topology_spec.rb b/spec/cassandra/cluster/schema/replication_strategies/network_topology_spec.rb index 4c4cb3083..82cdbc623 100644 --- a/spec/cassandra/cluster/schema/replication_strategies/network_topology_spec.rb +++ b/spec/cassandra/cluster/schema/replication_strategies/network_topology_spec.rb @@ -91,6 +91,27 @@ module ReplicationStrategies ]) end end + + context('with datacenters missing replication factor') do + let(:replication_options) { + { + 'dc1' => '2', + 'dc2' => '2' + } + } + + it 'skips those datacenters in replication map' do + replication_map = subject.replication_map(token_hosts, token_ring, replication_options) + expect(replication_map[token_ring[0]].map do |host| + [host.datacenter, host.rack] + end).to eq([ + ['dc1', 'rack1'], + ['dc2', 'rack1'], + ['dc1', 'rack2'], + ['dc2', 'rack2'], + ]) + end + end end end end