Skip to content

Commit df86686

Browse files
committed
JAVA-1161: Just to be safe, also ignoring replica set members without a setName.
1 parent 1ac648c commit df86686

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/main/com/mongodb/MultiServerCluster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private void handleReplicaSetMemberChanged(final ServerDescription newDescriptio
152152
return;
153153
}
154154

155-
if (newDescription.getHosts().isEmpty()) {
155+
if (newDescription.getHosts().isEmpty() || newDescription.getSetName() == null) {
156156
LOGGER.info(format("Server %s does not appear to be a member of an initiated replica set.", newDescription.getAddress()));
157157
return;
158158
}
@@ -161,7 +161,7 @@ private void handleReplicaSetMemberChanged(final ServerDescription newDescriptio
161161
replicaSetName = newDescription.getSetName();
162162
}
163163

164-
if (replicaSetName != null && !replicaSetName.equals(newDescription.getSetName())) {
164+
if (!replicaSetName.equals(newDescription.getSetName())) {
165165
LOGGER.severe(format("Expecting replica set member from set '%s', but found one from set '%s'. "
166166
+ "Removing %s from client view of cluster.",
167167
replicaSetName, newDescription.getSetName(), newDescription.getAddress()));

src/test/com/mongodb/MultiServerClusterSpecification.groovy

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,21 @@ class MultiServerClusterSpecification extends Specification {
120120
CLUSTER_LISTENER)
121121

122122
when:
123-
sendNotification(secondServer, ReplicaSetOther, [], null) // null replica set name
123+
sendNotification(secondServer, ReplicaSetOther, [])
124+
125+
then:
126+
getClusterDescription(cluster).type == ReplicaSet
127+
getClusterDescription(cluster).all == getServerDescriptions(firstServer, secondServer)
128+
}
129+
130+
def 'should ignore a host without a replica set name when type is replica set'() {
131+
given:
132+
def cluster = new MultiServerCluster(
133+
CLUSTER_ID, ClusterSettings.builder().requiredClusterType(ReplicaSet).hosts([firstServer, secondServer]).build(), factory,
134+
CLUSTER_LISTENER)
135+
136+
when:
137+
sendNotification(secondServer, ReplicaSetOther, [firstServer, secondServer], null) // null replica set name
124138

125139
then:
126140
getClusterDescription(cluster).type == ReplicaSet
@@ -322,7 +336,7 @@ class MultiServerClusterSpecification extends Specification {
322336
}
323337

324338
def sendNotification(ServerAddress serverAddress, ServerType serverType, List<ServerAddress> hosts) {
325-
sendNotification(serverAddress, serverType, hosts, null)
339+
sendNotification(serverAddress, serverType, hosts, 'test')
326340
}
327341

328342
def sendNotification(ServerAddress serverAddress, ServerType serverType, List<ServerAddress> hosts, String setName, int setVersion) {

0 commit comments

Comments
 (0)