You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the driver is wrapping the command in a ``$query`` field in order to pass a readPreference to a mongos (see `ReadPreference and Mongos <./find_getmore_killcursors_commands.rst#readpreference-and-mongos>`_), the driver SHOULD NOT add the ``lsid`` as a top-level field, and MUST add the ``lsid`` as a field of the ``$query``
671
+
If the driver is wrapping the command in a ``$query`` field for non-OP_MSG messages in order to pass a readPreference to a
672
+
mongos (see `ReadPreference and Mongos <./find_getmore_killcursors_commands.rst#readpreference-and-mongos>`_),
673
+
the driver SHOULD NOT add the ``lsid`` as a top-level field, and MUST add the ``lsid`` as a field of the ``$query``
670
674
671
675
.. code:: typescript
672
676
@@ -781,12 +785,9 @@ In case of an error, the server response has the following format:
781
785
782
786
Drivers MUST ignore any errors returned by the ``endSessions`` command.
783
787
784
-
Drivers that do not implement a server session pool MUST run the ``endSessions``
785
-
command when the ``ClientSession.endSession`` method is called. Drivers that do
786
-
implement a server session pool SHOULD run the ``endSessions`` command once when
787
-
the ``MongoClient`` instance is shut down. If the number of sessions is very large
788
-
the ``endSessions`` command SHOULD be run multiple times to end 10,000 sessions at
789
-
a time (in order to avoid creating excessively large commands).
788
+
The ``endSessions`` command MUST be run once when the ``MongoClient`` instance is shut down.
789
+
If the number of sessions is very large the ``endSessions`` command SHOULD be run
790
+
multiple times to end 10,000 sessions at a time (in order to avoid creating excessively large commands).
790
791
791
792
When connected to a sharded cluster the ``endSessions`` command can be sent to any
792
793
mongos. When connected to a replica set the ``endSessions`` command MUST be sent to
@@ -801,15 +802,15 @@ corresponding ``ServerSession``. However, starting a server session might requir
801
802
round trip to the server (which can be avoided by generating the session ID
802
803
locally) and ending a session requires a separate round trip to the server.
803
804
Drivers can operate more efficiently and put less load on the server if they
804
-
cache ``ServerSession`` instances for reuse. To this end drivers SHOULD
805
+
cache ``ServerSession`` instances for reuse. To this end drivers MUST
805
806
implement a server session pool containing ``ServerSession`` instances
806
807
available for reuse. A ``ServerSession`` pool MUST belong to a ``MongoClient``
807
808
instance and have the same lifetime as the ``MongoClient`` instance.
808
809
809
-
If a driver has a server session pool, then when a new ``ClientSession`` is started
810
-
it MUST attempt to acquire a server session from the server session pool. See
811
-
the algorithm below for the steps to follow when attempting to acquire a
812
-
``ServerSession`` from the server session pool.
810
+
When a new implicit ``ClientSession`` is started it MUST NOT attempt to acquire a server
811
+
session from the server session pool immediately. When a new explicit ``ClientSession`` is started
812
+
it MAY attempt to acquire a server session from the server session pool immediately.
813
+
See the algorithm below for the steps to follow when attempting to acquire a ``ServerSession`` from the server session pool.
813
814
814
815
Note that ``ServerSession`` instances acquired from the server session pool might have as
815
816
little as one minute left before becoming stale and being discarded server
@@ -825,18 +826,16 @@ to the hello and legacy hello commands. The smallest reported timeout is recorde
825
826
``logicalSessionTimeoutMinutes`` property of the ``TopologyDescription``. See the
826
827
Server Discovery And Monitoring specification for details.
827
828
828
-
If a driver has a server session pool, then when a ``ClientSession`` is ended it
829
-
MUST return the server session to the server session pool. See the algorithm
830
-
below for the steps to follow when returning a ``ServerSession`` instance to the server
829
+
When a ``ClientSession`` is ended it MUST return the server session to the server session pool.
830
+
See the algorithm below for the steps to follow when returning a ``ServerSession`` instance to the server
831
831
session pool.
832
832
833
833
The server session pool has no maximum size. The pool only shrinks when a
834
834
server session is acquired for use or discarded.
835
835
836
-
If a driver has a server session pool, then when a ``MongoClient`` instance is
837
-
closed the driver MUST proactively inform the server that the pooled server
838
-
sessions will no longer be used by sending one or more ``endSessions`` commands to the
839
-
server.
836
+
When a ``MongoClient`` instance is closed the driver MUST proactively inform the
837
+
server that the pooled server sessions will no longer be used by sending one or
838
+
more ``endSessions`` commands to the server.
840
839
841
840
The server session pool is modeled as a double ended queue. The algorithms
842
841
below require the ability to add and remove ``ServerSession`` instances from the front of
@@ -1143,17 +1142,24 @@ Test Plan
1143
1142
* Attach a command started listener that collects each command's lsid
* Wait for all operations to complete successfully
1155
+
* Assert the following across at least 5 retries of the above test:
1156
+
1157
+
* Drivers MUST assert that exactly one session is used for all operations at least once across the retries of this test.
1158
+
1159
+
* Note that it's possible, although rare, for >1 server session to be used because the session is not released until after the connection is checked in.
1160
+
1161
+
* Drivers MUST assert that the number of allocated sessions is strictly less than the number of concurrent operations in every retry of this test. In this instance it would be less than (but NOT equal to) 8.
1154
1162
1155
-
* Wait for all operations to complete
1156
-
* Assert that all commands contain the same lsid
1157
1163
1158
1164
1159
1165
Tests that only apply to drivers that have not implemented OP_MSG and are still using OP_QUERY
@@ -1323,6 +1329,13 @@ is needed and, known it will be used, after connection checkout succeeds.
1323
1329
It is still possible that via explicit sessions or cursors, which hold on to the session they started with, a driver could over allocate sessions.
1324
1330
But those scenarios are extenuating and outside the scope of solving in this spec.
1325
1331
1332
+
Why should drivers NOT attempt to release a serverSession before checking back in the operation's connection?
0 commit comments