Skip to content

Commit b6d1eb3

Browse files
committed
PYTHON-2715 Use hello command for monitoring when supported (#654)
(cherry picked from commit b991185)
1 parent 2a6c6eb commit b6d1eb3

File tree

182 files changed

+628
-408
lines changed

Some content is hidden

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

182 files changed

+628
-408
lines changed

pymongo/ismaster.py

+4
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,7 @@ def awaitable(self):
193193
@property
194194
def service_id(self):
195195
return self._doc.get('serviceId')
196+
197+
@property
198+
def hello_ok(self):
199+
return self._doc.get('helloOk', False)

pymongo/pool.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ def __init__(self, sock, pool, address, id):
539539
self.max_message_size = MAX_MESSAGE_SIZE
540540
self.max_write_batch_size = MAX_WRITE_BATCH_SIZE
541541
self.supports_sessions = False
542+
self.hello_ok = None
542543
self.is_mongos = False
543544
self.op_msg_enabled = False
544545
self.listeners = pool.opts.event_listeners
@@ -586,10 +587,10 @@ def unpin(self):
586587
self.close_socket(ConnectionClosedReason.STALE)
587588

588589
def hello_cmd(self):
589-
if self.opts.server_api:
590+
if self.opts.server_api or self.hello_ok:
590591
return SON([(HelloCompat.CMD, 1)])
591592
else:
592-
return SON([(HelloCompat.LEGACY_CMD, 1)])
593+
return SON([(HelloCompat.LEGACY_CMD, 1), ('helloOk', True)])
593594

594595
def ismaster(self, all_credentials=None):
595596
return self._ismaster(None, None, None, all_credentials)
@@ -641,6 +642,7 @@ def _ismaster(self, cluster_time, topology_version,
641642
self.max_write_batch_size = ismaster.max_write_batch_size
642643
self.supports_sessions = (
643644
ismaster.logical_session_timeout_minutes is not None)
645+
self.hello_ok = ismaster.hello_ok
644646
self.is_mongos = ismaster.server_type == SERVER_TYPE.Mongos
645647
if performing_handshake and self.compression_settings:
646648
ctx = self.compression_settings.get_compression_context(

test/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/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/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/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/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/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/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-NotMasterNoSlaveOk.json renamed to test/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryNoSecondaryOk.json

+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": {

test/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-NotMasterOrSecondary.json renamed to test/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-NotPrimaryOrSecondary.json

+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": {

test/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-NotMaster.json renamed to test/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-NotWritablePrimary.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Non-stale topologyVersion greater NotMaster error",
2+
"description": "Non-stale topologyVersion greater NotWritablePrimary 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 NotMaster error marks server Unknown",
55+
"description": "Non-stale topologyVersion greater NotWritablePrimary 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": "NotMaster",
64+
"errmsg": "NotWritablePrimary",
6465
"code": 10107,
6566
"topologyVersion": {
6667
"processId": {

test/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-PrimarySteppedDown.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/discovery_and_monitoring/errors/non-stale-topologyVersion-greater-ShutdownInProgress.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/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-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/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-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/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-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/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-NotMasterNoSlaveOk.json renamed to test/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryNoSecondaryOk.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Non-stale topologyVersion missing NotMasterNoSlaveOk error",
2+
"description": "Non-stale topologyVersion missing 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 missing NotMasterNoSlaveOk error marks server Unknown",
55+
"description": "Non-stale topologyVersion missing 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
}
6667
}

test/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-NotMasterOrSecondary.json renamed to test/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-NotPrimaryOrSecondary.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Non-stale topologyVersion missing NotMasterOrSecondary error",
2+
"description": "Non-stale topologyVersion missing 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 missing NotMasterOrSecondary error marks server Unknown",
55+
"description": "Non-stale topologyVersion missing 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
}
6667
}

test/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-NotMaster.json renamed to test/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-NotWritablePrimary.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Non-stale topologyVersion missing NotMaster error",
2+
"description": "Non-stale topologyVersion missing NotWritablePrimary 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 missing NotMaster error marks server Unknown",
55+
"description": "Non-stale topologyVersion missing NotWritablePrimary 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": "NotMaster",
64+
"errmsg": "NotWritablePrimary",
6465
"code": 10107
6566
}
6667
}

test/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-PrimarySteppedDown.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/discovery_and_monitoring/errors/non-stale-topologyVersion-missing-ShutdownInProgress.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/discovery_and_monitoring/errors/non-stale-topologyVersion-proccessId-changed-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/discovery_and_monitoring/errors/non-stale-topologyVersion-proccessId-changed-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
],

0 commit comments

Comments
 (0)