From c9e4aa67165942e8e9c216a173a310942fe40e43 Mon Sep 17 00:00:00 2001 From: Kirill Kurdyukov Date: Wed, 7 Aug 2024 15:27:31 +0300 Subject: [PATCH] dev: preparing for release (#158) --- src/Ydb.Sdk/src/Ado/YdbConnection.cs | 2 +- src/Ydb.Sdk/src/Driver.cs | 19 ++++++------------- src/Ydb.Sdk/src/GrpcRequestSettings.cs | 8 ++------ src/Ydb.Sdk/src/Services/Query/SessionPool.cs | 13 +++---------- src/Ydb.Sdk/src/Services/Table/Session.cs | 7 +------ 5 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/Ydb.Sdk/src/Ado/YdbConnection.cs b/src/Ydb.Sdk/src/Ado/YdbConnection.cs index a892d1a3..d7f0cb2f 100644 --- a/src/Ydb.Sdk/src/Ado/YdbConnection.cs +++ b/src/Ydb.Sdk/src/Ado/YdbConnection.cs @@ -92,7 +92,7 @@ public override async Task OpenAsync(CancellationToken cancellationToken) { Driver.TransportException transportException => new YdbException(transportException.Status), StatusUnsuccessfulException unsuccessfulException => new YdbException(unsuccessfulException.Status), - _ => throw new YdbException("Cannot get session", e) + _ => new YdbException("Cannot get session", e) }; } diff --git a/src/Ydb.Sdk/src/Driver.cs b/src/Ydb.Sdk/src/Driver.cs index db511d11..d4099e0d 100644 --- a/src/Ydb.Sdk/src/Driver.cs +++ b/src/Ydb.Sdk/src/Driver.cs @@ -145,6 +145,7 @@ internal async Task UnaryCall( catch (RpcException e) { PessimizeEndpoint(endpoint); + throw new TransportException(e); } } @@ -167,15 +168,10 @@ internal StreamIterator StreamCall( options: GetCallOptions(settings, true), request: request); - return new StreamIterator(call, e => - { - settings.RpcErrorHandler(e); - PessimizeEndpoint(endpoint); - }); + return new StreamIterator(call, () => { PessimizeEndpoint(endpoint); }); } catch (RpcException e) { - settings.RpcErrorHandler(e); PessimizeEndpoint(endpoint); throw new TransportException(e); @@ -326,9 +322,9 @@ private CallOptions GetCallOptions(GrpcRequestSettings settings, bool streaming) internal sealed class StreamIterator : IAsyncEnumerator, IAsyncEnumerable { private readonly AsyncServerStreamingCall _responseStream; - private readonly Action _rpcErrorAction; + private readonly Action _rpcErrorAction; - internal StreamIterator(AsyncServerStreamingCall responseStream, Action rpcErrorAction) + internal StreamIterator(AsyncServerStreamingCall responseStream, Action rpcErrorAction) { _responseStream = responseStream; _rpcErrorAction = rpcErrorAction; @@ -349,7 +345,8 @@ public async ValueTask MoveNextAsync() } catch (RpcException e) { - _rpcErrorAction(e); + _rpcErrorAction(); + throw new TransportException(e); } } @@ -367,10 +364,6 @@ public class InitializationFailureException : Exception internal InitializationFailureException(string message) : base(message) { } - - internal InitializationFailureException(string message, Exception inner) : base(message, inner) - { - } } public class TransportException : IOException diff --git a/src/Ydb.Sdk/src/GrpcRequestSettings.cs b/src/Ydb.Sdk/src/GrpcRequestSettings.cs index 1775b6bb..683f2290 100644 --- a/src/Ydb.Sdk/src/GrpcRequestSettings.cs +++ b/src/Ydb.Sdk/src/GrpcRequestSettings.cs @@ -1,6 +1,5 @@ using System.Collections.Immutable; using Google.Protobuf.WellKnownTypes; -using Grpc.Core; using Ydb.Operations; namespace Ydb.Sdk; @@ -11,13 +10,10 @@ public class GrpcRequestSettings public string TraceId { get; set; } = string.Empty; public TimeSpan? TransportTimeout { get; set; } - public ImmutableArray CustomClientHeaders { get; set; } + public ImmutableArray CustomClientHeaders { get; } = new(); internal long NodeId { get; set; } - - internal Action TrailersHandler { get; set; } = _ => { }; - - internal Action RpcErrorHandler { get; set; } = _ => { }; + internal Action TrailersHandler { get; set; } = _ => { }; } public class OperationSettings : GrpcRequestSettings diff --git a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs index 73ed138e..a1d3dc7e 100644 --- a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs @@ -58,14 +58,7 @@ protected override async Task CreateSession() return; } - var statusSession = Status.FromProto(stream.Current.Status, stream.Current.Issues); - - if (statusSession.IsNotSuccess) - { - completeTask.SetResult(statusSession); - } - - completeTask.SetResult(Status.Success); + completeTask.SetResult(Status.FromProto(stream.Current.Status, stream.Current.Issues)); try { @@ -85,9 +78,9 @@ protected override async Task CreateSession() { } } - catch (Driver.TransportException e) + catch (Exception e) { - completeTask.SetResult(e.Status); + completeTask.SetException(e); } finally { diff --git a/src/Ydb.Sdk/src/Services/Table/Session.cs b/src/Ydb.Sdk/src/Services/Table/Session.cs index e6c5b71a..9525827e 100644 --- a/src/Ydb.Sdk/src/Services/Table/Session.cs +++ b/src/Ydb.Sdk/src/Services/Table/Session.cs @@ -23,13 +23,8 @@ private void OnResponseStatus(Status status) } } - private void OnResponseTrailers(Grpc.Core.Metadata? trailers) + private void OnResponseTrailers(Grpc.Core.Metadata trailers) { - if (trailers is null) - { - return; - } - foreach (var hint in trailers.GetAll(Metadata.RpcServerHintsHeader)) { if (hint.Value == Metadata.GracefulShutdownHint)