Skip to content
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

CSOT #1215

Merged
merged 178 commits into from
Jul 23, 2024
Merged

CSOT #1215

merged 178 commits into from
Jul 23, 2024

Conversation

katcharov
Copy link
Contributor

@katcharov katcharov commented Oct 4, 2023

Description

This PR introduces a unified Client Side Operation Timeout (CSOT) as an Alpha feature to
simplify the multitude of existing timeout settings. This consolidation merges various complex and interacting timeout settings into a single, overarching operation timeout option, enhancing usability and predictability. Existing timeout options will continue to be honored if the operation timeout is not set.

Key Changes:

  • Implement CSOT across various layers of the driver, applying the new operation
    timeout configuration to govern execution time in areas such as Authentication,
    Connection Pool and Monitoring, Server Discovery and Monitoring, CRUD, GridFS,
    CSFLE, Transactions, Handshake, and Server Selection.

  • Annotate the CSOT API as Alpha, indicating that this public API element is in
    the early stages of development and may undergo incompatible changes.

  • Centralize the setting of maxTimeMS just before sending commands to the server.
    This optimization enhances performance and ensures more precise enforcement of timeouts.

  • Introduce TimeoutContext to centralize timeout-related logic, enhancing the
    clarity and ease of maintenance for timeout management within the driver.

  • Enable a new retry mode when CSOT is active, allowing operations to retry until the timeout is reached. This improves resiliency compared to the previous behavior of retrying only once.

  • Enhance MongoClient, MongoDatabase, MongoCollection, and ClientSession to support
    setting and inheriting the operation timeout.

  • Introduce MongoCluster, a new conceptual entity representing server deployments,
    configurable with specific writeConcern, timeouts, and read preferences.

  • Transform timeout errors from external sources into the new MongoOperationTimeoutException,
    standardizing error handling when CSOT is enabled.

Note: serverSelectionTimeoutMS and connectTimeoutMS are still honored even if CSOT is enabled.

Reviewers:

@rozza: Since you have made many of the changes in this branch, I have added you as a reviewer. I have addressed and answered some comments on this PR but would appreciate if you could double-check and comment if you have any objections. A full review of the PR is not expected.

@stIncMale: Could you please check if your previous comments have been addressed and resolve them as needed? A full review of the PR is not expected.

For reviewers:

  • Test Verification: Ensure all tests are passing and all important build variants are tested.
  • Verify that the ClientSideOperation* test suites does not have any ignored tests without a valid reason.

Context:

This PR focuses on the alpha changes of CSOT and includes changes from the EPIC: JAVA-3828.

Description is updated by @vbabanin.

rozza and others added 28 commits August 22, 2023 14:43
Initial client side operation timeout (CSOT) work.
The CSOT class is passed to all operations and currently encapsulate the following timeouts:

  - `timeoutMS` the new optional client side operation timeout
  - `maxTimeMS` the legacy maxTimeMS operation value. Ignored if CSOT is set.
  - `maxCommitTimeMS` the legacy commit timeout. Ignored if CSOT is set.
  - `maxAwaitTimeMS` the getMore await timeout.

This initial work allows for the CSOT to be available to all operations and later
work will pass / apply this timeout where required by the Spec.

JAVA-4086
# Conflicts:
#	driver-core/src/main/com/mongodb/ConnectionString.java
#	driver-core/src/test/unit/com/mongodb/MongoClientSettingsSpecification.groovy
An immutable class that contains all user configured timeouts.
This will eventaually allow access to user configuration down the
stack into Bindings / Cluster.selectServer and Connection.command.

JAVA-5169
In preparation for adding all contexts to OperationContext

JAVA-5170
This will allow the timeout settings to be available to the Binding
and this will allow the binding to create the TimeoutContext for the
operation.

JAVA-5170
Now contains RequestContext, SessionContext and TimeoutContext

JAVA-5170
Operations now supply TimeoutSettings

JAVA-5170
Pass OperationContext as a whole instead of RequestContext,
SessionContext, TimeoutContext and ServerAPI

JAVA-5170
Adds support for Explainable operations

JAVA-5172
# Conflicts:
#	driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java
#	driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java
#	driver-core/src/test/functional/com/mongodb/ClusterFixture.java
#	driver-core/src/test/unit/com/mongodb/internal/connection/BaseClusterSpecification.groovy
#	driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/ClientSessionBinding.java
#	driver-reactive-streams/src/test/unit/com/mongodb/reactivestreams/client/internal/ClientSessionBindingSpecification.groovy
#	driver-sync/src/test/unit/com/mongodb/client/internal/ClientSessionBindingSpecification.groovy
if (this == o) {
return true;
static Timeout expiresIn(final long duration, final TimeUnit unit) {
// TODO (CSOT) confirm that all usages in final PR are non-negative
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to address all TODOs prior to merging. (All files in github can be loaded using document.querySelectorAll('.load-diff-button').forEach(node => node.click()) in console, and then ctrl-f for TODO)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have addressed critical //TODO comments.

@vbabanin vbabanin self-assigned this Jul 12, 2024
# Conflicts:
#	driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/unified/UnifiedServerDiscoveryAndMonitoringTest.java
#	driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedTest.java
@vbabanin vbabanin marked this pull request as ready for review July 17, 2024 23:50
Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only concern I left here was addressed.

@rozza
Copy link
Member

rozza commented Jul 18, 2024

Kicked off a full build just to check.

https://spruce.mongodb.com/version/6698dcbb688ab00007faac91/

Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets replace all the @since CSOT doc annotations before merging into master.

@vbabanin
Copy link
Member

vbabanin commented Jul 19, 2024

The MongoCluster concept has been introduced in CSOT and is not marked with the @Alpha annotation, except for timeout-related methods like getTimeout and withTimeout. Although it originated in CSOT, it is applicable beyond this context, so the class MongoCluster has not been marked with @Alpha. If there are any objections, please share your feedback.

@vbabanin vbabanin requested a review from rozza July 22, 2024 05:28
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vbabanin vbabanin merged commit 01aff5a into master Jul 23, 2024
259 checks passed
Copy link
Member

@vbabanin vbabanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants