Skip to content

Commit 56ae9ba

Browse files
committed
RUBY-900 Don't add discovered servers to the cluster with Single topology
1 parent dfdf9af commit 56ae9ba

File tree

7 files changed

+13
-9
lines changed

7 files changed

+13
-9
lines changed

lib/mongo/address.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Address
3333
::Socket::AF_INET => IPv4
3434
}
3535

36-
# @return [ String ] address The seed address.
36+
# @return [ String ] seed The seed address.
3737
attr_reader :seed
3838

3939
# @return [ String ] host The original host name.

lib/mongo/cluster.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def ==(other)
6666
# @since 2.0.0
6767
def add(host)
6868
address = Address.new(host)
69-
unless addresses.include?(address)
69+
unless addresses.include?(address) || (@topology.single? && address.seed != @topology.seed)
7070
log_debug([ "Adding #{address.to_s} to the cluster." ])
7171
addresses.push(address)
7272
server = Server.new(address, event_listeners,

lib/mongo/cluster/topology.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ module Topology
4848
# @since 2.0.0
4949
def initial(seeds, options)
5050
if options.has_key?(:connect)
51-
return OPTIONS.fetch(options[:connect]).new(options)
51+
return OPTIONS.fetch(options[:connect]).new(options, seeds)
5252
end
5353
if options.has_key?(:replica_set)
54-
ReplicaSet.new(options)
54+
ReplicaSet.new(options, seeds)
5555
else
56-
seeds.size > 1 ? Unknown.new(options) : Single.new(options)
56+
seeds.size > 1 ? Unknown.new(options, seeds) : Single.new(options, seeds)
5757
end
5858
end
5959
end

lib/mongo/cluster/topology/replica_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def elect_primary(description, servers)
8282
# @param [ Hash ] options The options.
8383
#
8484
# @since 2.0.0
85-
def initialize(options)
85+
def initialize(options, seeds = [])
8686
@options = options
8787
end
8888

lib/mongo/cluster/topology/sharded.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def elect_primary(description, servers); self; end
5959
# @param [ Hash ] options The options.
6060
#
6161
# @since 2.0.0
62-
def initialize(options)
62+
def initialize(options, seeds = [])
6363
@options = options
6464
end
6565

lib/mongo/cluster/topology/single.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module Topology
2121
# @since 2.0.0
2222
class Single
2323

24+
# @return [ String ] seed The seed address.
25+
attr_reader :seed
26+
2427
# The display name for the topology.
2528
#
2629
# @since 2.0.0
@@ -59,8 +62,9 @@ def elect_primary(description, servers); self; end
5962
# @param [ Hash ] options The options.
6063
#
6164
# @since 2.0.0
62-
def initialize(options)
65+
def initialize(options, seeds = [])
6366
@options = options
67+
@seed = seeds.first
6468
end
6569

6670
# A single topology is not a replica set.

lib/mongo/cluster/topology/unknown.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def elect_primary(description, servers)
7070
# @param [ Hash ] options The options.
7171
#
7272
# @since 2.0.0
73-
def initialize(options)
73+
def initialize(options, seeds = [])
7474
@options = options
7575
end
7676

0 commit comments

Comments
 (0)