Tweak spec test because pymongo unpins cursors eagerly after errors.
Tweak spec test for PoolClearedEvent ordering when MongoDB handshake fails (see DRIVERS-1785).
Only skip killCursors for some error codes.
Rely on SDAM error handling to close the connection after a state change error.
Add service_id to various events.
Retain reference to pinned sockets to prevent premptive closure by CPython's cyclic GC.
Fixes a noisy OperationFailure: Authentication failed error.
Do not attempt to create unneeded connections to arbiters, ghosts,
hidden members, or unknown members.
Mark server unknown and clear the pool when background connections fail.
Eagerly evict threads from the wait queue when pool is paused. Evicted
threads will raise the following error:
AutoReconnect('localhost:27017: connection pool paused')
Introduce PoolClearedEvent and ConnectionPoolListener.pool_ready.
CMAP spec test changes:
- CMAP unit tests should not use real monitors
- Assert that CMAP threads complete all scheduled operations
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.
The behavior for a list of mongoses is changed from "high availability" to
"load balancing". Before, the client connected to the lowest-latency mongos in
the list, and used it until a network error prompted it to re-evaluate all
mongoses' latencies and reconnect to one of them. In PyMongo 3, the client
monitors its network latency to all the mongoses continuously, and distributes
operations evenly among those with the lowest latency. See
high_availability.rst.
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.
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.
MongoReplicaSetClient's old monitor used "force" to get a socket even when the
pool had reached its max size. This was so complicated and bug-prone that I
prohibited it in the Server Discovery And Monitoring Spec: monitors use
dedicated sockets now instead of sharing a pool with the application.
The Server Discovery And Monitoring Spec has replaced the term "cluster"
with "topology", since "cluster" in MongoDB terminology should be reserved
for sharded clusters. "Topology" describes a single server, replica set, or a
set of mongoses.
The previous commit replaced "cluster" with "topology" in file names. Here
I replace the term in class and variable names.
MongoClient now supports all MongoReplicaSetClient's features.
Fix bugs and add features in the new MongoClient to bring it up
to spec. MongoReplicaSetClient is now a deprecated stub that
subclasses MongoClient.
Introduce new errors, NetworkTimeout and NotMasterError, to
communicate events that MongoClient must handle specially.
The new MongoClient, based on Cluster and Server,
includes functionality that had been split between the
old MongoClient and MongoReplicaSetClient. A
previous commit introduced the new MongoClient
but broke authentication.
Replace MongoClient with an implementation that relies on Cluster and Server. The new MongoClient takes over MongoReplicaSetClient's responsibilities.
Authentication, secondary-pinning, and Mongos high-availability are broken and will be reimplemented in a future commit. RS tests are temporarily disabled.