Skip to content

Commit b991185

Browse files
PYTHON-2715 Use hello command for monitoring when supported (mongodb#654)
1 parent 8848029 commit b991185

File tree

182 files changed

+528
-410
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

+528
-410
lines changed

pymongo/ismaster.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,7 @@ def awaitable(self):
192192
@property
193193
def service_id(self):
194194
return self._doc.get('serviceId')
195+
196+
@property
197+
def hello_ok(self):
198+
return self._doc.get('helloOk', False)

pymongo/pool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ def __init__(self, sock, pool, address, id):
521521
self.max_message_size = MAX_MESSAGE_SIZE
522522
self.max_write_batch_size = MAX_WRITE_BATCH_SIZE
523523
self.supports_sessions = False
524+
self.hello_ok = None
524525
self.is_mongos = False
525526
self.op_msg_enabled = False
526527
self.listeners = pool.opts.event_listeners
@@ -568,10 +569,10 @@ def unpin(self):
568569
self.close_socket(ConnectionClosedReason.STALE)
569570

570571
def hello_cmd(self):
571-
if self.opts.server_api:
572+
if self.opts.server_api or self.hello_ok:
572573
return SON([(HelloCompat.CMD, 1)])
573574
else:
574-
return SON([(HelloCompat.LEGACY_CMD, 1)])
575+
return SON([(HelloCompat.LEGACY_CMD, 1), ('helloOk', True)])
575576

576577
def ismaster(self, all_credentials=None):
577578
return self._ismaster(None, None, None, all_credentials)
@@ -623,6 +624,7 @@ def _ismaster(self, cluster_time, topology_version,
623624
self.max_write_batch_size = ismaster.max_write_batch_size
624625
self.supports_sessions = (
625626
ismaster.logical_session_timeout_minutes is not None)
627+
self.hello_ok = ismaster.hello_ok
626628
self.is_mongos = ismaster.server_type == SERVER_TYPE.Mongos
627629
if performing_handshake and self.compression_settings:
628630
ctx = self.compression_settings.get_compression_context(

test/discovery_and_monitoring/errors/error_handling_handshake.json

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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
],
Lines changed: 5 additions & 4 deletions
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": {
Lines changed: 5 additions & 4 deletions
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)