8000 DOCSP-35923: csot page by rustagir · Pull Request #657 · mongodb/docs-java · GitHub
[go: up one dir, main page]

Skip to content

DOCSP-35923: csot page #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MW + MK PR fixes
  • Loading branch information
rustagir committed Mar 24, 2025
commit 4c4e2355be3c05f430f90640ddf24175da3151a3
2 changes: 1 addition & 1 deletion source/connection/specify-connection-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Specify Connection Options
.. toctree::

Stable API </connection/specify-connection-options/stable-api>
Single Timeout Setting </connection/specify-connection-options/csot>
Limit Execution Time </connection/specify-connection-options/csot>
Connection Pools </connection/specify-connection-options/connection-pools>
Cluster Settings </connection/specify-connection-options/cluster-settings>
Server Settings </connection/specify-connection-options/server-settings>
Expand Down
18 changes: 12 additions & 6 deletions source/connection/specify-connection-options/connection-pools.txt
Original file line number Diff line number Diff line change
10000 Expand Up @@ -87,9 +87,12 @@ see the corresponding syntax:

* - ``maxPoolSize``

- Maximum number of connections opened in the pool. When the
connection pool reaches the maximum number of connections, new
connections wait for up to the amount of time set by ``timeoutMS``.
- Maximum number of connections opened in the pool. If an
operation needs a new connection while the connection pool has
``maxPoolSize`` connections open, the new
operation waits for a new connection to open. To limit this
waiting time, use the single timeout setting. To learn more,
see the :ref:`java-csot` guide.

*Default:* ``100``

Expand All @@ -103,10 +106,13 @@ see the corresponding syntax:

* - ``waitQueueTimeoutMS`` *(deprecated)*

- Maximum wait time in milliseconds that an operation can wait for
- This option is deprecated. You can configure this timeout by
setting the the :ref:`client-level timeout <java-csot>`
instead.

Maximum wait time in milliseconds that an operation can wait for
a connection to become available. A value of ``0`` means there
is no limit. Set the :ref:`client-level timeout <java-csot>` to
replace the functionality of this deprecated option.
is no limit.

*Default*: ``120000`` (120 seconds)

Expand Down
76 changes: 40 additions & 36 deletions source/connection/specify-connection-options/csot.txt
10000
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ To specify a timeout when connecting to a MongoDB deployment, set the
``timeoutMS`` connection option to the timeout length in milliseconds. You can
set the ``timeoutMS`` option in the following ways:

- Using the ``timeout()`` method from the
- Calling the ``timeout()`` method from the
``MongoClientSettings.Builder`` class
- Setting the ``timeoutMS`` parameter in your connection string

Select from the following :guilabel:`MongoClientSettings` and
:guilabel:`Connection String` tabs to view how to set a client-level
timeout of 5 seconds by using each method:
The following code examples set a client-level timeout of ``5`` seconds.
Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection
String` tab to see the corresponding code.

.. tabs::

.. tab:: MongoClientSettings
:tabid: mongoclientsettings

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-mongoclientsettings
:end-before: end-mongoclientsettings
Expand All @@ -62,14 +62,14 @@ timeout of 5 seconds by using each method:
.. tab:: Connection String
:tabid: connection-string

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-string
:end-before: end-string
:dedent:

Behavior
~~~~~~~~
Accepted Timeout Values
~~~~~~~~~~~~~~~~~~~~~~~

The following table describes the timeout behavior corresponding to the
accepted values for ``timeoutMS``:
Expand All @@ -81,11 +81,11 @@ accepted values for ``timeoutMS``:
* - Value
- Behavior

* - Positive value
* - Positive integer
- Sets the timeout to use for operation completion.

* - ``0``
- Sets an infinite timeout.
- Specifies that operations never time out.

* - ``null`` or unset
- | Defers the timeout behavior to the following settings:
Expand All @@ -99,11 +99,11 @@ accepted values for ``timeoutMS``:
| These settings are deprecated and are ignored if you set ``timeoutMS``.

If you specify the ``timeoutMS`` option, the driver automatically applies the
specified timeout for each server operation. The following code example specifies
a timeout of 5 seconds at the client level, and then calls the
specified timeout to each server operation. The following code example specifies
a timeout of ``5`` seconds at the client level, and then calls the
``MongoCollection.insertOne()`` method:

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-operation-timeout
:end-before: end-operation-timeout
Expand All @@ -124,24 +124,27 @@ The following table describes how the timeout value is inherited at each level:
- Inheritance Description

* - Operation
- Takes the highest precedence and will override ``timeoutMS``
options set at any other level.
- Takes the highest precedence and overrides the timeout
options that you set at any other level.

* - Transaction
- Takes precedence over ``timeoutMS`` set at the session,
- Takes precedence over the timeout value that you set at the session,
collection, database, or client level.

* - Session
- Applies to all transactions and operations within
that session, unless the option is overridden by options set at those levels.
that session, unless you set a different timeout value at those
levels.

* - Database
- Applies to all sessions and operations within that
database, unless the option is overridden by options set at those levels.
database, unless you set a different timeout value at those
levels.

* - Collection
- Applies to all sessions and operations on that
collection, unless the option is overridden by options set at those levels.
collection, unless you set a different timeout value at those
levels.

* - Client
- Applies to all databases, collections, sessions, transactions, and
Expand All @@ -159,14 +162,15 @@ Overrides
The {+driver-short+} supports various levels of configuration to control the
behavior and performance of database operations.

You can specify a ``timeoutMS`` option at a lower level to override the
client-level configuration. This allows you to customize timeouts based
on the needs of individual operations.
You can specify a ``timeoutMS`` option at a more specific level to override the
client-level configuration. The table in the preceding section describes
the levels at which you can specify a timeout setting. This allows you
to customize timeouts based on the needs of individual operations.

The following example demonstrates how a collection-level timeout
configuration can override a client-level timeout configuration:

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-override
:end-before: end-override
Expand All @@ -182,7 +186,7 @@ When you create a new `ClientSession
<{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/ClientSession.html>`__
instance to implement a transaction, use
the ``defaultTimeout()`` method when building a ``ClientSessionOptions``
instance. You can use this option to specify the timeout to apply for
instance. You can use this option to specify the timeout for
the following methods:

- `commitTransaction() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/ClientSession.html#commitTransaction()>`__
Expand All @@ -193,7 +197,7 @@ the following methods:
The following code demonstrates how to set the ``defaultTimeout`` when
instantiating a ``ClientSession``:

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-session-timeout
:end-before: end-session-timeout
Expand All @@ -202,12 +206,12 @@ instantiating a ``ClientSession``:
If you do not specify the ``defaultTimeout``, the driver uses the timeout
value set on the parent ``MongoClient``.

You can also set a transaction-level timeout by using the ``timeout()``
You can also set a transaction-level timeout by calling the ``timeout()``
method when building a ``TransactionOptions`` instance. Setting this
option applies a timeout to all operations performed in the scope of the
transaction:

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-txn-timeout
:end-before: end-txn-timeout
Expand All @@ -221,17 +225,17 @@ Client Encryption
When you use Client-Side Field Level Encryption (CSFLE), the driver uses the
``timeoutMS`` option to limit the time allowed for encryption and decryption
operations. You can set a timeout option for your ``ClientEncryption``
instance by using the ``timeout()`` method when building a
instance by calling the ``timeout()`` method when building a
``ClientEncryptionSettings`` instance.

If you specify the timeout when you construct a
``ClientEncryption`` instance, it controls the lifetime of all operations
``ClientEncryption`` instance, the timeout controls the lifetime of all operations
performed on that instance. If you do not provide a timeout when
instantiating ``ClientEncryption``, the instance
inherits the timeout setting from the ``MongoClient`` used in the
``ClientEncryption`` constructor.

If you set ``timeoutMS`` on both the client and directly in
If you set ``timeoutMS`` both on the client and directly in
``ClientEncryption``, the value provided to ``ClientEncryption`` takes
precedence.

Expand Down Expand Up @@ -261,10 +265,10 @@ Cursor Lifetime Mode
~~~~~~~~~~~~~~~~~~~~

The cursor lifetime mode uses the timeout setting to limit the entire lifetime of a
cursor. In this mode, the initialization of the cursor and all subsequent calls
to the cursor methods must complete within the limit specified by the
timeout option. All documents must be returned within this limit.
Otherwise, the cursor's lifetime expires and a timeout error occurs.
cursor. In this mode, your application must initialize the cursor, complete
all calls to the cursor methods, and return all documents within the specified
time limit. Otherwise, the cursor's lifetime expires and the driver
raises a timeout error.

When you close a cursor by calling the ``close()`` method, the
timeout resets for the ``killCursors`` command to ensure server-side resources are
Expand All @@ -274,7 +278,7 @@ The following example shows how to set a cursor timeout to ensure that
the cursor is initialized and all documents are retrieved within the
inherited timeout:

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-cursor-lifetime
:end-before: end-cursor-lifetime
Expand All @@ -294,7 +298,7 @@ The following code example iterates over documents in the ``db.people`` collecti
by using a cursor with the ``ITERATION`` timeout mode, and then retrieves
and prints the ``name`` field value for each document:

.. literalinclude:: /includes/connect/CSOT.java
.. literalinclude:: /includes/connect/CsotExample.java
:language: java
:start-after: start-cursor-iteration
:end-before: end-cursor-iteration
Expand Down
8 changes: 4 additions & 4 deletions source/crud/query-documents/cursor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Access Data From a Cursor
Overview
--------

In this guide, you can learn how to access data using a **cursor** in
In this guide, you can learn how to access data by using a **cursor** in
the {+driver-short+}.

A cursor is a mechanism that allows an application to iterate over database
Expand All @@ -38,9 +38,9 @@ to see by setting parameters through methods.

.. tip:: Cursor Timeout

You can set a timeout to limit the amount of time it takes to
retrieve data from a cursor. To learn more, see the
:ref:`java-csot-cursor` section of the Limit Server Execution Time guide.
You can set a timeout on your cursor to return query results.
To learn more, see the :ref:`java-csot-cursor` section of the Limit
Server Execution Time guide.

Terminal Methods
----------------
Expand Down
2 changes: 1 addition & 1 deletion source/crud/transactions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ documentation <api-docs-transaction>` to learn more about these methods.

.. tip:: Transaction Timeout

You can set a timeout to limit the amount of time it takes operations
You can set a limit on amount of time that operations can take
to complete in your transactions. To learn more, see the
:ref:`java-csot-txn` section of the Limit Server Execution Time guide.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.bson.Document;


public class csot {
public class CsotExample {

public static void main(String[] args) {
MongoClient mongoClient = new csot().mongoClientSettings();
Expand Down
Loading
0