Skip to content

Commit 5a8842a

Browse files
authored
fix(NODE-3279): use "hello" for monitoring if supported (#2895)
1 parent a488d88 commit 5a8842a

File tree

379 files changed

+1466
-854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

379 files changed

+1466
-854
lines changed

.evergreen/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
stepback: true
22
command_type: system
3-
exec_timeout_secs: 900
3+
exec_timeout_secs: 1200
44
timeout:
55
- command: shell.exec
66
params:

.evergreen/config.yml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ command_type: system
1111
# Protect ourself against rogue test case, or curl gone wild, that runs forever
1212
# Good rule of thumb: the averageish length a task takes, times 5
1313
# That roughly accounts for variable system performance for various buildvariants
14-
exec_timeout_secs: 900
14+
exec_timeout_secs: 1200
1515

1616
# What to do when evergreen hits the timeout (`post:` tasks are run automatically)
1717
timeout:

src/cmap/connect.ts

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ function performInitialHandshake(
119119
response.ismaster = response.isWritablePrimary;
120120
}
121121

122+
if (response.helloOk) {
123+
conn.helloOk = true;
124+
}
125+
122126
const supportedServerErr = checkSupportedServer(response, options);
123127
if (supportedServerErr) {
124128
callback(supportedServerErr);
@@ -158,6 +162,7 @@ function performInitialHandshake(
158162
export interface HandshakeDocument extends Document {
159163
ismaster?: boolean;
160164
hello?: boolean;
165+
helloOk?: boolean;
161166
client: ClientMetadata;
162167
compression: string[];
163168
saslSupportedMechs?: string;
@@ -170,6 +175,7 @@ function prepareHandshakeDocument(authContext: AuthContext, callback: Callback<H
170175

171176
const handshakeDoc: HandshakeDocument = {
172177
[serverApi?.version ? 'hello' : 'ismaster']: true,
178+
helloOk: true,
173179
client: options.metadata || makeClientMetadata(options),
174180
compression: compressors
175181
};

src/cmap/connection.ts

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
164164
destroyed: boolean;
165165
lastIsMasterMS?: number;
166166
serverApi?: ServerApi;
167+
helloOk?: boolean;
167168
/** @internal */
168169
[kDescription]: StreamDescription;
169170
/** @internal */

src/sdam/monitor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ function checkServer(monitor: Monitor, callback: Callback<Document>) {
227227

228228
const connection = monitor[kConnection];
229229
if (connection && !connection.closed) {
230-
const { serverApi } = connection;
230+
const { serverApi, helloOk } = connection;
231231
const connectTimeoutMS = monitor.options.connectTimeoutMS;
232232
const maxAwaitTimeMS = monitor.options.heartbeatFrequencyMS;
233233
const topologyVersion = monitor[kServer].description.topologyVersion;
234234
const isAwaitable = topologyVersion != null;
235235

236236
const cmd = {
237-
[serverApi?.version ? 'hello' : 'ismaster']: true,
237+
[serverApi?.version || helloOk ? 'hello' : 'ismaster']: true,
238238
...(isAwaitable && topologyVersion
239239
? { maxAwaitTimeMS, topologyVersion: makeTopologyVersion(topologyVersion) }
240240
: {})

src/sdam/server_description.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export function parseServerType(ismaster?: Document): ServerType {
222222
if (ismaster.setName) {
223223
if (ismaster.hidden) {
224224
return ServerType.RSOther;
225-
} else if (ismaster.ismaster) {
225+
} else if (ismaster.ismaster || ismaster.isWritablePrimary) {
226226
return ServerType.RSPrimary;
227227
} else if (ismaster.secondary) {
228228
return ServerType.RSSecondary;

test/functional/mongo_client_options.test.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ describe('MongoClient Options', function () {
6464
const args = Array.prototype.slice.call(arguments);
6565
const ns = args[0];
6666
const command = args[1];
67-
const options = args[2];
68-
if (ns.toString() === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) {
69-
stub.restore();
67+
const options = args[2] || {};
68+
if (
69+
ns.toString() === 'admin.$cmd' &&
70+
(command.ismaster || command.hello) &&
71+
options.exhaustAllowed
72+
) {
7073
expect(options).property('socketTimeoutMS').to.equal(0);
74+
stub.restore();
7175
client.close(done);
7276
}
73-
7477
stub.wrappedMethod.apply(this, args);
7578
});
7679
});
@@ -90,13 +93,16 @@ describe('MongoClient Options', function () {
9093
const args = Array.prototype.slice.call(arguments);
9194
const ns = args[0];
9295
const command = args[1];
93-
const options = args[2];
94-
if (ns.toString() === 'admin.$cmd' && command.ismaster && options.exhaustAllowed) {
95-
stub.restore();
96+
const options = args[2] || {};
97+
if (
98+
ns.toString() === 'admin.$cmd' &&
99+
(command.ismaster || command.hello) &&
100+
options.exhaustAllowed
101+
) {
96102
expect(options).property('socketTimeoutMS').to.equal(510);
103+
stub.restore();
97104
client.close(done);
98105
}
99-
100106
stub.wrappedMethod.apply(this, args);
101107
});
102108
});

test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

test/spec/server-discovery-and-monitoring/errors/error_handling_handshake.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ phases:
55
responses:
66
- - a:27017
77
- ok: 1
8-
ismaster: true
8+
helloOk: true
9+
isWritablePrimary: true
910
hosts:
1011
- a:27017
1112
setName: rs

test/spec/server-discovery-and-monitoring/errors/generate-error-tests.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def write_test(filename, data):
3535
ERR_CODES = {
3636
'InterruptedAtShutdown': (11600,),
3737
'InterruptedDueToReplStateChange': (11602,),
38-
'NotMasterOrSecondary': (13436,),
38+
'NotPrimaryOrSecondary': (13436,),
3939
'PrimarySteppedDown': (189,),
4040
'ShutdownInProgress': (91,),
41-
'NotMaster': (10107,),
42-
'NotMasterNoSlaveOk': (13435,),
41+
'NotWritablePrimary': (10107,),
42+
'NotPrimaryNoSecondaryOk': (13435,),
4343
'LegacyNotPrimary': (10058,),
4444
}
4545

@@ -139,7 +139,7 @@ def create_stale_generation_tests():
139139

140140
def create_pre_42_tests():
141141
tmp = template('pre-42.yml.template')
142-
# All "not master"/"node is recovering" clear the pool on <4.2
142+
# All "not writable primary"/"node is recovering" clear the pool on <4.2
143143
for error_name in ERR_CODES:
144144
test_name = f'pre-42-{error_name}'
145145
error_code, = ERR_CODES[error_name]

test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

test/spec/server-discovery-and-monitoring/errors/non-stale-network-error.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ phases:
55
responses:
66
- - a:27017
77
- ok: 1
8-
ismaster: true
8+
helloOk: true
9+
isWritablePrimary: true
910
hosts:
1011
- a:27017
1112
setName: rs

test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

test/spec/server-discovery-and-monitoring/errors/non-stale-network-timeout-error.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ phases:
55
responses:
66
- - a:27017
77
- ok: 1
8-
ismaster: true
8+
helloOk: true
9+
isWritablePrimary: true
910
hosts:
1011
- a:27017
1112
setName: rs

test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedAtShutdown.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ phases:
66
responses:
77
- - a:27017
88
- ok: 1
9-
ismaster: true
9+
helloOk: true
10+
isWritablePrimary: true
1011
hosts:
1112
- a:27017
1213
setName: rs

test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-InterruptedDueToReplStateChange.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ phases:
66
responses:
77
- - a:27017
88
- ok: 1
9-
ismaster: true
9+
helloOk: true
10+
isWritablePrimary: true
1011
hosts:
1112
- a:27017
1213
setName: rs

test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],

test/spec/server-discovery-and-monitoring/errors/non-stale-topologyVersion-greater-LegacyNotPrimary.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ phases:
66
responses:
77
- - a:27017
88
- ok: 1
9-
ismaster: true
9+
helloOk: true
10+
isWritablePrimary: true
1011
hosts:
1112
- a:27017
1213
setName: rs
+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Non-stale topologyVersion greater NotMasterNoSlaveOk error",
2+
"description": "Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error",
33
"uri": "mongodb://a/?replicaSet=rs",
44
"phases": [
55
{
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],
@@ -51,7 +52,7 @@
5152
}
5253
},
5354
{
54-
"description": "Non-stale topologyVersion greater NotMasterNoSlaveOk error marks server Unknown",
55+
"description": "Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error marks server Unknown",
5556
"applicationErrors": [
5657
{
5758
"address": "a:27017",
@@ -60,7 +61,7 @@
6061
"type": "command",
6162
"response": {
6263
"ok": 0,
63-
"errmsg": "NotMasterNoSlaveOk",
64+
"errmsg": "NotPrimaryNoSecondaryOk",
6465
"code": 13435,
6566
"topologyVersion": {
6667
"processId": {
+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Autogenerated tests for SDAM error handling, see generate-error-tests.py
2-
description: Non-stale topologyVersion greater NotMasterNoSlaveOk error
2+
description: Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error
33
uri: mongodb://a/?replicaSet=rs
44
phases:
55
- description: Primary A is discovered
66
responses:
77
- - a:27017
88
- ok: 1
9-
ismaster: true
9+
helloOk: true
10+
isWritablePrimary: true
1011
hosts:
1112
- a:27017
1213
setName: rs
@@ -29,15 +30,15 @@ phases:
2930
logicalSessionTimeoutMinutes: null
3031
setName: rs
3132

32-
- description: Non-stale topologyVersion greater NotMasterNoSlaveOk error marks server Unknown
33+
- description: Non-stale topologyVersion greater NotPrimaryNoSecondaryOk error marks server Unknown
3334
applicationErrors:
3435
- address: a:27017
3536
when: afterHandshakeCompletes
3637
maxWireVersion: 9
3738
type: command
3839
response:
3940
ok: 0
40-
errmsg: NotMasterNoSlaveOk
41+
errmsg: NotPrimaryNoSecondaryOk
4142
code: 13435
4243
topologyVersion:
4344
processId:
+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Non-stale topologyVersion greater NotMasterOrSecondary error",
2+
"description": "Non-stale topologyVersion greater NotPrimaryOrSecondary error",
33
"uri": "mongodb://a/?replicaSet=rs",
44
"phases": [
55
{
@@ -9,7 +9,8 @@
99
"a:27017",
1010
{
1111
"ok": 1,
12-
"ismaster": true,
12+
"helloOk": true,
13+
"isWritablePrimary": true,
1314
"hosts": [
1415
"a:27017"
1516
],
@@ -51,7 +52,7 @@
5152
}
5253
},
5354
{
54-
"description": "Non-stale topologyVersion greater NotMasterOrSecondary error marks server Unknown",
55+
"description": "Non-stale topologyVersion greater NotPrimaryOrSecondary error marks server Unknown",
5556
"applicationErrors": [
5657
{
5758
"address": "a:27017",
@@ -60,7 +61,7 @@
6061
"type": "command",
6162
"response": {
6263
"ok": 0,
63-
"errmsg": "NotMasterOrSecondary",
64+
"errmsg": "NotPrimaryOrSecondary",
6465
"code": 13436,
6566
"topologyVersion": {
6667
"processId": {

0 commit comments

Comments
 (0)