Skip to content

Commit 43a758e

Browse files
fix
1 parent 08a57ab commit 43a758e

File tree

7 files changed

+27
-65
lines changed

7 files changed

+27
-65
lines changed

src/Ydb.Sdk/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- `YdbException`: Added cancellation token propagation support in `CommitAsync` and `RollbackAsync`.
2-
- Delete legacy exceptions: Driver.TransportException and StatusUnsuccessfulException.
3-
- Fixed bug: Unhandled exception System.Net.Http.HttpIOException convert to YdbException ([grpc-dotnet issue](https://github.com/grpc/grpc-dotnet/issues/2638)).
2+
- Deleted legacy exceptions: Driver.TransportException, StatusUnsuccessfulException and InitializationFailureException.
3+
- Fixed bug: Unhandled exception System.Net.Http.HttpIOException has now been converted to YdbException ([grpc-dotnet issue](https://github.com/grpc/grpc-dotnet/issues/2638)).
44
- Added 'x-ydb-client-pid' header to any RPC calls.
55
- Added DisableServerBalancer option to ADO.NET session creation; default false.
66

src/Ydb.Sdk/src/Ado/Internal/StatusCodeUtils.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,8 @@ public static class StatusCodeUtils
1414
_ => StatusCode.ClientTransportUnknown
1515
};
1616

17-
internal static StatusCode Code(this StatusIds.Types.StatusCode statusCode)
18-
{
19-
var value = (uint)statusCode;
20-
if (Enum.IsDefined(typeof(StatusCode), value))
21-
{
22-
return (StatusCode)value;
23-
}
24-
25-
return StatusCode.Unspecified;
26-
}
17+
internal static StatusCode Code(this StatusIds.Types.StatusCode statusCode) =>
18+
Enum.IsDefined(typeof(StatusCode), (int)statusCode) ? (StatusCode)statusCode : StatusCode.Unavailable;
2719

2820
internal static bool IsNotSuccess(this StatusIds.Types.StatusCode code) =>
2921
code != StatusIds.Types.StatusCode.Success;

src/Ydb.Sdk/src/Ado/YdbException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static YdbException FromServer(StatusIds.Types.StatusCode statusCode, I
2020
var code = statusCode.Code();
2121

2222
var message = code.ToMessage(issues);
23-
23+
2424
return new YdbException(code, message);
2525
}
2626

src/Ydb.Sdk/src/Driver.cs

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Microsoft.Extensions.Logging.Abstractions;
55
using Ydb.Discovery;
66
using Ydb.Discovery.V1;
7+
using Ydb.Sdk.Ado;
8+
using Ydb.Sdk.Ado.Internal;
79
using Ydb.Sdk.Pool;
810

911
namespace Ydb.Sdk;
@@ -39,19 +41,15 @@ public async Task Initialize()
3941
{
4042
try
4143
{
42-
var status = await DiscoverEndpoints();
43-
if (status.IsSuccess)
44-
{
45-
_ = Task.Run(PeriodicDiscovery);
46-
47-
return;
48-
}
44+
await DiscoverEndpoints();
4945

50-
Logger.LogCritical("Error during initial endpoint discovery: {status}", status);
46+
_ = Task.Run(PeriodicDiscovery);
47+
48+
return;
5149
}
52-
catch (RpcException e)
50+
catch (YdbException e)
5351
{
54-
Logger.LogCritical("RPC error during initial endpoint discovery: {e.Status}", e.Status);
52+
Logger.LogError(e, "RPC error during initial endpoint discovery: {e.Status}", e.Code);
5553

5654
if (i == AttemptDiscovery - 1)
5755
{
@@ -62,7 +60,7 @@ public async Task Initialize()
6260
await Task.Delay(TimeSpan.FromMilliseconds(i * 200)); // await 0 ms, 200 ms, 400ms, ... 1.8 sec
6361
}
6462

65-
throw new InitializationFailureException("Error during initial endpoint discovery");
63+
throw new YdbException("Error during initial endpoint discovery");
6664
}
6765

6866
protected override string GetEndpoint(long nodeId) => _endpointPool.GetEndpoint(nodeId);
@@ -90,7 +88,7 @@ Grpc.Core.StatusCode.DeadlineExceeded or
9088
_ = Task.Run(DiscoverEndpoints);
9189
}
9290

93-
private async Task<Status> DiscoverEndpoints()
91+
private async Task DiscoverEndpoints()
9492
{
9593
using var channel = GrpcChannelFactory.CreateChannel(Config.Endpoint);
9694

@@ -111,30 +109,13 @@ private async Task<Status> DiscoverEndpoints()
111109
options: await GetCallOptions(requestSettings)
112110
);
113111

114-
if (!response.Operation.Ready)
112+
var operation = response.Operation;
113+
if (operation.Status.IsNotSuccess())
115114
{
116-
const string error = "Unexpected non-ready endpoint discovery operation.";
117-
Logger.LogError($"Endpoint discovery internal error: {error}");
118-
119-
return new Status(StatusCode.ClientInternalError, error);
115+
throw YdbException.FromServer(operation.Status, operation.Issues);
120116
}
121117

122-
var status = Status.FromProto(response.Operation.Status, response.Operation.Issues);
123-
if (status.IsNotSuccess)
124-
{
125-
Logger.LogWarning("Unsuccessful endpoint discovery: {Status}", status);
126-
return status;
127-
}
128-
129-
if (response.Operation.Result is null)
130-
{
131-
const string error = "Unexpected empty endpoint discovery result.";
132-
Logger.LogError($"Endpoint discovery internal error: {error}");
133-
134-
return new Status(StatusCode.ClientInternalError, error);
135-
}
136-
137-
var resultProto = response.Operation.Result.Unpack<ListEndpointsResult>();
118+
var resultProto = operation.Result.Unpack<ListEndpointsResult>();
138119

139120
Logger.LogDebug(
140121
"Successfully discovered endpoints: {EndpointsCount}, self location: {SelfLocation}, sdk info: {SdkInfo}",
@@ -151,8 +132,6 @@ await ChannelPool.RemoveChannels(
151132
.ToImmutableArray()
152133
)
153134
);
154-
155-
return new Status(StatusCode.Success);
156135
}
157136

158137
private async Task PeriodicDiscovery()
@@ -163,23 +142,16 @@ private async Task PeriodicDiscovery()
163142
{
164143
await Task.Delay(Config.EndpointDiscoveryInterval);
165144

166-
_ = await DiscoverEndpoints();
145+
await DiscoverEndpoints();
167146
}
168-
catch (RpcException e)
147+
catch (YdbException e)
169148
{
170-
Logger.LogWarning("RPC error during endpoint discovery: {Status}", e.Status);
149+
Logger.LogWarning(e, "Error during endpoint discovery");
171150
}
172151
catch (Exception e)
173152
{
174153
Logger.LogError(e, "Unexpected exception during session pool periodic check");
175154
}
176155
}
177156
}
178-
179-
public class InitializationFailureException : Exception
180-
{
181-
internal InitializationFailureException(string message) : base(message)
182-
{
183-
}
184-
}
185157
}

src/Ydb.Sdk/src/Services/Table/CopyTable.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Ydb.Sdk.Ado;
21
using Ydb.Sdk.Client;
32
using Ydb.Sdk.Services.Operations;
43
using Ydb.Table;

src/Ydb.Sdk/src/Status.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ public override string ToString()
207207

208208
private static StatusCode ConvertStatusCode(StatusIds.Types.StatusCode statusCode)
209209
{
210-
var value = (uint)statusCode;
211-
if (Enum.IsDefined(typeof(StatusCode), value))
210+
if (Enum.IsDefined(typeof(StatusCode), (int)statusCode))
212211
{
213-
return (StatusCode)value;
212+
return (StatusCode)statusCode;
214213
}
215214

216215
return StatusCode.Unspecified;

src/Ydb.Sdk/src/Value/YdbValue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Ydb.Sdk.Value;
22

3-
public enum YdbTypeId : uint
3+
public enum YdbTypeId
44
{
55
Unknown = 0,
66

@@ -45,7 +45,7 @@ public enum YdbTypeId : uint
4545

4646
internal static class YdbTypeIdRanges
4747
{
48-
public const uint ComplexTypesFirst = 0xffff;
48+
public const int ComplexTypesFirst = 0xffff;
4949
}
5050

5151
public sealed partial class YdbValue
@@ -85,7 +85,7 @@ private static string ToYql(Type type) =>
8585
internal static YdbTypeId GetYdbTypeId(Type protoType) =>
8686
protoType.TypeCase switch
8787
{
88-
Type.TypeOneofCase.TypeId => Enum.IsDefined(typeof(YdbTypeId), (uint)protoType.TypeId)
88+
Type.TypeOneofCase.TypeId => Enum.IsDefined(typeof(YdbTypeId), (int)protoType.TypeId)
8989
? (YdbTypeId)protoType.TypeId
9090
: YdbTypeId.Unknown,
9191
Type.TypeOneofCase.DecimalType => YdbTypeId.DecimalType,

0 commit comments

Comments
 (0)