Skip to content

Commit 2d69e07

Browse files
committed
JAVA-1161: When a replica set member returns an empty list of hosts, assume it's not a part of an initiated replica set and do not remove every server from the client view of the replica set.
1 parent cd8f98b commit 2d69e07

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/main/com/mongodb/MultiServerCluster.java

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

155+
if (newDescription.getHosts().isEmpty()) {
156+
LOGGER.info(format("Server %s does not appear to be a member of an initiated replica set.", newDescription.getAddress()));
157+
return;
158+
}
159+
155160
if (replicaSetName == null) {
156161
replicaSetName = newDescription.getSetName();
157162
}

src/test/com/mongodb/MultiServerClusterSpecification.groovy

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
18-
19-
20-
2117
package com.mongodb
2218

2319
import spock.lang.Specification
@@ -27,6 +23,7 @@ import static com.mongodb.ClusterType.ReplicaSet
2723
import static com.mongodb.ClusterType.Sharded
2824
import static com.mongodb.ServerConnectionState.Connected
2925
import static com.mongodb.ServerConnectionState.Connecting
26+
import static com.mongodb.ServerType.ReplicaSetOther
3027
import static com.mongodb.ServerType.ReplicaSetPrimary
3128
import static com.mongodb.ServerType.ReplicaSetSecondary
3229
import static com.mongodb.ServerType.ShardRouter
@@ -116,6 +113,20 @@ class MultiServerClusterSpecification extends Specification {
116113
}
117114
}
118115

116+
def 'should ignore an empty list of hosts when type is replica set'() {
117+
given:
118+
def cluster = new MultiServerCluster(
119+
CLUSTER_ID, ClusterSettings.builder().requiredClusterType(ReplicaSet).hosts([firstServer, secondServer]).build(), factory,
120+
CLUSTER_LISTENER)
121+
122+
when:
123+
sendNotification(secondServer, ReplicaSetOther, [], null) // null replica set name
124+
125+
then:
126+
getClusterDescription(cluster).type == ReplicaSet
127+
getClusterDescription(cluster).all == getServerDescriptions(firstServer, secondServer)
128+
}
129+
119130
def 'should remove a server of the wrong type when type is sharded'() {
120131
given:
121132
def cluster = new MultiServerCluster(

0 commit comments

Comments
 (0)