Skip to content

CSHARP-5608: CSOT: Command Execution #1716

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sanych-sun
Copy link
Member

No description provided.

@sanych-sun sanych-sun requested a review from a team as a code owner June 23, 2025 19:07
@sanych-sun sanych-sun requested review from papafe, rstam and adelinowona and removed request for a team and papafe June 23, 2025 19:07
@BorisDog BorisDog requested a review from Copilot June 24, 2025 21:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces explicit handling of server round-trip time ("RTT") by expanding SelectServer to return both a server and its RTT, and thread this RTT through various APIs and wire protocols to support operation timeouts and fail points.

  • Update SelectServer and SelectServerAsync to return (IServer server, TimeSpan roundTripTime).
  • Add serverRoundTripTime parameters to FailPoint.Configure, binding constructors, and CommandWireProtocol.
  • Inject RTT into command message sections for dynamic timeout calculation and update numerous tests to use the new overloads.

Reviewed Changes

Copilot reviewed 103 out of 103 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedTargetedFailPointOperation.cs Destructure (server, roundTripTime) and pass RTT into FailPoint.Configure
src/MongoDB.Driver/Core/WireProtocol/CommandUsingCommandMessageWireProtocol.cs Thread serverRoundTripTime into command creation and timeout logic
src/MongoDB.Driver/OperationContextExtensions.cs Add HasOperationTimeout and root context lookup
src/MongoDB.Driver/Core/WireProtocol/CommandWireProtocol.cs Update IWireProtocol methods to accept OperationContext and RTT
tests/MongoDB.Driver.Tests/Core/Bindings/SingleServerReadWriteBindingTests.cs Introduce RTT parameter in test constructors and add validation
Comments suppressed due to low confidence (3)

src/MongoDB.Driver/Core/WireProtocol/CommandWireProtocol.cs:88

  • [nitpick] The field _serverRoundTripTime is declared without XML doc. Add a brief comment explaining that this RTT is used for dynamic timeout calculations in command messages.
                messageEncoderSettings,

src/MongoDB.Driver/Core/WireProtocol/CommandUsingCommandMessageWireProtocol.cs:381

  • OperationContext does not define a RemainingTimeout property. You should compute the remaining time from the original timeout and elapsed time, or add a helper on OperationContext to expose the remaining timeout.
                var serverTimeout = operationContext.RemainingTimeout - _serverRoundTripTime;

src/MongoDB.Driver/Core/WireProtocol/CommandUsingCommandMessageWireProtocol.cs:630

  • RemainingTimeout is not a member of OperationContext. Consider replacing this check with your new helper (e.g., HasOperationTimeout) or implement a proper RemainingTimeout getter.
            if (operationContext.RemainingTimeout == Timeout.InfiniteTimeSpan)
Copy link
Contributor

@adelinowona adelinowona left a comment

Choose a reason for hiding this comment

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

No major comments from me, just minor issues/questions

EndServerSelection(expirableClusterDescription.ClusterDescription, selector, result.ServerDescription, stopwatch);
return result.Server;
EndServerSelection(expirableClusterDescription.ClusterDescription, selector, description, stopwatch);
return (server, description.AverageRoundTripTime);
Copy link
Member Author

Choose a reason for hiding this comment

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

Accordingly to CSOT spec we should use MinRoundTripTime here, but CSharp driver do not track it yet, we have only AverageRoundTripTime. We decided to go with the AverageRoundTripTime and replace it on the later stages of CSOT implementation. More over there is a chance that RTT will be removed from maxTimeMs calculation at all.
Find more details in the https://jira.mongodb.org/browse/CSHARP-5627

@sanych-sun sanych-sun requested a review from adelinowona June 25, 2025 17:40
Copy link
Contributor

@adelinowona adelinowona left a comment

Choose a reason for hiding this comment

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

LGTM

@sanych-sun sanych-sun requested a review from adelinowona June 25, 2025 23:38
@@ -61,10 +64,45 @@ public TimeSpan RemainingTimeout
}
}

[Obsolete("Do not use this property, unless it's needed to avoid breaking changes in public API")]
public CancellationToken CombinedCancellationToken
Copy link
Member Author

Choose a reason for hiding this comment

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

We have a number of use-cases when we cannot update the interfaces, because they are public (I've run into at least 2 cases like that: IStreamFactory and ISaslStep), so we have to squeeze both: cancellation token itself and timeout into linked cancellation token. Having such CombinedCancellationToken on operation context allow us to reuse instantiated CancellationTokenSources. Also I've marked the property as obsolete, so we easily can find all usages and replace with some interface changes in next major release.

Oleksandr Poliakov added 2 commits June 25, 2025 16:46
@@ -94,7 +115,7 @@ public void WaitTask(Task task)
}

var timeout = RemainingTimeout;
if (timeout != System.Threading.Timeout.InfiniteTimeSpan && timeout < TimeSpan.Zero)
Copy link
Member Author

@sanych-sun sanych-sun Jun 25, 2025

Choose a reason for hiding this comment

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

RemainingTimeout returns TimeSpan.Zero if timed out now, so the check could be simplified.

{
var remainingTimeout = RemainingTimeout;
if (remainingTimeout == System.Threading.Timeout.InfiniteTimeSpan)
Copy link
Member Author

Choose a reason for hiding this comment

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

RemainingTimeout returns TimeSpan.Zero if timed out now, so the check could be simplified.

Oleksandr Poliakov added 2 commits June 25, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants