Skip to content

Commit f588412

Browse files
committed
PYTHON-1842 Implement Connection Monitoring and Pooling spec
1 parent 876db99 commit f588412

Some content is hidden

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

42 files changed

+2366
-272
lines changed

doc/api/pymongo/monitoring.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
.. autoclass:: TopologyListener
1818
:members:
1919
:inherited-members:
20+
.. autoclass:: ConnectionPoolListener
21+
:members:
22+
:inherited-members:
23+
2024
.. autoclass:: CommandStartedEvent
2125
:members:
2226
:inherited-members:
@@ -53,3 +57,43 @@
5357
.. autoclass:: ServerHeartbeatFailedEvent
5458
:members:
5559
:inherited-members:
60+
61+
.. autoclass:: PoolCreatedEvent
62+
:members:
63+
:inherited-members:
64+
.. autoclass:: PoolClearedEvent
65+
:members:
66+
:inherited-members:
67+
.. autoclass:: PoolClosedEvent
68+
:members:
69+
:inherited-members:
70+
71+
.. autoclass:: ConnectionCreatedEvent
72+
:members:
73+
:inherited-members:
74+
.. autoclass:: ConnectionReadyEvent
75+
:members:
76+
:inherited-members:
77+
78+
.. autoclass:: ConnectionClosedReason
79+
:members:
80+
81+
.. autoclass:: ConnectionClosedEvent
82+
:members:
83+
:inherited-members:
84+
.. autoclass:: ConnectionCheckOutStartedEvent
85+
:members:
86+
:inherited-members:
87+
88+
.. autoclass:: ConnectionCheckOutFailedReason
89+
:members:
90+
91+
.. autoclass:: ConnectionCheckOutFailedEvent
92+
:members:
93+
:inherited-members:
94+
.. autoclass:: ConnectionCheckedOutEvent
95+
:members:
96+
:inherited-members:
97+
.. autoclass:: ConnectionCheckedInEvent
98+
:members:
99+
:inherited-members:

doc/changelog.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ Version 3.9 adds support for MongoDB 4.2. Highlights include:
3737
time, with at-most-once semantics.
3838
- Support for retryable reads and the ``retryReads`` URI option which is
3939
enabled by default. See the :class:`~pymongo.mongo_client.MongoClient`
40-
documentation for details.
40+
documentation for details. Now that supported operations are retried
41+
automatically and transparently, users should consider adjusting any custom
42+
retry logic to prevent an application from inadvertently retrying for too
43+
long.
4144
- Support zstandard for wire protocol compression.
4245
- Support for periodically polling DNS SRV records to update the mongos proxy
4346
list without having to change client configuration.
4447
- New method :meth:`pymongo.database.Database.aggregate` to support running
4548
database level aggregations.
46-
47-
Now that supported operations are retried automatically and transparently,
48-
users should consider adjusting any custom retry logic to prevent
49-
an application from inadvertently retrying for too long.
49+
- Support for publishing Connection Monitoring and Pooling events via the new
50+
:class:`~pymongo.monitoring.ConnectionPoolListener` class. See
51+
:mod:`~pymongo.monitoring` for an example.
5052

5153
.. _URI options specification: https://github.com/mongodb/specifications/blob/master/source/uri-options/uri-options.rst
5254

pymongo/client_options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ def _parse_pool_options(options):
110110
"""Parse connection pool options."""
111111
max_pool_size = options.get('maxpoolsize', common.MAX_POOL_SIZE)
112112
min_pool_size = options.get('minpoolsize', common.MIN_POOL_SIZE)
113-
default_idle_seconds = common.validate_timeout_or_none(
114-
'maxidletimems', common.MAX_IDLE_TIME_MS)
115-
max_idle_time_seconds = options.get('maxidletimems', default_idle_seconds)
113+
max_idle_time_seconds = options.get(
114+
'maxidletimems', common.MAX_IDLE_TIME_SEC)
116115
if max_pool_size is not None and min_pool_size > max_pool_size:
117116
raise ValueError("minPoolSize must be smaller or equal to maxPoolSize")
118117
connect_timeout = options.get('connecttimeoutms', common.CONNECT_TIMEOUT)
119118
socket_keepalive = options.get('socketkeepalive', True)
120119
socket_timeout = options.get('sockettimeoutms')
121-
wait_queue_timeout = options.get('waitqueuetimeoutms')
120+
wait_queue_timeout = options.get(
121+
'waitqueuetimeoutms', common.WAIT_QUEUE_TIMEOUT)
122122
wait_queue_multiple = options.get('waitqueuemultiple')
123123
event_listeners = options.get('event_listeners')
124124
appname = options.get('appname')

pymongo/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@
8888
# Default value for maxIdleTimeMS.
8989
MAX_IDLE_TIME_MS = None
9090

91+
# Default value for maxIdleTimeMS in seconds.
92+
MAX_IDLE_TIME_SEC = None
93+
94+
# Default value for waitQueueTimeoutMS in seconds.
95+
WAIT_QUEUE_TIMEOUT = None
96+
9197
# Default value for localThresholdMS.
9298
LOCAL_THRESHOLD_MS = 15
9399

pymongo/cursor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
_RawBatchGetMore,
3838
_Query,
3939
_RawBatchQuery)
40+
from pymongo.monitoring import ConnectionClosedReason
4041

4142

4243
_QUERY_OPTIONS = {
@@ -303,7 +304,8 @@ def __die(self, synchronous=False):
303304
# If this is an exhaust cursor and we haven't completely
304305
# exhausted the result set we *must* close the socket
305306
# to stop the server from sending more data.
306-
self.__exhaust_mgr.sock.close()
307+
self.__exhaust_mgr.sock.close_socket(
308+
ConnectionClosedReason.ERROR)
307309
else:
308310
address = _CursorAddress(
309311
self.__address, self.__collection.full_name)

pymongo/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class InvalidURI(ConfigurationError):
234234
"""Raised when trying to parse an invalid mongodb URI."""
235235

236236

237-
class ExceededMaxWaiters(Exception):
237+
class ExceededMaxWaiters(PyMongoError):
238238
"""Raised when a thread tries to get a connection from a pool and
239239
``maxPoolSize * waitQueueMultiple`` threads are already waiting.
240240

0 commit comments

Comments
 (0)