Skip to content

Commit e19e172

Browse files
Add XML documentation comments to public API (#537)
1 parent 56c2201 commit e19e172

26 files changed

+1908
-35
lines changed

src/Ydb.Sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Added XML documentation for all public APIs in `Ydb.Sdk`.
12
- Feat ADO.NET: Added dispose timeout (10 seconds) to `PoolingSessionSource`.
23
- Feat ADO.NET: Added `EnableImplicitSession` to support implicit sessions.
34

src/Ydb.Sdk/src/Ado/BulkUpsert/BulkUpsertImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Ydb.Sdk.Ado.BulkUpsert;
88

9-
public sealed class BulkUpsertImporter : IBulkUpsertImporter
9+
internal class BulkUpsertImporter : IBulkUpsertImporter
1010
{
1111
private readonly IDriver _driver;
1212
private readonly string _tablePath;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
namespace Ydb.Sdk.Ado.RetryPolicy;
22

3+
/// <summary>
4+
/// Defines the contract for retry policies used by YDB operations.
5+
/// </summary>
6+
/// <remarks>
7+
/// IRetryPolicy provides a way to implement custom retry logic for YDB operations.
8+
/// The recommended implementation is <see cref="YdbRetryPolicy"/>, but custom implementations
9+
/// can be created for specific use cases. When implementing a custom retry policy, ensure
10+
/// you understand the implications of retrying operations and handle idempotency correctly.
11+
/// </remarks>
312
public interface IRetryPolicy
413
{
14+
/// <summary>
15+
/// Calculates the delay before the next retry attempt.
16+
/// </summary>
17+
/// <param name="ydbException">The <see cref="YdbException"/> that was thrown during the last execution attempt.</param>
18+
/// <param name="attempt">The current attempt number (0-based).</param>
19+
/// <returns>
20+
/// The delay before the next retry attempt, or null if no more retries should be attempted.
21+
/// </returns>
22+
/// <remarks>
23+
/// This method is called for each retry attempt. Return null to stop retrying.
24+
/// Consider the <see cref="YdbException"/>, attempt number, and operation idempotency when making retry decisions.
25+
/// </remarks>
526
public TimeSpan? GetNextDelay(YdbException ydbException, int attempt);
627
}

src/Ydb.Sdk/src/Ado/RetryPolicy/YdbRetryPolicy.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
namespace Ydb.Sdk.Ado.RetryPolicy;
44

55
/// <summary>
6-
/// See <a href="https://aws.amazon.com/ru/blogs/architecture/exponential-backoff-and-jitter/">AWS paper</a>
6+
/// Default retry policy implementation for YDB operations using exponential backoff with jitter.
77
/// </summary>
8+
/// <remarks>
9+
/// YdbRetryPolicy implements the recommended retry strategy for YDB operations based on
10+
/// <a href="https://aws.amazon.com/ru/blogs/architecture/exponential-backoff-and-jitter/">AWS best practices</a>.
11+
/// It uses different backoff strategies for different types of errors and includes jitter
12+
/// to prevent thundering herd problems. This is the recommended implementation of <see cref="IRetryPolicy"/>.
13+
/// </remarks>
814
public class YdbRetryPolicy : IRetryPolicy
915
{
16+
/// <summary>
17+
/// Gets the default retry policy instance with default configuration.
18+
/// </summary>
19+
/// <remarks>
20+
/// This instance uses the default configuration from <see cref="YdbRetryPolicyConfig.Default"/>.
21+
/// It's suitable for most use cases and provides a good balance between retry frequency and performance.
22+
/// </remarks>
1023
public static readonly YdbRetryPolicy Default = new(YdbRetryPolicyConfig.Default);
1124

1225
private readonly int _maxAttempt;
@@ -19,6 +32,14 @@ public class YdbRetryPolicy : IRetryPolicy
1932
private readonly bool _enableRetryIdempotence;
2033
private readonly IRandom _random;
2134

35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="YdbRetryPolicy"/> class with the specified configuration.
37+
/// </summary>
38+
/// <param name="config">The <see cref="YdbRetryPolicyConfig"/> retry policy configuration.</param>
39+
/// <remarks>
40+
/// This constructor creates a retry policy with the specified configuration.
41+
/// The policy will use different backoff strategies based on the error type and attempt number.
42+
/// </remarks>
2243
public YdbRetryPolicy(YdbRetryPolicyConfig config)
2344
{
2445
_maxAttempt = config.MaxAttempts;
@@ -32,11 +53,31 @@ public YdbRetryPolicy(YdbRetryPolicyConfig config)
3253
_random = ThreadLocalRandom.Instance;
3354
}
3455

56+
/// <summary>
57+
/// Initializes a new instance of the <see cref="YdbRetryPolicy"/> class with the specified configuration and random number generator.
58+
/// </summary>
59+
/// <param name="config">The <see cref="YdbRetryPolicyConfig"/> retry policy configuration.</param>
60+
/// <param name="random">The random number generator for jitter calculations.</param>
61+
/// <remarks>
62+
/// This constructor is used for testing purposes to provide deterministic behavior.
63+
/// In production code, use the constructor that takes only the configuration parameter.
64+
/// </remarks>
3565
internal YdbRetryPolicy(YdbRetryPolicyConfig config, IRandom random) : this(config)
3666
{
3767
_random = random;
3868
}
3969

70+
/// <inheritdoc/>
71+
/// <remarks>
72+
/// <para>This method implements different retry strategies based on the YDB status code:</para>
73+
/// <para>- BadSession/SessionBusy: Immediate retry (TimeSpan.Zero)</para>
74+
/// <para>- Aborted/Undetermined: Fast backoff with full jitter</para>
75+
/// <para>- Unavailable/Transport errors: Fast backoff with equal jitter</para>
76+
/// <para>- Overloaded/Resource exhausted: Slow backoff with equal jitter</para>
77+
/// <para>- Other errors: No retry (null)</para>
78+
///
79+
/// <para>The policy respects the maximum attempt limit and idempotence settings.</para>
80+
/// </remarks>
4081
public TimeSpan? GetNextDelay(YdbException ydbException, int attempt)
4182
{
4283
if (attempt >= _maxAttempt - 1 || (!_enableRetryIdempotence && !ydbException.IsTransient))

src/Ydb.Sdk/src/Ado/RetryPolicy/YdbRetryPolicyConfig.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,97 @@
11
namespace Ydb.Sdk.Ado.RetryPolicy;
22

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>
311
public class YdbRetryPolicyConfig
412
{
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>
520
public static readonly YdbRetryPolicyConfig Default = new();
621

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>
730
public int MaxAttempts { get; init; } = 10;
831

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>
941
public int FastBackoffBaseMs { get; init; } = 5;
1042

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>
1152
public int SlowBackoffBaseMs { get; init; } = 50;
1253

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>
1362
public int FastCapBackoffMs { get; init; } = 500;
1463

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>
1572
public int SlowCapBackoffMs { get; init; } = 5_000;
1673

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>
1785
public bool EnableRetryIdempotence { get; init; } = false;
1886

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>
1995
public override string ToString() => $"MaxAttempt={MaxAttempts};" +
2096
$"FastBackoffBaseMs={FastBackoffBaseMs};" +
2197
$"SlowBackoffBaseMs={SlowBackoffBaseMs};" +

src/Ydb.Sdk/src/Ado/RetryPolicy/YdbRetryPolicyExecutor.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ public YdbRetryPolicyExecutor(IRetryPolicy retryPolicy)
1010
}
1111

1212
/// <summary>
13-
/// Executes the specified asynchronous operation and returns the result.
13+
/// Executes the specified asynchronous operation and returns the result.
1414
/// </summary>
1515
/// <param name="operation">
16-
/// A function that returns a started task of type <typeparamref name="TResult" />.
16+
/// A function that returns a started task of type <typeparamref name="TResult" />.
1717
/// </param>
1818
/// <param name="cancellationToken">
19-
/// A cancellation token used to cancel the retry operation, but not operations that are already in flight
20-
/// or that already completed successfully.
19+
/// A cancellation token used to cancel the retry operation, but not operations that are already in flight
20+
/// or that already completed successfully.
2121
/// </param>
2222
/// <typeparam name="TResult"> The result type of the <see cref="Task{TResult}" /> returned by <paramref name="operation" />. </typeparam>
2323
/// <returns>
24-
/// A task that will run to completion if the original task completes successfully (either the
25-
/// first time or after retrying transient failures). If the task fails with a non-transient error or
26-
/// the retry limit is reached, the returned task will become faulted and the exception must be observed.
24+
/// A task that will run to completion if the original task completes successfully (either the
25+
/// first time or after retrying transient failures). If the task fails with a non-transient error or
26+
/// the retry limit is reached, the returned task will become faulted and the exception must be observed.
2727
/// </returns>
2828
public Task<TResult> ExecuteAsync<TResult>(
2929
Func<CancellationToken, Task<TResult>> operation,

src/Ydb.Sdk/src/Ado/Schema/YdbTableStats.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Ydb.Sdk.Ado.Schema;
22

3-
public class YdbTableStats
3+
internal class YdbTableStats
44
{
55
public YdbTableStats(Table.TableStats tableStats)
66
{

src/Ydb.Sdk/src/Ado/Transaction/TransactionMode.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,74 @@
22

33
namespace Ydb.Sdk.Ado;
44

5+
/// <summary>
6+
/// Specifies the transaction isolation mode for YDB operations.
7+
/// </summary>
8+
/// <remarks>
9+
/// TransactionMode defines the isolation level and consistency guarantees
10+
/// for database operations within a transaction.
11+
///
12+
/// <para>
13+
/// For more information about YDB transaction modes, see:
14+
/// <see href="https://ydb.tech/docs/en/concepts/transactions">YDB Transactions Documentation</see>.
15+
/// </para>
16+
/// </remarks>
517
public enum TransactionMode
618
{
19+
/// <summary>
20+
/// Serializable read-write transaction mode.
21+
/// </summary>
22+
/// <remarks>
23+
/// Provides the strictest isolation level for custom transactions.
24+
/// Guarantees that the result of successful parallel transactions is equivalent
25+
/// to their serial execution, with no read anomalies for successful transactions.
26+
/// This is the default mode for read-write operations.
27+
/// </remarks>
728
SerializableRw,
29+
30+
/// <summary>
31+
/// Snapshot read-only transaction mode.
32+
/// </summary>
33+
/// <remarks>
34+
/// All read operations within the transaction access the database snapshot.
35+
/// All data reads are consistent. The snapshot is taken when the transaction begins,
36+
/// meaning the transaction sees all changes committed before it began.
37+
/// Only read operations are allowed.
38+
/// </remarks>
839
SnapshotRo,
40+
41+
/// <summary>
42+
/// Stale read-only transaction mode.
43+
/// </summary>
44+
/// <remarks>
45+
/// Read operations within the transaction may return results that are slightly
46+
/// out-of-date (lagging by fractions of a second). Each individual read returns
47+
/// consistent data, but no consistency between different reads is guaranteed.
48+
/// Only read operations are allowed.
49+
/// </remarks>
950
StaleRo,
1051

52+
/// <summary>
53+
/// Online read-only transaction mode.
54+
/// </summary>
55+
/// <remarks>
56+
/// Each read operation in the transaction reads the data that is most recent
57+
/// at execution time. Each individual read operation returns consistent data,
58+
/// but no consistency is guaranteed between reads. Reading the same table range
59+
/// twice may return different results.
60+
/// Only read operations are allowed.
61+
/// </remarks>
1162
OnlineRo,
63+
64+
/// <summary>
65+
/// Online inconsistent read-only transaction mode.
66+
/// </summary>
67+
/// <remarks>
68+
/// Each read operation in the transaction reads the data that is most recent
69+
/// at execution time. Even the data fetched by a particular read operation may
70+
/// contain inconsistent results. This mode provides the highest performance
71+
/// but the lowest consistency guarantees.
72+
/// Only read operations are allowed.
73+
/// </remarks>
1274
OnlineInconsistentRo
1375
}

src/Ydb.Sdk/src/Ado/YdbCommand.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
namespace Ydb.Sdk.Ado;
88

9+
/// <summary>
10+
/// Represents a SQL command to execute against a YDB database. This class cannot be inherited.
11+
/// </summary>
12+
/// <remarks>
13+
/// YdbCommand provides a standard ADO.NET command interface for executing SQL statements
14+
/// against YDB databases. It supports both synchronous and asynchronous execution methods.
15+
/// </remarks>
916
public sealed class YdbCommand : DbCommand
1017
{
1118
private YdbConnection? _ydbConnection;
@@ -14,15 +21,34 @@ public sealed class YdbCommand : DbCommand
1421
private YdbConnection YdbConnection =>
1522
_ydbConnection ?? throw new InvalidOperationException("Connection property has not been initialized");
1623

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="YdbCommand"/> class.
26+
/// </summary>
1727
public YdbCommand()
1828
{
1929
}
2030

31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="YdbCommand"/> class with the specified connection.
33+
/// </summary>
34+
/// <param name="ydbConnection">A <see cref="YdbConnection"/> that represents the connection to a YDB server.</param>
2135
public YdbCommand(YdbConnection ydbConnection)
2236
{
2337
_ydbConnection = ydbConnection;
2438
}
2539

40+
/// <summary>
41+
/// Initializes a new instance of the <see cref="YdbCommand"/> class with the text of the query, a
42+
/// <see cref="YdbConnection"/>, and the <see cref="YdbTransaction"/>.
43+
/// </summary>
44+
/// <param name="commandText">The text of the query.</param>
45+
/// <param name="ydbConnection">A <see cref="YdbConnection"/> that represents the connection to a YDB server.</param>
46+
public YdbCommand(string commandText, YdbConnection? ydbConnection = null)
47+
{
48+
_commandText = commandText;
49+
_ydbConnection = ydbConnection;
50+
}
51+
2652
public override void Cancel()
2753
{
2854
}

0 commit comments

Comments
 (0)