Skip to content

Commit bac3f04

Browse files
committed
JAVA-2421: Select only primaries and secondaries for nearest read preference
1 parent 71f7a78 commit bac3f04

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

driver-core/src/main/com/mongodb/TaggableReadPreference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public String getName() {
344344
@Override
345345
@SuppressWarnings("deprecation")
346346
public List<ServerDescription> chooseForReplicaSet(final ClusterDescription clusterDescription) {
347-
List<ServerDescription> selectedServers = selectFreshServers(clusterDescription, clusterDescription.getAny());
347+
List<ServerDescription> selectedServers = selectFreshServers(clusterDescription, clusterDescription.getAnyPrimaryOrSecondary());
348348
if (!getTagSetList().isEmpty()) {
349349
ClusterDescription nonStaleClusterDescription = copyClusterDescription(clusterDescription, selectedServers);
350350
selectedServers = Collections.emptyList();

driver-core/src/test/resources/server-selection/server_selection/ReplicaSetNoPrimary/read/Nearest.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,24 @@
5353
"data_center": "nyc"
5454
},
5555
"type": "RSSecondary"
56+
},
57+
{
58+
"address": "d:27017",
59+
"avg_rtt_ms": 5,
60+
"tags": {
61+
"data_center": "nyc"
62+
},
63+
"type": "RSArbiter"
64+
},
65+
{
66+
"address": "e:27017",
67+
"avg_rtt_ms": 5,
68+
"tags": {
69+
"data_center": "nyc"
70+
},
71+
"type": "RSGhost"
5672
}
57-
],
73+
],
5874
"type": "ReplicaSetNoPrimary"
5975
}
6076
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"in_latency_window": [
3+
{
4+
"address": "b:27017",
5+
"avg_rtt_ms": 5,
6+
"tags": {
7+
"data_center": "nyc"
8+
},
9+
"type": "RSSecondary"
10+
}
11+
],
12+
"operation": "read",
13+
"read_preference": {
14+
"mode": "Nearest",
15+
},
16+
"suitable_servers": [
17+
{
18+
"address": "b:27017",
19+
"avg_rtt_ms": 5,
20+
"tags": {
21+
"data_center": "nyc"
22+
},
23+
"type": "RSSecondary"
24+
},
25+
{
26+
"address": "c:27017",
27+
"avg_rtt_ms": 100,
28+
"tags": {
29+
"data_center": "nyc"
30+
},
31+
"type": "RSSecondary"
32+
}
33+
],
34+
"topology_description": {
35+
"servers": [
36+
{
37+
"address": "b:27017",
38+
"avg_rtt_ms": 5,
39+
"tags": {
40+
"data_center": "nyc"
41+
},
42+
"type": "RSSecondary"
43+
},
44+
{
45+
"address": "c:27017",
46+
"avg_rtt_ms": 100,
47+
"tags": {
48+
"data_center": "nyc"
49+
},
50+
"type": "RSSecondary"
51+
},
52+
{
53+
"address": "d:27017",
54+
"avg_rtt_ms": 5,
55+
"tags": {
56+
"data_center": "nyc"
57+
},
58+
"type": "RSArbiter"
59+
},
60+
{
61+
"address": "e:27017",
62+
"avg_rtt_ms": 5,
63+
"tags": {
64+
"data_center": "nyc"
65+
},
66+
"type": "RSGhost"
67+
}
68+
],
69+
"type": "ReplicaSetNoPrimary"
70+
}
71+
}

0 commit comments

Comments
 (0)