File tree Expand file tree Collapse file tree 4 files changed +31
-10
lines changed
test/resources/max-staleness/server_selection Expand file tree Collapse file tree 4 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -255,10 +255,12 @@ protected List<ServerDescription> selectFreshServers(final ClusterDescription cl
255255 }
256256 } else {
257257 ServerDescription mostUpToDateSecondary = findMostUpToDateSecondary (clusterDescription );
258- for (ServerDescription cur : servers ) {
259- if (getLastWriteDateNonNull (mostUpToDateSecondary ).getTime () - getLastWriteDateNonNull (cur ).getTime ()
260- + heartbeatFrequencyMS <= maxStaleness ) {
261- freshServers .add (cur );
258+ if (mostUpToDateSecondary != null ) {
259+ for (ServerDescription cur : servers ) {
260+ if (getLastWriteDateNonNull (mostUpToDateSecondary ).getTime () - getLastWriteDateNonNull (cur ).getTime ()
261+ + heartbeatFrequencyMS <= maxStaleness ) {
262+ freshServers .add (cur );
263+ }
262264 }
263265 }
264266 }
@@ -293,9 +295,6 @@ private ServerDescription findMostUpToDateSecondary(final ClusterDescription clu
293295 }
294296 }
295297 }
296- if (mostUpdateToDateSecondary == null ) {
297- throw new MongoInternalException ("Expected at least one secondary in cluster description: " + clusterDescription );
298- }
299298 return mostUpdateToDateSecondary ;
300299 }
301300
Original file line number Diff line number Diff line change 1+ {
2+ "topology_description" : {
3+ "type" : " ReplicaSetNoPrimary" ,
4+ "servers" : [
5+ {
6+ "address" : " a:27017" ,
7+ "type" : " Unknown"
8+ },
9+ {
10+ "address" : " b:27017" ,
11+ "type" : " Unknown"
12+ }
13+ ]
14+ },
15+ "read_preference" : {
16+ "mode" : " Nearest" ,
17+ "maxStalenessSeconds" : 1
18+ },
19+ "error" : true
20+ }
Original file line number Diff line number Diff line change 1414 },
1515 "read_preference" : {
1616 "mode" : " Nearest" ,
17- "maxStalenessSeconds" : 1
17+ "maxStalenessSeconds" : 90
1818 },
19- "error" : true
19+ "suitable_servers" : [],
20+ "in_latency_window" : []
2021}
Original file line number Diff line number Diff line change 55 "servers" : [
66 {
77 "address" : " a:27017" ,
8- "type" : " Unknown"
8+ "type" : " Unknown" ,
9+ "maxWireVersion" : 5
910 }
1011 ]
1112 },
You can’t perform that action at this time.
0 commit comments