Skip to content

Commit 75c6734

Browse files
committed
JAVA-2663: Consider only data-bearing servers (Mongos, Standalone, Primary, and Secondary) when considering whether sessions are supported.
This excludes, in particular, arbiters and "ghosts"
1 parent e72feb1 commit 75c6734

File tree

4 files changed

+251
-19
lines changed

4 files changed

+251
-19
lines changed

driver-core/src/main/com/mongodb/connection/ClusterDescription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public Integer getLogicalSessionTimeoutMinutes() {
208208
for (ServerDescription cur : getServersByPredicate(new Predicate() {
209209
@Override
210210
public boolean apply(final ServerDescription serverDescription) {
211-
return serverDescription.isOk();
211+
return serverDescription.isPrimary() || serverDescription.isSecondary();
212212
}
213213
})) {
214214
if (cur.getLogicalSessionTimeoutMinutes() == null) {

driver-core/src/test/resources/server-discovery-and-monitoring/rs/ls_timeout.json

Lines changed: 180 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,127 @@
1111
"ismaster": true,
1212
"hosts": [
1313
"a:27017",
14-
"b:27017"
14+
"b:27017",
15+
"c:27017",
16+
"d:27017",
17+
"e:27017"
1518
],
1619
"setName": "rs",
17-
"logicalSessionTimeoutMinutes": 1,
20+
"logicalSessionTimeoutMinutes": 3,
21+
"minWireVersion": 0,
22+
"maxWireVersion": 6
23+
}
24+
]
25+
],
26+
"outcome": {
27+
"servers": {
28+
"a:27017": {
29+
"type": "RSPrimary",
30+
"setName": "rs"
31+
},
32+
"b:27017": {
33+
"type": "Unknown"
34+
},
35+
"c:27017": {
36+
"type": "Unknown"
37+
},
38+
"d:27017": {
39+
"type": "Unknown"
40+
},
41+
"e:27017": {
42+
"type": "Unknown"
43+
}
44+
},
45+
"topologyType": "ReplicaSetWithPrimary",
46+
"logicalSessionTimeoutMinutes": 3,
47+
"setName": "rs"
48+
}
49+
},
50+
{
51+
"responses": [
52+
[
53+
"d:27017",
54+
{
55+
"ok": 1,
56+
"ismaster": false,
57+
"isreplicaset": true,
1858
"minWireVersion": 0,
1959
"maxWireVersion": 6
2060
}
21-
],
61+
]
62+
],
63+
"outcome": {
64+
"servers": {
65+
"a:27017": {
66+
"type": "RSPrimary",
67+
"setName": "rs"
68+
},
69+
"b:27017": {
70+
"type": "Unknown"
71+
},
72+
"c:27017": {
73+
"type": "Unknown"
74+
},
75+
"d:27017": {
76+
"type": "RSGhost"
77+
},
78+
"e:27017": {
79+
"type": "Unknown"
80+
}
81+
},
82+
"topologyType": "ReplicaSetWithPrimary",
83+
"logicalSessionTimeoutMinutes": 3,
84+
"setName": "rs"
85+
}
86+
},
87+
{
88+
"responses": [
89+
[
90+
"e:27017",
91+
{
92+
"ok": 1,
93+
"ismaster": false,
94+
"hosts": [
95+
"a:27017",
96+
"b:27017",
97+
"c:27017",
98+
"d:27017",
99+
"e:27017"
100+
],
101+
"setName": "rs",
102+
"arbiterOnly": true,
103+
"minWireVersion": 0,
104+
"maxWireVersion": 6
105+
}
106+
]
107+
],
108+
"outcome": {
109+
"servers": {
110+
"a:27017": {
111+
"type": "RSPrimary",
112+
"setName": "rs"
113+
},
114+
"b:27017": {
115+
"type": "Unknown"
116+
},
117+
"c:27017": {
118+
"type": "Unknown"
119+
},
120+
"d:27017": {
121+
"type": "RSGhost"
122+
},
123+
"e:27017": {
124+
"type": "RSArbiter",
125+
"setName": "rs"
126+
}
127+
},
128+
"topologyType": "ReplicaSetWithPrimary",
129+
"logicalSessionTimeoutMinutes": 3,
130+
"setName": "rs"
131+
}
132+
},
133+
{
134+
"responses": [
22135
[
23136
"b:27017",
24137
{
@@ -27,7 +140,10 @@
27140
"secondary": true,
28141
"hosts": [
29142
"a:27017",
30-
"b:27017"
143+
"b:27017",
144+
"c:27017",
145+
"d:27017",
146+
"e:27017"
31147
],
32148
"setName": "rs",
33149
"logicalSessionTimeoutMinutes": 2,
@@ -45,30 +161,67 @@
45161
"b:27017": {
46162
"type": "RSSecondary",
47163
"setName": "rs"
164+
},
165+
"c:27017": {
166+
"type": "Unknown"
167+
},
168+
"d:27017": {
169+
"type": "RSGhost"
170+
},
171+
"e:27017": {
172+
"type": "RSArbiter",
173+
"setName": "rs"
48174
}
49175
},
50176
"topologyType": "ReplicaSetWithPrimary",
51-
"logicalSessionTimeoutMinutes": 1,
177+
"logicalSessionTimeoutMinutes": 2,
52178
"setName": "rs"
53179
}
54180
},
55181
{
56182
"responses": [
57183
[
58-
"a:27017",
184+
"c:27017",
59185
{
60186
"ok": 1,
61-
"ismaster": true,
62-
"hosts": [
63-
"a:27017",
64-
"b:27017"
65-
],
187+
"ismaster": false,
66188
"setName": "rs",
189+
"hidden": true,
67190
"logicalSessionTimeoutMinutes": 1,
68191
"minWireVersion": 0,
69192
"maxWireVersion": 6
70193
}
71-
],
194+
]
195+
],
196+
"outcome": {
197+
"servers": {
198+
"a:27017": {
199+
"type": "RSPrimary",
200+
"setName": "rs"
201+
},
202+
"b:27017": {
203+
"type": "RSSecondary",
204+
"setName": "rs"
205+
},
206+
"c:27017": {
207+
"type": "RSOther",
208+
"setName": "rs"
209+
},
210+
"d:27017": {
211+
"type": "RSGhost"
212+
},
213+
"e:27017": {
214+
"type": "RSArbiter",
215+
"setName": "rs"
216+
}
217+
},
218+
"topologyType": "ReplicaSetWithPrimary",
219+
"logicalSessionTimeoutMinutes": 2,
220+
"setName": "rs"
221+
}
222+
},
223+
{
224+
"responses": [
72225
[
73226
"b:27017",
74227
{
@@ -77,7 +230,10 @@
77230
"secondary": true,
78231
"hosts": [
79232
"a:27017",
80-
"b:27017"
233+
"b:27017",
234+
"c:27017",
235+
"d:27017",
236+
"e:27017"
81237
],
82238
"setName": "rs",
83239
"logicalSessionTimeoutMinutes": null,
@@ -95,6 +251,17 @@
95251
"b:27017": {
96252
"type": "RSSecondary",
97253
"setName": "rs"
254+
},
255+
"c:27017": {
256+
"type": "RSOther",
257+
"setName": "rs"
258+
},
259+
"d:27017": {
260+
"type": "RSGhost"
261+
},
262+
"e:27017": {
263+
"type": "RSArbiter",
264+
"setName": "rs"
98265
}
99266
},
100267
"topologyType": "ReplicaSetWithPrimary",

driver-core/src/test/unit/com/mongodb/connection/ClusterDescriptionTest.java

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
import java.util.List;
3232

3333
import static com.mongodb.connection.ClusterConnectionMode.MULTIPLE;
34+
import static com.mongodb.connection.ClusterConnectionMode.SINGLE;
3435
import static com.mongodb.connection.ClusterType.REPLICA_SET;
36+
import static com.mongodb.connection.ClusterType.SHARDED;
37+
import static com.mongodb.connection.ClusterType.STANDALONE;
3538
import static com.mongodb.connection.ClusterType.UNKNOWN;
3639
import static com.mongodb.connection.ServerConnectionState.CONNECTED;
3740
import static com.mongodb.connection.ServerConnectionState.CONNECTING;
@@ -284,10 +287,60 @@ public void testLogicalSessionTimeoutMinutes() {
284287
));
285288
assertEquals(null, description.getLogicalSessionTimeoutMinutes());
286289

290+
description = new ClusterDescription(SINGLE, STANDALONE, asList(
291+
builder().state(CONNECTED)
292+
.ok(true)
293+
.address(new ServerAddress("loc:27017"))
294+
.type(ServerType.STANDALONE)
295+
.logicalSessionTimeoutMinutes(5)
296+
.build()
297+
));
298+
assertEquals(new Integer(5), description.getLogicalSessionTimeoutMinutes());
299+
300+
description = new ClusterDescription(SINGLE, SHARDED, asList(
301+
builder().state(CONNECTED)
302+
.ok(true)
303+
.address(new ServerAddress("loc:27017"))
304+
.type(ServerType.SHARD_ROUTER)
305+
.logicalSessionTimeoutMinutes(5)
306+
.build()
307+
));
308+
assertEquals(new Integer(5), description.getLogicalSessionTimeoutMinutes());
309+
310+
description = new ClusterDescription(MULTIPLE, SHARDED, asList(
311+
builder().state(CONNECTED)
312+
.ok(true)
313+
.address(new ServerAddress("loc:27017"))
314+
.type(ServerType.SHARD_ROUTER)
315+
.logicalSessionTimeoutMinutes(5)
316+
.build(),
317+
builder().state(CONNECTING)
318+
.address(new ServerAddress("loc:27018"))
319+
.build()
320+
));
321+
assertEquals(new Integer(5), description.getLogicalSessionTimeoutMinutes());
322+
323+
description = new ClusterDescription(MULTIPLE, SHARDED, asList(
324+
builder().state(CONNECTED)
325+
.ok(true)
326+
.address(new ServerAddress("loc:27017"))
327+
.type(ServerType.SHARD_ROUTER)
328+
.logicalSessionTimeoutMinutes(5)
329+
.build(),
330+
builder().state(CONNECTED)
331+
.ok(true)
332+
.address(new ServerAddress("loc:27018"))
333+
.type(ServerType.SHARD_ROUTER)
334+
.logicalSessionTimeoutMinutes(3)
335+
.build()
336+
));
337+
assertEquals(new Integer(3), description.getLogicalSessionTimeoutMinutes());
338+
287339
description = new ClusterDescription(MULTIPLE, REPLICA_SET, asList(
288340
builder().state(CONNECTED)
289341
.ok(true)
290342
.address(new ServerAddress("loc:27017"))
343+
.type(ServerType.REPLICA_SET_PRIMARY)
291344
.logicalSessionTimeoutMinutes(5)
292345
.build(),
293346
builder().state(CONNECTING)
@@ -300,15 +353,17 @@ public void testLogicalSessionTimeoutMinutes() {
300353
builder().state(CONNECTED)
301354
.ok(true)
302355
.address(new ServerAddress("loc:27017"))
356+
.type(REPLICA_SET_PRIMARY)
303357
.logicalSessionTimeoutMinutes(5)
304358
.build(),
305359
builder().state(CONNECTED)
306360
.ok(true)
307361
.address(new ServerAddress("loc:27018"))
362+
.type(REPLICA_SET_SECONDARY)
308363
.logicalSessionTimeoutMinutes(3)
309364
.build(),
310365
builder().state(CONNECTING)
311-
.address(new ServerAddress("loc:27017"))
366+
.address(new ServerAddress("loc:27019"))
312367
.build()
313368
));
314369
assertEquals(Integer.valueOf(3), description.getLogicalSessionTimeoutMinutes());
@@ -317,15 +372,17 @@ public void testLogicalSessionTimeoutMinutes() {
317372
builder().state(CONNECTED)
318373
.ok(true)
319374
.address(new ServerAddress("loc:27017"))
375+
.type(REPLICA_SET_PRIMARY)
320376
.logicalSessionTimeoutMinutes(3)
321377
.build(),
322378
builder().state(CONNECTED)
323379
.ok(true)
324380
.address(new ServerAddress("loc:27018"))
381+
.type(REPLICA_SET_SECONDARY)
325382
.logicalSessionTimeoutMinutes(5)
326383
.build(),
327384
builder().state(CONNECTING)
328-
.address(new ServerAddress("loc:27017"))
385+
.address(new ServerAddress("loc:27019"))
329386
.build()
330387
));
331388
assertEquals(Integer.valueOf(3), description.getLogicalSessionTimeoutMinutes());

0 commit comments

Comments
 (0)