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.
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.
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.
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.
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.
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.
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.
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.