Skip to content

Commit 16daa31

Browse files
committed
Clarify behavior when "me" field doesn't match any values in "hosts" array
JAVA-3602
1 parent 8a27274 commit 16daa31

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

driver-core/src/main/com/mongodb/internal/connection/AbstractMultiServerCluster.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ private boolean handleReplicaSetMemberChanged(final ServerDescription newDescrip
261261
ensureServers(newDescription);
262262

263263
if (newDescription.getCanonicalAddress() != null
264-
&& !newDescription.getAddress().equals(new ServerAddress(newDescription.getCanonicalAddress()))) {
264+
&& !newDescription.getAddress().equals(new ServerAddress(newDescription.getCanonicalAddress()))
265+
&& !newDescription.isPrimary()) {
265266
if (LOGGER.isInfoEnabled()) {
266267
LOGGER.info(format("Canonical address %s does not match server address. Removing %s from client view of cluster",
267268
newDescription.getCanonicalAddress(), newDescription.getAddress()));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"description": "Primary mismatched me is not removed",
3+
"uri": "mongodb://localhost:27017,localhost:27018/?replicaSet=rs",
4+
"phases": [
5+
{
6+
"responses": [
7+
[
8+
"localhost:27017",
9+
{
10+
"ok": 1,
11+
"hosts": [
12+
"localhost:27017",
13+
"localhost:27018"
14+
],
15+
"ismaster": true,
16+
"setName": "rs",
17+
"primary": "localhost:27017",
18+
"me": "a:27017",
19+
"minWireVersion": 0,
20+
"maxWireVersion": 7
21+
}
22+
]
23+
],
24+
"outcome": {
25+
"servers": {
26+
"localhost:27017": {
27+
"type": "RSPrimary",
28+
"setName": "rs"
29+
},
30+
"localhost:27018": {
31+
"type": "Unknown",
32+
"setName": null
33+
}
34+
},
35+
"topologyType": "ReplicaSetWithPrimary",
36+
"logicalSessionTimeoutMinutes": null,
37+
"setName": "rs"
38+
}
39+
},
40+
{
41+
"responses": [
42+
[
43+
"localhost:27018",
44+
{
45+
"ok": 1,
46+
"hosts": [
47+
"localhost:27017",
48+
"localhost:27018"
49+
],
50+
"ismaster": false,
51+
"secondary": true,
52+
"setName": "rs",
53+
"primary": "localhost:27017",
54+
"me": "localhost:27018",
55+
"minWireVersion": 0,
56+
"maxWireVersion": 7
57+
}
58+
]
59+
],
60+
"outcome": {
61+
"servers": {
62+
"localhost:27017": {
63+
"type": "RSPrimary",
64+
"setName": "rs"
65+
},
66+
"localhost:27018": {
67+
"type": "RSSecondary",
68+
"setName": "rs"
69+
}
70+
},
71+
"topologyType": "ReplicaSetWithPrimary",
72+
"logicalSessionTimeoutMinutes": null,
73+
"setName": "rs"
74+
}
75+
}
76+
]
77+
}

0 commit comments

Comments
 (0)