Skip to content
Draft
16 changes: 6 additions & 10 deletions Microsoft.Azure.Cosmos/src/CosmosClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public class CosmosClientOptions
private IWebProxy webProxy;
private Func<HttpClient> httpClientFactory;
private string applicationName;
private SessionRetryOptions sessionRetryOptions;

/// <summary>
/// Creates a new CosmosClientOptions
Expand All @@ -88,7 +87,7 @@ public CosmosClientOptions()
this.ApiType = CosmosClientOptions.DefaultApiType;
this.CustomHandlers = new Collection<RequestHandler>();
this.CosmosClientTelemetryOptions = new CosmosClientTelemetryOptions();
this.sessionRetryOptions = new SessionRetryOptions();
this.SessionRetryOptions = new SessionRetryOptions();
}

/// <summary>
Expand All @@ -115,7 +114,8 @@ public string ApplicationName
this.applicationName = value;
}
}


internal SessionRetryOptions SessionRetryOptions { get; private set; }
/// <summary>
/// Get or set session container for the client
/// </summary>
Expand Down Expand Up @@ -732,14 +732,10 @@ public Func<HttpClient> HttpClientFactory
/// <summary>
/// provides SessionTokenMismatchRetryPolicy optimization through customer supplied region switch hints
/// </summary>
internal SessionRetryOptions SessionRetryOptions
internal bool EnableRemoteRegionPreferredForSessionRetry
Copy link
Member

Choose a reason for hiding this comment

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

This should be conditionally public or internal - it is teh public surface area that custoemrs would use

Like
#if PREVIEW public #else internal #endif

See this PR for an example - #5077

{
get => this.sessionRetryOptions;
set
{
value.Validate();
this.sessionRetryOptions = value;
}
get => this.SessionRetryOptions.RemoteRegionPreferred;
set => this.SessionRetryOptions.RemoteRegionPreferred = value;
}
/// <summary>
/// Enable partition key level failover
Expand Down
8 changes: 4 additions & 4 deletions Microsoft.Azure.Cosmos/src/Fluent/CosmosClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,12 @@ public CosmosClientBuilder WithSerializerOptions(CosmosSerializationOptions cosm

/// <summary>
/// provides SessionTokenMismatchRetryPolicy optimization through customer supplied region switch hints
/// </summary>
/// <param name="sessionRetryOptions">customer supplied region switch hints </param>
/// </summary>
/// <param name="enableRemoteRegionPreferredForSessionRetry"></param>
/// <returns>The <see cref="CosmosClientBuilder"/> object</returns>
public CosmosClientBuilder WithSessionRetryOptions(SessionRetryOptions sessionRetryOptions)
public CosmosClientBuilder WithEnableRemoteRegionPreferredForSessionRetry(bool enableRemoteRegionPreferredForSessionRetry)
Copy link
Member

Choose a reason for hiding this comment

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

Same public for preview / internal for GA package - see #5077

{
this.clientOptions.SessionRetryOptions = sessionRetryOptions;
this.clientOptions.EnableRemoteRegionPreferredForSessionRetry = enableRemoteRegionPreferredForSessionRetry;
return this;
}

Expand Down
30 changes: 2 additions & 28 deletions Microsoft.Azure.Cosmos/src/SessionRetryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// <summary>
/// Implementation of ISessionRetryOptions interface, do not want clients to subclass.
/// </summary>
public sealed class SessionRetryOptions : ISessionRetryOptions
internal sealed class SessionRetryOptions : ISessionRetryOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="SessionRetryOptions"/> class.
Expand Down Expand Up @@ -35,32 +35,6 @@ public SessionRetryOptions()
/// retry in the local region up to 5s
/// </summary>
public bool RemoteRegionPreferred { get; set; } = false;

/// <summary>
/// validates the client options.
/// </summary>
internal void Validate()
{
if (this.RemoteRegionPreferred)
{
if (this.MinInRegionRetryTime == null)
{
throw new ArgumentException($"Argument 'MinInRegionRetryTime' must not be null when RemoteRegionPreferred option is selected.");
}

if (this.MinInRegionRetryTime.TotalMilliseconds < ConfigurationManager.MinMinInRegionRetryTimeForWritesInMs)
{
throw new ArgumentException($"Argument 'MinInRegionRetryTime' in the SessionRetryOptions must be set and have at least a value of {ConfigurationManager.MinMinInRegionRetryTimeForWritesInMs} ms");
}

if (this.MaxInRegionRetryCount < ConfigurationManager.MinMaxRetriesInLocalRegionWhenRemoteRegionPreferred)
{
throw new ArgumentException($"Argument 'MaxInRegionRetryCount' in the SessionRetryOptions must have at least a value of {ConfigurationManager.MinMaxRetriesInLocalRegionWhenRemoteRegionPreferred}");
}
}
}




}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ public async Task ReadOperationWithReadSessionUnavailableTest(FaultInjectionOper
Assert.IsNotNull(faultInjector);
CosmosClientOptions clientOptions = new CosmosClientOptions()
{
SessionRetryOptions = new SessionRetryOptions()
{
RemoteRegionPreferred = remoteRegionPreferred,
},

EnableRemoteRegionPreferredForSessionRetry = remoteRegionPreferred,
ConsistencyLevel = ConsistencyLevel.Session,
ApplicationPreferredRegions = preferredRegions,
ConnectionMode = ConnectionMode.Direct,
Expand Down Expand Up @@ -162,10 +158,7 @@ public async Task WriteOperationWithReadSessionUnavailableTest(FaultInjectionOpe

CosmosClientOptions clientOptions = new CosmosClientOptions()
{
SessionRetryOptions = new SessionRetryOptions()
{
RemoteRegionPreferred = remoteRegionPreferred,
},
EnableRemoteRegionPreferredForSessionRetry = remoteRegionPreferred,
ConsistencyLevel = ConsistencyLevel.Session,
ApplicationPreferredRegions = preferredRegions,
ConnectionMode = ConnectionMode.Direct,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public void SessionRetryOptionsValidValuesTest()
{
CosmosClientOptions clientOptions = new CosmosClientOptions()
{
SessionRetryOptions = new SessionRetryOptions()
{
RemoteRegionPreferred = true
},
EnableRemoteRegionPreferredForSessionRetry = true,
};

Assert.IsTrue(clientOptions.SessionRetryOptions.MinInRegionRetryTime == TimeSpan.FromMilliseconds(200));
Expand All @@ -44,10 +41,7 @@ public void SessionRetryOptionsDefaultValuesTest()
{
CosmosClientOptions clientOptions = new CosmosClientOptions()
{
SessionRetryOptions = new SessionRetryOptions()
{
RemoteRegionPreferred = true,
},
EnableRemoteRegionPreferredForSessionRetry = true,
};

Assert.IsTrue(clientOptions.SessionRetryOptions.MinInRegionRetryTime == TimeSpan.FromMilliseconds(500));
Expand All @@ -64,10 +58,7 @@ public void SessionRetryOptionsInValidValuesTest()
{
CosmosClientOptions clientOptions = new CosmosClientOptions()
{
SessionRetryOptions = new SessionRetryOptions()
{
RemoteRegionPreferred = true
},
EnableRemoteRegionPreferredForSessionRetry = true,
};

Assert.IsTrue(clientOptions.SessionRetryOptions.MinInRegionRetryTime == TimeSpan.FromMilliseconds(100));
Expand Down