-
Notifications
You must be signed in to change notification settings - Fork 527
Expand file tree
/
Copy pathSessionRetryOptions.cs
More file actions
66 lines (56 loc) · 3.16 KB
/
SessionRetryOptions.cs
File metadata and controls
66 lines (56 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
namespace Microsoft.Azure.Cosmos
{
using System;
using Microsoft.Azure.Documents;
/// <summary>
/// Implementation of ISessionRetryOptions interface, do not want clients to subclass.
/// </summary>
public sealed class SessionRetryOptions : ISessionRetryOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="SessionRetryOptions"/> class.
/// </summary>
public SessionRetryOptions()
{
this.MinInRegionRetryTime = ConfigurationManager.GetMinRetryTimeInLocalRegionWhenRemoteRegionPreferred();
this.MaxInRegionRetryCount = ConfigurationManager.GetMaxRetriesInLocalRegionWhenRemoteRegionPreferred();
}
/// <summary>
/// Sets the minimum retry time for 404/1002 retries within each region for read and write operations.
/// The minimum value is 100ms - this minimum is enforced to provide a way for the local region to catch-up on replication lag. The default value is 500ms - as a recommendation ensure that this value is higher than the steady-state
/// replication latency between the regions you chose
/// </summary>
public TimeSpan MinInRegionRetryTime { get; private set; }
/// <summary>
/// Sets the maximum number of retries within each region for read and write operations. The minimum value is 1 - the backoff time for the last in-region retry will ensure that the total retry time within the
/// region is at least the min. in-region retry time.
/// </summary>
public int MaxInRegionRetryCount { get; private set; }
/// <summary>
/// hints which guide SDK-internal retry policies on how early to switch retries to a different region. If true, will retry all replicas once and add a minimum delay before switching to the next region.If false, it will
/// 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}");
}
}
}
}
}