|
1 | 1 | namespace Ydb.Sdk.Ado.RetryPolicy; |
2 | 2 |
|
| 3 | +/// <summary> |
| 4 | +/// Configuration settings for the <see cref="YdbRetryPolicy"/>. |
| 5 | +/// </summary> |
| 6 | +/// <remarks> |
| 7 | +/// YdbRetryPolicyConfig provides configuration options for customizing the retry behavior |
| 8 | +/// of YDB operations. The default values are suitable for most use cases, but can be |
| 9 | +/// adjusted based on specific requirements and performance characteristics. |
| 10 | +/// </remarks> |
3 | 11 | public class YdbRetryPolicyConfig |
4 | 12 | { |
| 13 | + /// <summary> |
| 14 | + /// Gets the default retry policy configuration. |
| 15 | + /// </summary> |
| 16 | + /// <remarks> |
| 17 | + /// This configuration provides a good balance between retry frequency and performance |
| 18 | + /// for most YDB operations. It can be used as a starting point for custom configurations. |
| 19 | + /// </remarks> |
5 | 20 | public static readonly YdbRetryPolicyConfig Default = new(); |
6 | 21 |
|
| 22 | + /// <summary> |
| 23 | + /// Gets or sets the maximum number of retry attempts. |
| 24 | + /// </summary> |
| 25 | + /// <remarks> |
| 26 | + /// The total number of attempts will be MaxAttempts (including the initial attempt). |
| 27 | + /// Setting this to 1 disables retries entirely. |
| 28 | + /// <para>Default value: 10.</para> |
| 29 | + /// </remarks> |
7 | 30 | public int MaxAttempts { get; init; } = 10; |
8 | 31 |
|
| 32 | + /// <summary> |
| 33 | + /// Gets or sets the base delay in milliseconds for fast backoff strategies. |
| 34 | + /// </summary> |
| 35 | + /// <remarks> |
| 36 | + /// This is used for errors that typically resolve quickly, such as temporary |
| 37 | + /// unavailability or TLI (Transaction Lock Invalidated). |
| 38 | + /// The actual delay will be calculated using exponential backoff with jitter. |
| 39 | + /// <para>Default value: 5 ms.</para> |
| 40 | + /// </remarks> |
9 | 41 | public int FastBackoffBaseMs { get; init; } = 5; |
10 | 42 |
|
| 43 | + /// <summary> |
| 44 | + /// Gets or sets the base delay in milliseconds for slow backoff strategies. |
| 45 | + /// </summary> |
| 46 | + /// <remarks> |
| 47 | + /// This is used for errors that may take longer to resolve, such as overload |
| 48 | + /// or resource exhaustion. The actual delay will be calculated using |
| 49 | + /// exponential backoff with jitter. |
| 50 | + /// <para>Default value: 50 ms.</para> |
| 51 | + /// </remarks> |
11 | 52 | public int SlowBackoffBaseMs { get; init; } = 50; |
12 | 53 |
|
| 54 | + /// <summary> |
| 55 | + /// Gets or sets the maximum delay in milliseconds for fast backoff strategies. |
| 56 | + /// </summary> |
| 57 | + /// <remarks> |
| 58 | + /// This caps the maximum delay for fast backoff to prevent excessively long waits. |
| 59 | + /// The exponential backoff will not exceed this value. |
| 60 | + /// <para>Default value: 500 ms.</para> |
| 61 | + /// </remarks> |
13 | 62 | public int FastCapBackoffMs { get; init; } = 500; |
14 | 63 |
|
| 64 | + /// <summary> |
| 65 | + /// Gets or sets the maximum delay in milliseconds for slow backoff strategies. |
| 66 | + /// </summary> |
| 67 | + /// <remarks> |
| 68 | + /// This caps the maximum delay for slow backoff to prevent excessively long waits. |
| 69 | + /// The exponential backoff will not exceed this value. |
| 70 | + /// <para>Default value: 5000 ms.</para> |
| 71 | + /// </remarks> |
15 | 72 | public int SlowCapBackoffMs { get; init; } = 5_000; |
16 | 73 |
|
| 74 | + /// <summary> |
| 75 | + /// Gets or sets a value indicating whether to enable retry for idempotent statuses. |
| 76 | + /// </summary> |
| 77 | + /// <remarks> |
| 78 | + /// When false, only transient errors are retried. When true, all retryable statuses |
| 79 | + /// are retried, which means the operation may be executed twice. This happens because |
| 80 | + /// some statuses (like unavailable) don't indicate whether the server processed the |
| 81 | + /// operation - the connection might have been lost during the response. Enable this |
| 82 | + /// only if you are certain that the operations being retried are idempotent. |
| 83 | + /// <para>Default value: false.</para> |
| 84 | + /// </remarks> |
17 | 85 | public bool EnableRetryIdempotence { get; init; } = false; |
18 | 86 |
|
| 87 | + /// <summary> |
| 88 | + /// Returns a string representation of the retry policy configuration. |
| 89 | + /// </summary> |
| 90 | + /// <returns>A string containing all configuration values in a readable format.</returns> |
| 91 | + /// <remarks> |
| 92 | + /// This method is useful for logging and debugging purposes to see the current |
| 93 | + /// retry policy configuration values. |
| 94 | + /// </remarks> |
19 | 95 | public override string ToString() => $"MaxAttempt={MaxAttempts};" + |
20 | 96 | $"FastBackoffBaseMs={FastBackoffBaseMs};" + |
21 | 97 | $"SlowBackoffBaseMs={SlowBackoffBaseMs};" + |
|
0 commit comments