Skip to content

Commit acbbb6d

Browse files
start doc
1 parent 56c2201 commit acbbb6d

19 files changed

+1036
-10
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+
- 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 primarily 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+
/// This method implements different retry strategies based on the error type:
73+
/// - BadSession/SessionBusy: Immediate retry (TimeSpan.Zero)
74+
/// - Aborted/Undetermined: Fast backoff with full jitter
75+
/// - Unavailable/Transport errors: Fast backoff with equal jitter
76+
/// - Overloaded/Resource exhausted: Slow backoff with equal jitter
77+
/// - Other errors: No retry (null)
78+
///
79+
/// The policy respects the maximum attempt limit and idempotence settings.
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+
/// Default value: 10.
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+
/// Default value: 5 ms.
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+
/// Default value: 50 ms.
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+
/// Default value: 500 ms.
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+
/// Default value: 5000 ms.
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+
/// Default value: false.
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/Transaction/TransactionMode.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,62 @@
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+
/// </remarks>
512
public enum TransactionMode
613
{
14+
/// <summary>
15+
/// Serializable read-write transaction mode.
16+
/// </summary>
17+
/// <remarks>
18+
/// Provides the highest isolation level with full ACID guarantees.
19+
/// All reads and writes are serializable, ensuring complete consistency.
20+
/// This is the default mode for read-write operations.
21+
/// </remarks>
722
SerializableRw,
23+
24+
/// <summary>
25+
/// Snapshot read-only transaction mode.
26+
/// </summary>
27+
/// <remarks>
28+
/// Provides a consistent snapshot of the database at a specific point in time.
29+
/// All reads within the transaction see the same consistent state.
30+
/// Only read operations are allowed.
31+
/// </remarks>
832
SnapshotRo,
33+
34+
/// <summary>
35+
/// Stale read-only transaction mode.
36+
/// </summary>
37+
/// <remarks>
38+
/// Allows reading potentially stale data for better performance.
39+
/// Provides eventual consistency guarantees but may return outdated information.
40+
/// Only read operations are allowed.
41+
/// </remarks>
942
StaleRo,
1043

44+
/// <summary>
45+
/// Online read-only transaction mode.
46+
/// </summary>
47+
/// <remarks>
48+
/// Provides real-time read access with strong consistency.
49+
/// Reads the most recent committed data without allowing inconsistent reads.
50+
/// Only read operations are allowed.
51+
/// </remarks>
1152
OnlineRo,
53+
54+
/// <summary>
55+
/// Online inconsistent read-only transaction mode.
56+
/// </summary>
57+
/// <remarks>
58+
/// Provides real-time read access but allows inconsistent reads for better performance.
59+
/// May return data from different points in time within the same transaction.
60+
/// Only read operations are allowed.
61+
/// </remarks>
1262
OnlineInconsistentRo
1363
}

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
}

src/Ydb.Sdk/src/Ado/YdbConnection.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
namespace Ydb.Sdk.Ado;
1010

11+
/// <summary>
12+
/// Represents a connection to a YDB database.
13+
/// </summary>
14+
/// <remarks>
15+
/// YdbConnection provides a standard ADO.NET connection interface for YDB databases.
16+
/// It manages database sessions and provides access to YDB-specific functionality.
17+
/// </remarks>
1118
public sealed class YdbConnection : DbConnection
1219
{
1320
private static readonly StateChangeEventArgs ClosedToOpenEventArgs =
@@ -39,10 +46,17 @@ internal ISession Session
3946

4047
private ISession _session = null!;
4148

49+
/// <summary>
50+
/// Initializes a new instance of the YdbConnection class.
51+
/// </summary>
4252
public YdbConnection()
4353
{
4454
}
4555

56+
/// <summary>
57+
/// Initializes a new instance of the YdbConnection class with the specified connection string.
58+
/// </summary>
59+
/// <param name="connectionString">The connection string used to establish the connection.</param>
4660
public YdbConnection(string connectionString)
4761
{
4862
ConnectionStringBuilder = new YdbConnectionStringBuilder(connectionString);

0 commit comments

Comments
 (0)