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
CSHARP-3757: Redirect read/write retries to other mongos if possible #1304
base: master
Are you sure you want to change the base?
Conversation
|
||
var deprioritizedServers = new List<ServerDescription> { connected1 }; | ||
|
||
for (int i = 0; i < 15; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running multiple times to account for server selection randomness and guarantee we get the expected result for each run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, few minor comments.
src/MongoDB.Driver.Core/Core/Operations/RetryableReadOperationExecutor.cs
Outdated
Show resolved
Hide resolved
/// <returns>The selected server.</returns> | ||
IServer SelectServer(IServerSelector selector, CancellationToken cancellationToken); | ||
IServer SelectServer(IServerSelector selector, CancellationToken cancellationToken, IReadOnlyCollection<ServerDescription> deprioritizedServers = null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider having augmenting IServerSelector
to account for deprioritizedServers
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments.
var selector = deprioritizedServers != null | ||
? (IServerSelector)new CompositeServerSelector(new IServerSelector[] { new PriorityServerSelector(deprioritizedServers), writableServerSelector }) | ||
: writableServerSelector; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selector = deprioritizedServers != null
? new CompositeServerSelector(new[] { new PriorityServerSelector(deprioritizedServers), selector })
: selector;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new IServerSelector[]
-> new[]
src/MongoDB.Driver.Core/Core/Clusters/ServerSelectors/PriorityServerSelector.cs
Outdated
Show resolved
Hide resolved
src/MongoDB.Driver.Core/Core/Clusters/ServerSelectors/PriorityServerSelector.cs
Outdated
Show resolved
Hide resolved
src/MongoDB.Driver.Core/Core/Clusters/ServerSelectors/PriorityServerSelector.cs
Outdated
Show resolved
Hide resolved
src/MongoDB.Driver.Core/Core/Clusters/ServerSelectors/PriorityServerSelector.cs
Outdated
Show resolved
Hide resolved
src/MongoDB.Driver.Core/Core/Operations/RetryableReadOperationExecutor.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsProseTests.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.Driver.Core.Tests/Core/Bindings/WritableServerBindingTests.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.Driver.Tests/Specifications/retryable-reads/RetryableReadsProseTests.cs
Outdated
Show resolved
Hide resolved
.../MongoDB.Driver.Tests/Specifications/retryable-writes/prose-tests/RetryWriteOnOtherMongos.cs
Outdated
Show resolved
Hide resolved
|
||
[Theory] | ||
[ParameterAttributeData] | ||
public async void SelectServer_should_return_deprioritized_servers_if_no_other_servers_exist_or_cluster_not_sharded( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to mention that async method should return Task
, for better clarity.
@@ -53,7 +53,7 @@ public static TResult Execute<TResult>(IRetryableWriteOperation<TResult> operati | |||
|
|||
try | |||
{ | |||
context.ReplaceChannelSource(context.Binding.GetWriteChannelSource(cancellationToken)); | |||
context.ReplaceChannelSource(context.Binding.GetWriteChannelSource(new [] { context.ChannelSource.ServerDescription }, cancellationToken)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the extra space in new []
--> new[]
/// <summary> | ||
/// Represents a server selector that selects servers based on a collection of servers to deprioritize. | ||
/// </summary> | ||
public sealed class PriorityServerSelector : IServerSelector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should have few very basic tests for this selector. like EndPointServerSelectorTests
var selector = deprioritizedServers != null | ||
? (IServerSelector)new CompositeServerSelector(new IServerSelector[] { new PriorityServerSelector(deprioritizedServers), writableServerSelector }) | ||
: writableServerSelector; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new IServerSelector[]
-> new[]
return CreateServerChannelSource(server); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<IChannelSourceHandle> GetWriteChannelSourceAsync(IMayUseSecondaryCriteria mayUseSecondary, CancellationToken cancellationToken) | ||
{ | ||
return await GetWriteChannelSourceAsync(null, mayUseSecondary, cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to await, can just return the task.
Additional await might create addition wrapping task object.
var writableServerSelector = new WritableServerSelector(mayUseSecondary); | ||
|
||
var selector = deprioritizedServers != null | ||
? (IServerSelector)new CompositeServerSelector(new IServerSelector[] { new PriorityServerSelector(deprioritizedServers), writableServerSelector }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment applies here
/// <param name="deprioritizedServers">The collection of servers to deprioritize.</param> | ||
public PriorityServerSelector(IReadOnlyCollection<ServerDescription> deprioritizedServers) | ||
{ | ||
_deprioritizedServers = Ensure.IsNotNull(deprioritizedServers, nameof(deprioritizedServers)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be IsNotNullOrEmpty
maybe?
Description
On a sharded cluster, retrying reads and writes will attempt to prioritize other mongos for selection if available.
What is changing?