Skip to content

Commit 0c81bea

Browse files
init commit
1 parent c357731 commit 0c81bea

File tree

11 files changed

+46
-35
lines changed

11 files changed

+46
-35
lines changed

src/Ydb.Sdk/src/IDriver.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
namespace Ydb.Sdk;
66

7-
public interface IDriver : IAsyncDisposable, IDisposable
7+
internal interface IDriver : IAsyncDisposable, IDisposable
88
{
9-
internal Task<TResponse> UnaryCall<TRequest, TResponse>(
9+
Task<TResponse> UnaryCall<TRequest, TResponse>(
1010
Method<TRequest, TResponse> method,
1111
TRequest request,
1212
GrpcRequestSettings settings)
1313
where TRequest : class
1414
where TResponse : class;
1515

16-
internal ServerStream<TResponse> ServerStreamCall<TRequest, TResponse>(
16+
ServerStream<TResponse> ServerStreamCall<TRequest, TResponse>(
1717
Method<TRequest, TResponse> method,
1818
TRequest request,
1919
GrpcRequestSettings settings)
2020
where TRequest : class
2121
where TResponse : class;
2222

23-
internal BidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TRequest, TResponse>(
23+
BidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TRequest, TResponse>(
2424
Method<TRequest, TResponse> method,
2525
GrpcRequestSettings settings)
2626
where TRequest : class
@@ -33,6 +33,7 @@ public abstract class BaseDriver : IDriver
3333
{
3434
protected readonly DriverConfig Config;
3535
protected readonly ILogger Logger;
36+
protected readonly ILoggerFactory LoggerFactory;
3637

3738
protected int Disposed;
3839

@@ -43,7 +44,7 @@ protected BaseDriver(DriverConfig config, ILoggerFactory loggerFactory, ILogger
4344
LoggerFactory = loggerFactory;
4445
}
4546

46-
public async Task<TResponse> UnaryCall<TRequest, TResponse>(
47+
async Task<TResponse> IDriver.UnaryCall<TRequest, TResponse>(
4748
Method<TRequest, TResponse> method,
4849
TRequest request,
4950
GrpcRequestSettings settings)
@@ -155,7 +156,7 @@ protected CallOptions GetCallOptions(GrpcRequestSettings settings, bool streamin
155156
return options;
156157
}
157158

158-
public ILoggerFactory LoggerFactory { get; }
159+
ILoggerFactory IDriver.LoggerFactory => LoggerFactory;
159160

160161
public void Dispose()
161162
{
@@ -166,6 +167,8 @@ public async ValueTask DisposeAsync()
166167
{
167168
if (Interlocked.CompareExchange(ref Disposed, 1, 0) == 0)
168169
{
170+
GC.SuppressFinalize(this);
171+
169172
await InternalDispose();
170173
}
171174
}

src/Ydb.Sdk/src/Services/Operations/OperationsClient.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
public partial class OperationsClient
44
{
5-
private readonly Driver _driver;
5+
private readonly IDriver _driver;
66

77
public OperationsClient(Driver driver)
88
{
99
_driver = driver;
1010
}
11+
12+
internal OperationsClient(IDriver driver)
13+
{
14+
_driver = driver;
15+
}
1116
}

src/Ydb.Sdk/src/Services/Query/SessionPool.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ internal sealed class SessionPool : SessionPool<Session>, IAsyncDisposable
2020
TransportTimeout = TimeSpan.FromMinutes(1)
2121
};
2222

23-
private readonly Driver _driver;
23+
private readonly IDriver _driver;
2424
private readonly bool _disposingDriver;
2525

26-
internal SessionPool(Driver driver, int? maxSessionPool = null, bool disposingDriver = false)
26+
internal SessionPool(IDriver driver, int? maxSessionPool = null, bool disposingDriver = false)
2727
: base(driver.LoggerFactory.CreateLogger<SessionPool>(), maxSessionPool)
2828
{
2929
_driver = driver;
@@ -132,9 +132,9 @@ protected override ValueTask DisposeDriver()
132132

133133
internal class Session : SessionBase<Session>
134134
{
135-
private readonly Driver _driver;
135+
private readonly IDriver _driver;
136136

137-
internal Session(Driver driver, SessionPool<Session> sessionPool, string sessionId, long nodeId)
137+
internal Session(IDriver driver, SessionPool<Session> sessionPool, string sessionId, long nodeId)
138138
: base(sessionPool, sessionId, nodeId)
139139
{
140140
_driver = driver;

src/Ydb.Sdk/src/Services/Scheme/SchemeClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal static Permissions FromProto(Ydb.Scheme.Permissions permissionsProto)
4242

4343
public class SchemeEntry
4444
{
45-
internal SchemeEntry(
45+
private SchemeEntry(
4646
string name,
4747
string owner,
4848
SchemeEntryType type,
@@ -69,11 +69,11 @@ internal static SchemeEntry FromProto(Entry entryProto)
6969
: SchemeEntryType.Unspecified;
7070

7171
var effectivePermissions = entryProto.EffectivePermissions
72-
.Select(p => Scheme.Permissions.FromProto(p))
72+
.Select(Scheme.Permissions.FromProto)
7373
.ToList();
7474

7575
var permissions = entryProto.Permissions
76-
.Select(p => Scheme.Permissions.FromProto(p))
76+
.Select(Scheme.Permissions.FromProto)
7777
.ToList();
7878

7979
return new SchemeEntry(
@@ -120,7 +120,7 @@ internal static ResultData FromProto(ListDirectoryResult resultProto)
120120

121121
public class SchemeClient
122122
{
123-
private readonly Driver _driver;
123+
private readonly IDriver _driver;
124124

125125
public SchemeClient(Driver driver)
126126
{

src/Ydb.Sdk/src/Services/Sessions/SessionBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace Ydb.Sdk.Services.Sessions;
44

55
public abstract class SessionBase : IDisposable
66
{
7-
protected readonly Driver Driver;
87
internal static readonly TimeSpan DeleteSessionTimeout = TimeSpan.FromSeconds(1);
98

109
public string Id { get; }
@@ -13,9 +12,8 @@ public abstract class SessionBase : IDisposable
1312
private protected bool Disposed;
1413
protected readonly ILogger Logger;
1514

16-
protected SessionBase(Driver driver, string id, long nodeId, ILogger logger)
15+
protected SessionBase(string id, long nodeId, ILogger logger)
1716
{
18-
Driver = driver;
1917
Id = id;
2018
NodeId = nodeId;
2119
Logger = logger;

src/Ydb.Sdk/src/Services/Sessions/SessionPoolBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ public void Dispose()
5555
}
5656
}
5757

58-
public abstract class SessionPoolBase<TSession> : ISessionPool<TSession> where TSession : SessionBase
58+
internal abstract class SessionPoolBase<TSession> : ISessionPool<TSession> where TSession : SessionBase
5959
{
6060
private const int MaxAttempts = 100;
6161

62-
private protected readonly Driver Driver;
62+
private protected readonly IDriver Driver;
6363
private protected readonly ILogger Logger;
6464
private protected readonly SessionPoolConfig Config;
6565

@@ -70,7 +70,7 @@ public abstract class SessionPoolBase<TSession> : ISessionPool<TSession> where T
7070
private protected readonly Stack<string> IdleSessions = new();
7171
protected uint PendingSessions;
7272

73-
protected SessionPoolBase(Driver driver, SessionPoolConfig config, ILogger logger)
73+
protected SessionPoolBase(IDriver driver, SessionPoolConfig config, ILogger logger)
7474
{
7575
Driver = driver;
7676
Config = config;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ namespace Ydb.Sdk.Services.Table;
77
public partial class Session : SessionBase
88
{
99
private readonly SessionPool? _sessionPool;
10+
private readonly IDriver _driver;
1011

11-
internal Session(Driver driver, SessionPool? sessionPool, string id, long nodeId)
12-
: base(driver, id, nodeId, driver.LoggerFactory.CreateLogger<Session>())
12+
internal Session(IDriver driver, SessionPool? sessionPool, string id, long nodeId)
13+
: base(id, nodeId, driver.LoggerFactory.CreateLogger<Session>())
1314
{
15+
_driver = driver;
1416
_sessionPool = sessionPool;
1517
}
1618

@@ -48,7 +50,7 @@ protected override void Dispose(bool disposing)
4850
{
4951
Logger.LogTrace($"Closing detached session on dispose: {Id}");
5052

51-
var client = new TableClient(Driver, new NoPool<Session>());
53+
var client = new TableClient(_driver, new NoPool<Session>());
5254
var task = client.DeleteSession(Id, new DeleteSessionSettings
5355
{
5456
TransportTimeout = DeleteSessionTimeout
@@ -74,7 +76,7 @@ private async Task<TResponse> UnaryCall<TRequest, TResponse>(
7476
settings.NodeId = NodeId;
7577
settings.TrailersHandler = OnResponseTrailers;
7678

77-
return await Driver.UnaryCall(
79+
return await _driver.UnaryCall(
7880
method: method,
7981
request: request,
8082
settings: settings

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ internal sealed class SessionPool : SessionPoolBase<Session>
1010
{
1111
private readonly TableClient _tableClient;
1212

13-
public SessionPool(Driver driver, SessionPoolConfig config) :
14-
base(
15-
driver: driver,
16-
config: config,
17-
logger: driver.LoggerFactory.CreateLogger<SessionPool>())
13+
public SessionPool(IDriver driver, SessionPoolConfig config) :
14+
base(driver: driver, config: config, logger: driver.LoggerFactory.CreateLogger<SessionPool>())
1815
{
1916
_tableClient = new TableClient(driver, new NoPool());
2017

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public TableClientConfig(
1616
public partial class TableClient : IDisposable
1717
{
1818
private readonly ISessionPool<Session> _sessionPool;
19-
private readonly Driver _driver;
19+
private readonly IDriver _driver;
20+
private readonly string _database;
2021

2122
private bool _disposed;
2223

@@ -25,13 +26,15 @@ public TableClient(Driver driver, TableClientConfig? config = null)
2526
config ??= new TableClientConfig();
2627

2728
_driver = driver;
29+
_database = driver.Database;
2830
_sessionPool = new SessionPool(driver, config.SessionPoolConfig);
2931
}
3032

31-
internal TableClient(Driver driver, ISessionPool<Session> sessionPool)
33+
internal TableClient(IDriver driver, ISessionPool<Session> sessionPool)
3234
{
3335
_driver = driver;
3436
_sessionPool = sessionPool;
37+
_database = ""; // stub legacy client
3538
}
3639

3740
public void Dispose()
@@ -57,6 +60,6 @@ private void Dispose(bool disposing)
5760

5861
internal string MakeTablePath(string path)
5962
{
60-
return path.StartsWith('/') ? path : $"{_driver.Database}/{path}";
63+
return path.StartsWith('/') ? path : $"{_database}/{path}";
6164
}
6265
}

src/Ydb.Sdk/src/Services/Topic/TopicClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Ydb.Sdk.Services.Topic;
66

77
public class TopicClient
88
{
9-
private readonly Driver _driver;
9+
private readonly IDriver _driver;
1010

1111
public TopicClient(Driver driver)
1212
{

0 commit comments

Comments
 (0)