Skip to content

Commit 7b143c6

Browse files
authored
CDRIVER-3885 Don't inspect error messages for "not master" or "node is recovering" (#745)
* CDRIVER-3885 Only inspect error messages when no code was given * CDRIVER-3884 Ensure that SDAM ignores the writeErrors field * Fix code review issues
1 parent 26321ea commit 7b143c6

18 files changed

+1188
-28
lines changed

src/libmongoc/src/mongoc/mongoc-error-private.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ typedef enum {
4949
MONGOC_SERVER_ERR_INTERRUPTEDDUETOREPLSTATECHANGE = 11602,
5050
MONGOC_SERVER_ERR_STALECONFIG = 13388,
5151
MONGOC_SERVER_ERR_NOTMASTERNOSLAVEOK = 13435,
52-
MONGOC_SERVER_ERR_NOTMASTERORSECONDARY = 13436
52+
MONGOC_SERVER_ERR_NOTMASTERORSECONDARY = 13436,
53+
MONGOC_SERVER_ERR_LEGACYNOTPRIMARY = 10058
5354
} mongoc_server_err_t;
5455

5556
mongoc_read_err_type_t

src/libmongoc/src/mongoc/mongoc-error.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,13 @@ _mongoc_error_is_not_master (bson_error_t *error)
268268
switch (error->code) {
269269
case MONGOC_SERVER_ERR_NOTMASTER:
270270
case MONGOC_SERVER_ERR_NOTMASTERNOSLAVEOK:
271+
case MONGOC_SERVER_ERR_LEGACYNOTPRIMARY:
271272
return true;
272-
default:
273+
/* All errors where no code was found are marked as MONGOC_ERROR_QUERY_FAILURE */
274+
case MONGOC_ERROR_QUERY_FAILURE:
273275
return NULL != strstr (error->message, "not master");
276+
default:
277+
return false;
274278
}
275279
}
276280

@@ -287,9 +291,12 @@ _mongoc_error_is_recovering (bson_error_t *error)
287291
case MONGOC_SERVER_ERR_PRIMARYSTEPPEDDOWN:
288292
case MONGOC_SERVER_ERR_SHUTDOWNINPROGRESS:
289293
return true;
290-
default:
294+
/* All errors where no code was found are marked as MONGOC_ERROR_QUERY_FAILURE */
295+
case MONGOC_ERROR_QUERY_FAILURE:
291296
return NULL != strstr (error->message, "not master or secondary") ||
292297
NULL != strstr (error->message, "node is recovering");
298+
default:
299+
return false;
293300
}
294301
}
295302

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"description": "Non-stale topologyVersion greater LegacyNotPrimary error",
3+
"uri": "mongodb://a/?replicaSet=rs",
4+
"phases": [
5+
{
6+
"description": "Primary A is discovered",
7+
"responses": [
8+
[
9+
"a:27017",
10+
{
11+
"ok": 1,
12+
"ismaster": true,
13+
"hosts": [
14+
"a:27017"
15+
],
16+
"setName": "rs",
17+
"minWireVersion": 0,
18+
"maxWireVersion": 9,
19+
"topologyVersion": {
20+
"processId": {
21+
"$oid": "000000000000000000000001"
22+
},
23+
"counter": {
24+
"$numberLong": "1"
25+
}
26+
}
27+
}
28+
]
29+
],
30+
"outcome": {
31+
"servers": {
32+
"a:27017": {
33+
"type": "RSPrimary",
34+
"setName": "rs",
35+
"topologyVersion": {
36+
"processId": {
37+
"$oid": "000000000000000000000001"
38+
},
39+
"counter": {
40+
"$numberLong": "1"
41+
}
42+
},
43+
"pool": {
44+
"generation": 0
45+
}
46+
}
47+
},
48+
"topologyType": "ReplicaSetWithPrimary",
49+
"logicalSessionTimeoutMinutes": null,
50+
"setName": "rs"
51+
}
52+
},
53+
{
54+
"description": "Non-stale topologyVersion greater LegacyNotPrimary error marks server Unknown",
55+
"applicationErrors": [
56+
{
57+
"address": "a:27017",
58+
"when": "afterHandshakeCompletes",
59+
"maxWireVersion": 9,
60+
"type": "command",
61+
"response": {
62+
"ok": 0,
63+
"errmsg": "LegacyNotPrimary",
64+
"code": 10058,
65+
"topologyVersion": {
66+
"processId": {
67+
"$oid": "000000000000000000000001"
68+
},
69+
"counter": {
70+
"$numberLong": "2"
71+
}
72+
}
73+
}
74+
}
75+
],
76+
"outcome": {
77+
"servers": {
78+
"a:27017": {
79+
"type": "Unknown",
80+
"topologyVersion": {
81+
"processId": {
82+
"$oid": "000000000000000000000001"
83+
},
84+
"counter": {
85+
"$numberLong": "2"
86+
}
87+
},
88+
"pool": {
89+
"generation": 0
90+
}
91+
}
92+
},
93+
"topologyType": "ReplicaSetNoPrimary",
94+
"logicalSessionTimeoutMinutes": null,
95+
"setName": "rs"
96+
}
97+
}
98+
]
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"description": "Non-stale topologyVersion missing LegacyNotPrimary error",
3+
"uri": "mongodb://a/?replicaSet=rs",
4+
"phases": [
5+
{
6+
"description": "Primary A is discovered",
7+
"responses": [
8+
[
9+
"a:27017",
10+
{
11+
"ok": 1,
12+
"ismaster": true,
13+
"hosts": [
14+
"a:27017"
15+
],
16+
"setName": "rs",
17+
"minWireVersion": 0,
18+
"maxWireVersion": 9,
19+
"topologyVersion": {
20+
"processId": {
21+
"$oid": "000000000000000000000001"
22+
},
23+
"counter": {
24+
"$numberLong": "1"
25+
}
26+
}
27+
}
28+
]
29+
],
30+
"outcome": {
31+
"servers": {
32+
"a:27017": {
33+
"type": "RSPrimary",
34+
"setName": "rs",
35+
"topologyVersion": {
36+
"processId": {
37+
"$oid": "000000000000000000000001"
38+
},
39+
"counter": {
40+
"$numberLong": "1"
41+
}
42+
},
43+
"pool": {
44+
"generation": 0
45+
}
46+
}
47+
},
48+
"topologyType": "ReplicaSetWithPrimary",
49+
"logicalSessionTimeoutMinutes": null,
50+
"setName": "rs"
51+
}
52+
},
53+
{
54+
"description": "Non-stale topologyVersion missing LegacyNotPrimary error marks server Unknown",
55+
"applicationErrors": [
56+
{
57+
"address": "a:27017",
58+
"when": "afterHandshakeCompletes",
59+
"maxWireVersion": 9,
60+
"type": "command",
61+
"response": {
62+
"ok": 0,
63+
"errmsg": "LegacyNotPrimary",
64+
"code": 10058
65+
}
66+
}
67+
],
68+
"outcome": {
69+
"servers": {
70+
"a:27017": {
71+
"type": "Unknown",
72+
"topologyVersion": null,
73+
"pool": {
74+
"generation": 0
75+
}
76+
}
77+
},
78+
"topologyType": "ReplicaSetNoPrimary",
79+
"logicalSessionTimeoutMinutes": null,
80+
"setName": "rs"
81+
}
82+
}
83+
]
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"description": "Non-stale topologyVersion proccessId changed LegacyNotPrimary error",
3+
"uri": "mongodb://a/?replicaSet=rs",
4+
"phases": [
5+
{
6+
"description": "Primary A is discovered",
7+
"responses": [
8+
[
9+
"a:27017",
10+
{
11+
"ok": 1,
12+
"ismaster": true,
13+
"hosts": [
14+
"a:27017"
15+
],
16+
"setName": "rs",
17+
"minWireVersion": 0,
18+
"maxWireVersion": 9,
19+
"topologyVersion": {
20+
"processId": {
21+
"$oid": "000000000000000000000001"
22+
},
23+
"counter": {
24+
"$numberLong": "1"
25+
}
26+
}
27+
}
28+
]
29+
],
30+
"outcome": {
31+
"servers": {
32+
"a:27017": {
33+
"type": "RSPrimary",
34+
"setName": "rs",
35+
"topologyVersion": {
36+
"processId": {
37+
"$oid": "000000000000000000000001"
38+
},
39+
"counter": {
40+
"$numberLong": "1"
41+
}
42+
},
43+
"pool": {
44+
"generation": 0
45+
}
46+
}
47+
},
48+
"topologyType": "ReplicaSetWithPrimary",
49+
"logicalSessionTimeoutMinutes": null,
50+
"setName": "rs"
51+
}
52+
},
53+
{
54+
"description": "Non-stale topologyVersion proccessId changed LegacyNotPrimary error marks server Unknown",
55+
"applicationErrors": [
56+
{
57+
"address": "a:27017",
58+
"when": "afterHandshakeCompletes",
59+
"maxWireVersion": 9,
60+
"type": "command",
61+
"response": {
62+
"ok": 0,
63+
"errmsg": "LegacyNotPrimary",
64+
"code": 10058,
65+
"topologyVersion": {
66+
"processId": {
67+
"$oid": "000000000000000000000002"
68+
},
69+
"counter": {
70+
"$numberLong": "1"
71+
}
72+
}
73+
}
74+
}
75+
],
76+
"outcome": {
77+
"servers": {
78+
"a:27017": {
79+
"type": "Unknown",
80+
"topologyVersion": {
81+
"processId": {
82+
"$oid": "000000000000000000000002"
83+
},
84+
"counter": {
85+
"$numberLong": "1"
86+
}
87+
},
88+
"pool": {
89+
"generation": 0
90+
}
91+
}
92+
},
93+
"topologyType": "ReplicaSetNoPrimary",
94+
"logicalSessionTimeoutMinutes": null,
95+
"setName": "rs"
96+
}
97+
}
98+
]
99+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"description": "Post-4.2 LegacyNotPrimary error",
3+
"uri": "mongodb://a/?replicaSet=rs",
4+
"phases": [
5+
{
6+
"description": "Primary A is discovered",
7+
"responses": [
8+
[
9+
"a:27017",
10+
{
11+
"ok": 1,
12+
"ismaster": true,
13+
"hosts": [
14+
"a:27017"
15+
],
16+
"setName": "rs",
17+
"minWireVersion": 0,
18+
"maxWireVersion": 8
19+
}
20+
]
21+
],
22+
"outcome": {
23+
"servers": {
24+
"a:27017": {
25+
"type": "RSPrimary",
26+
"setName": "rs",
27+
"topologyVersion": null,
28+
"pool": {
29+
"generation": 0
30+
}
31+
}
32+
},
33+
"topologyType": "ReplicaSetWithPrimary",
34+
"logicalSessionTimeoutMinutes": null,
35+
"setName": "rs"
36+
}
37+
},
38+
{
39+
"description": "Post-4.2 LegacyNotPrimary error marks server Unknown",
40+
"applicationErrors": [
41+
{
42+
"address": "a:27017",
43+
"when": "afterHandshakeCompletes",
44+
"maxWireVersion": 8,
45+
"type": "command",
46+
"response": {
47+
"ok": 0,
48+
"errmsg": "LegacyNotPrimary",
49+
"code": 10058
50+
}
51+
}
52+
],
53+
"outcome": {
54+
"servers": {
55+
"a:27017": {
56+
"type": "Unknown",
57+
"topologyVersion": null,
58+
"pool": {
59+
"generation": 0
60+
}
61+
}
62+
},
63+
"topologyType": "ReplicaSetNoPrimary",
64+
"logicalSessionTimeoutMinutes": null,
65+
"setName": "rs"
66+
}
67+
}
68+
]
69+
}

0 commit comments

Comments
 (0)