Commit Graph

68 Commits

Author SHA1 Message Date
Steven Silvester
5578999a90
PYTHON-1834 Use a code formatter (#852) 2022-02-09 06:44:28 -06:00
Steven Silvester
dd6c140d43
PYTHON-3060 Add typings to pymongo package (#831) 2022-02-02 21:12:36 -06:00
Shane Harvey
c94a3ad1df
PYTHON-2585 Remove legacy multi-auth code (#816) 2021-12-09 18:00:41 -08:00
Shane Harvey
12a6af7ab6
PYTHON-2981 Stop using MongoClient.address for hashing and equality (#795) 2021-11-17 12:31:59 -08:00
Shane Harvey
b342990934
PYTHON-2164 Add MongoClient.options, remove redundant properties (#772) 2021-11-03 11:21:33 -07:00
Julius Park
6bb8a1f411
PYTHON-2823 Allow custom service names with srvServiceName URI option (#749) 2021-10-08 11:23:21 -07:00
Bernie Hackett
ad4315134c PYTHON-2803 Get rid of most uses of 'master'
This change also resolves PYTHON-2848 for MongoDB 4.0.
2021-09-13 12:50:49 -07:00
Shane Harvey
3e02957998 PYTHON-2288 Finish removing IsMaster from docs 2021-08-06 12:33:26 -07:00
Prashant Mital
3f8c104157
PYTHON-2288 Remove IsMaster (#690) 2021-07-29 10:32:51 -07:00
Prashant Mital
ff6ca53328
PYTHON-2572 Introduce NotPrimaryError and deprecate NotMasterError (#646) 2021-06-22 13:24:07 -07:00
Bernie Hackett
cf877e95c7 PYTHON-2503 Always use time.monotonic
For monotonic time needs.
2021-01-25 12:48:31 -08:00
Bernie Hackett
6c2d629006 PYTHON-2133 Remove Py2 compatibility from pymongo 2021-01-19 21:15:20 -08:00
Shane Harvey
6c92e6c67e
PYTHON-2433 Fix Python 3 ServerDescription/Exception memory leak (#520)
When the SDAM monitor check fails, a ServerDescription is created from
the exception. This exception is kept alive via the
ServerDescription.error field. Unfortunately, the exception's traceback
contains a reference to the previous ServerDescription. Altogether this
means that each consecutively failing check leaks memory by building an
ever growing chain of ServerDescription -> Exception -> Traceback ->
Frame -> ServerDescription -> ... objects.

This change breaks the chain and prevents the memory leak by clearing
the Exception's __traceback__, __context__, and __cause__ fields.
2020-11-20 18:58:47 -08:00
Shane Harvey
b04e3343cb
PYTHON-2328 Reset the connection pool in Topology.on_change (#470)
PYTHON-2304 Ensure _RttMonitor closes socket on when the client is closed
2020-07-27 13:27:05 -07:00
Shane Harvey
1c29c1a65e
PYTHON-2299 Add the "awaited" field to heartbeat events (#457) 2020-07-08 14:02:34 -07:00
Shane Harvey
1f4123e4bf PYTHON-2123 Streaming heartbeat protocol
MongoClient now requires 2 connections and 2 threads to each MongoDB 4.4+ server.
With one connection, the server streams (or pushes) updated heartbeat info.
With the other connection, the client periodically pings the server to
establish an accurate round-trip time (RTT). This change optimizes the
discovery of server state changes such as replica set elections.

Additional changes:
- Mark server Unknown before retrying isMaster check.
- Always reset the pool _after_ marking the server unknown.
- Configure fail point before creating the client in test SpecRunner.
- Unfreeze with replSetFreeze:0 to ensure a speedy elections in test suite.
2020-07-01 14:49:46 -07:00
Shane Harvey
9a9f42bb99 PYTHON-2236 Reset the server pool only after marking the server Unknown 2020-06-08 11:48:44 -07:00
Shane Harvey
350ada10d5 PYTHON-2206 Rename pool_id to generation to better match CMAP spec 2020-04-16 11:46:54 -07:00
Shane Harvey
0b24e1e0b7 PYTHON-2126 Refactor monitor to create PeriodicExecutor in one place 2020-02-14 13:11:34 -08:00
Prashant Mital
b834e312a3
PYTHON-1872 Fix SrvMonitor related test failures 2019-06-14 16:34:06 -07:00
Prashant Mital
f85a9f9450
PYTHON-1675 SRV polling for mongos discovery 2019-06-10 12:51:49 -07:00
Shane Harvey
0aefc6c19b PYTHON-1434 Update max cluster time even when heartbeats fail 2018-02-26 11:00:00 -08:00
Shane Harvey
1fa894d757 PYTHON-1434 Don't resend client metadata on the same socket 2018-02-26 11:00:00 -08:00
Bernie Hackett
507f954ed4 Update copyright dates 2017-12-01 17:23:39 -08:00
Shane Harvey
2a05236f61 PYTHON-1332 Only gossip cluster time on >= 3.6.
Do not add readConcern to explain.
Test explain with collation.
2017-11-30 14:53:14 -08:00
A. Jesse Jiryu Davis
dcd8f68994 PYTHON-1332 - send $clusterTime with isMaster 2017-10-23 18:01:59 -04:00
Shane Harvey
f0b847adb8 PYTHON-1329 Refactor wire protocol message parsing.
Use _OpReply class instead of passing bytes around.
Remove unnecessary operation argument to receive message.
Move _first_batch to message.py to avoid circular import.
2017-10-09 15:11:50 -07:00
Bernie Hackett
81b93a251d PYTHON-1141 - Always publish failed event when heartbeats fail 2016-09-02 15:35:56 -07:00
A. Jesse Jiryu Davis
78c8a4522d PYTHON-1119 - Monitor sends metadata when reconnecting. 2016-08-01 02:51:40 -04:00
Luke Lovett
84875ed38f PYTHON-1119 - Ensure that the command name is first when issuing 'ismaster' command. 2016-07-27 09:58:35 -07:00
Luke Lovett
c9bbfa7ace PYTHON-1119 - Implement the client metadata capture specification. 2016-07-26 10:35:55 -07:00
A. Jesse Jiryu Davis
a2f97f92a4 PYTHON-1105 Configurable heartbeatFrequencyMS. 2016-07-08 16:30:56 -04:00
aherlihy
d98a745700 PYTHON-1067 - Implement SDAM Monitoring 2016-06-14 15:20:19 +02:00
A. Jesse Jiryu Davis
4618998dd1 PYTHON-983 Idle monitor threads use excessive CPU. 2015-10-14 23:52:18 -04:00
Bernie Hackett
164cc34320 PYTHON-975 - Name our threads 2015-08-21 17:06:44 -07:00
A. Jesse Jiryu Davis
5648745d0b PYTHON-863 - Ref cycle in Monitor. 2015-04-02 13:42:17 -04:00
Bernie Hackett
aec685b374 Fix up copyright dates. 2015-03-25 11:55:02 -07:00
A. Jesse Jiryu Davis
41bf0080cf PYTHON-857 - Collection and Database use SocketInfo.command. 2015-03-19 14:17:26 -04:00
A. Jesse Jiryu Davis
c000354416 PYTHON-857 - Use client._get_socket_for_writes for OP_UPDATE and OP_DELETE.
Also check max document size in legacy writes.
2015-03-16 17:35:59 -04:00
A. Jesse Jiryu Davis
f737ec0db9 PYTHON-728 - Translate socket.error to ConnectionFailure in pool.py.
SocketInfo and Pool are now responsible for catching all socket.errors and
gaierrors and translating them to ConnectionFailure. Server and MongoClient
need no longer worry about anything but ConnectionFailure. Functions in pool.py
and network.py still throw socket.errors into SocketInfo and Pool.
2015-03-11 19:57:01 -04:00
A. Jesse Jiryu Davis
7f42430978 PYTHON-847 Remove disconnect(), synonym of MongoClient.close().
close() seems more standard among MongoDB drivers.
2015-02-25 14:52:34 -05:00
A. Jesse Jiryu Davis
9da835ab3d PYTHON-825 BSON API changes and internal options handling.
This change resolves four issues:

PYTHON-826 The new codec_options submodule is moved from pymongo to bson.

PYTHON-827 Use codec_options in BSON APIs.

Functions and methods of the bson module that accepted the options as_class,
tz_aware, and uuid_subtype now accept a codec_options parameter instead.

For example, the function definition for bson.decode_all changes from this:

def decode_all(data, as_class=dict, tz_aware=True,
               uuid_subtype=OLD_UUID_SUBTYPE)

to:

def decode_all(data, codec_options=CodecOptions())

The following functions are changed:

- decode_all
- decode_iter
- decode_file_iter

The following methods are changed:

- BSON.encode
- BSON.decode

This is a breaking change for any application that uses the BSON API directly
and changes any of the named parameter defaults. No changes are required for
applications that use the default values for these options. The behavior
remains the same.

PYTHON-828 Internal BSON module changes to support CodecOptions

The pure Python BSON module passes around a CodecOptions instance instead of
as_class, tz_aware, and uuid_subtype. C extensions pass these values around in
a struct.

PYTHON-801 Rename uuid_subtype to uuid_representation.
2015-02-05 23:09:23 -06:00
A. Jesse Jiryu Davis
9b208caed9 PYTHON-829 Call ismaster on each new connection.
Call ismaster on each new connection and store the results on the SocketInfo
instance.

The upcoming Authentication Spec says: "If credentials exist, upon opening a
socket, drivers MUST send an isMaster command immediately. This allows a driver
to determine whether the server is an Arbiter. Calling ismaster additionally
allows the driver to know if the default authentication method for each socket
is MONGODB-CR or SCRAM-SHA-1, avoiding races when the driver repopulates the
pool after a disconnect."

In theory we could choose not to call ismaster if there are no credentials, but
it's simpler always to call ismaster, and paves the way for future breaking
changes to the wire protocol besides the current breaking change to
authentication.
2015-01-26 16:54:14 -05:00
A. Jesse Jiryu Davis
acd90be727 Reset average round trip time if a server is disconnected.
The Server Discovery And Monitoring Spec says if a server "changes from a known
type to Unknown its RTT is set to null."
2015-01-26 15:38:24 -05:00
A. Jesse Jiryu Davis
a6bb78d441 Stop thread sooner after Monitor is deleted.
Otherwise the PeriodicExecutor waits up to 10 seconds to stop and unregister
itself. Not a real problem since the executor is a daemon thread, but it makes
TestMonitor slow and unreliable.
2015-01-12 18:03:15 -05:00
A. Jesse Jiryu Davis
1ab83f72cf PYTHON-799 Break ref cycle in Monitor.
Previous code to avoid the cycle was wrong.
2015-01-05 15:21:50 -05:00
A. Jesse Jiryu Davis
f0daebf4bb PYTHON-799 Create a PeriodicExecutor class for background monitoring.
The executor will also be used to solve a deadlock in Cursor.__del__.
2014-12-17 13:19:05 -05:00
A. Jesse Jiryu Davis
6ae50e2ea1 Update a comment in Monitor. 2014-12-12 10:04:12 -05:00
A. Jesse Jiryu Davis
ecc55f502a New method to calculate average round trip time.
Replace 5-sample moving average with exponentially weighted average,
required by the upcoming Server Selection Spec. Move responsibility for
tracking the average from ServerDescription to Monitor. Now the
ServerDescription only knows the average at the time it was created.
2014-12-03 16:30:35 -05:00
A. Jesse Jiryu Davis
990afe5707 Unused import in monitor. 2014-11-24 18:15:35 -05:00