Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Ydb.Sdk/src/IDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

namespace Ydb.Sdk;

public interface IDriver : IAsyncDisposable, IDisposable
internal interface IDriver : IAsyncDisposable, IDisposable
{
internal Task<TResponse> UnaryCall<TRequest, TResponse>(
Task<TResponse> UnaryCall<TRequest, TResponse>(
Method<TRequest, TResponse> method,
TRequest request,
GrpcRequestSettings settings)
where TRequest : class
where TResponse : class;

internal ServerStream<TResponse> ServerStreamCall<TRequest, TResponse>(
ServerStream<TResponse> ServerStreamCall<TRequest, TResponse>(
Method<TRequest, TResponse> method,
TRequest request,
GrpcRequestSettings settings)
where TRequest : class
where TResponse : class;

internal BidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TRequest, TResponse>(
BidirectionalStream<TRequest, TResponse> BidirectionalStreamCall<TRequest, TResponse>(
Method<TRequest, TResponse> method,
GrpcRequestSettings settings)
where TRequest : class
Expand All @@ -33,6 +33,7 @@ public abstract class BaseDriver : IDriver
{
protected readonly DriverConfig Config;
protected readonly ILogger Logger;
protected readonly ILoggerFactory LoggerFactory;

protected int Disposed;

Expand All @@ -43,7 +44,7 @@ protected BaseDriver(DriverConfig config, ILoggerFactory loggerFactory, ILogger
LoggerFactory = loggerFactory;
}

public async Task<TResponse> UnaryCall<TRequest, TResponse>(
async Task<TResponse> IDriver.UnaryCall<TRequest, TResponse>(
Method<TRequest, TResponse> method,
TRequest request,
GrpcRequestSettings settings)
Expand Down Expand Up @@ -155,7 +156,7 @@ protected CallOptions GetCallOptions(GrpcRequestSettings settings, bool streamin
return options;
}

public ILoggerFactory LoggerFactory { get; }
ILoggerFactory IDriver.LoggerFactory => LoggerFactory;

public void Dispose()
{
Expand All @@ -166,6 +167,8 @@ public async ValueTask DisposeAsync()
{
if (Interlocked.CompareExchange(ref Disposed, 1, 0) == 0)
{
GC.SuppressFinalize(this);

await InternalDispose();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Ydb.Sdk/src/Pool/ChannelPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
using Microsoft.Extensions.Logging;
using Org.BouncyCastle.Security;

#if TEST
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
#endif

namespace Ydb.Sdk.Pool;

internal class ChannelPool<T> : IAsyncDisposable where T : ChannelBase, IDisposable
Expand Down
6 changes: 4 additions & 2 deletions src/Ydb.Sdk/src/Services/Auth/AuthClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public async Task<LoginResponse> Login(string user, string? password, LoginSetti

try
{
await using var transport = new AuthGrpcChannelDriver(_config, _grpcChannelFactory, _loggerFactory);
await using var driver = Driver;

var response = await transport.UnaryCall(
var response = await driver.UnaryCall(
method: AuthService.LoginMethod,
request: request,
settings: settings
Expand All @@ -61,6 +61,8 @@ public async Task<LoginResponse> Login(string user, string? password, LoginSetti
return new LoginResponse(e.Status);
}
}

private IDriver Driver => new AuthGrpcChannelDriver(_config, _grpcChannelFactory, _loggerFactory);
}

public class LoginSettings : OperationSettings
Expand Down
7 changes: 6 additions & 1 deletion src/Ydb.Sdk/src/Services/Operations/OperationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

public partial class OperationsClient
{
private readonly Driver _driver;
private readonly IDriver _driver;

public OperationsClient(Driver driver)
{
_driver = driver;
}

internal OperationsClient(IDriver driver)
{
_driver = driver;
}
}
8 changes: 4 additions & 4 deletions src/Ydb.Sdk/src/Services/Query/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ internal sealed class SessionPool : SessionPool<Session>, IAsyncDisposable
TransportTimeout = TimeSpan.FromMinutes(1)
};

private readonly Driver _driver;
private readonly IDriver _driver;
private readonly bool _disposingDriver;

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

internal class Session : SessionBase<Session>
{
private readonly Driver _driver;
private readonly IDriver _driver;

internal Session(Driver driver, SessionPool<Session> sessionPool, string sessionId, long nodeId)
internal Session(IDriver driver, SessionPool<Session> sessionPool, string sessionId, long nodeId)
: base(sessionPool, sessionId, nodeId)
{
_driver = driver;
Expand Down
8 changes: 4 additions & 4 deletions src/Ydb.Sdk/src/Services/Scheme/SchemeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static Permissions FromProto(Ydb.Scheme.Permissions permissionsProto)

public class SchemeEntry
{
internal SchemeEntry(
private SchemeEntry(
string name,
string owner,
SchemeEntryType type,
Expand All @@ -69,11 +69,11 @@ internal static SchemeEntry FromProto(Entry entryProto)
: SchemeEntryType.Unspecified;

var effectivePermissions = entryProto.EffectivePermissions
.Select(p => Scheme.Permissions.FromProto(p))
.Select(Scheme.Permissions.FromProto)
.ToList();

var permissions = entryProto.Permissions
.Select(p => Scheme.Permissions.FromProto(p))
.Select(Scheme.Permissions.FromProto)
.ToList();

return new SchemeEntry(
Expand Down Expand Up @@ -120,7 +120,7 @@ internal static ResultData FromProto(ListDirectoryResult resultProto)

public class SchemeClient
{
private readonly Driver _driver;
private readonly IDriver _driver;

public SchemeClient(Driver driver)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Ydb.Sdk/src/Services/Sessions/SessionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Ydb.Sdk.Services.Sessions;

public abstract class SessionBase : IDisposable
{
protected readonly Driver Driver;
internal static readonly TimeSpan DeleteSessionTimeout = TimeSpan.FromSeconds(1);

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

protected SessionBase(Driver driver, string id, long nodeId, ILogger logger)
protected SessionBase(string id, long nodeId, ILogger logger)
{
Driver = driver;
Id = id;
NodeId = nodeId;
Logger = logger;
Expand Down
6 changes: 3 additions & 3 deletions src/Ydb.Sdk/src/Services/Sessions/SessionPoolBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public void Dispose()
}
}

public abstract class SessionPoolBase<TSession> : ISessionPool<TSession> where TSession : SessionBase
internal abstract class SessionPoolBase<TSession> : ISessionPool<TSession> where TSession : SessionBase
{
private const int MaxAttempts = 100;

private protected readonly Driver Driver;
private protected readonly IDriver Driver;
private protected readonly ILogger Logger;
private protected readonly SessionPoolConfig Config;

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

protected SessionPoolBase(Driver driver, SessionPoolConfig config, ILogger logger)
protected SessionPoolBase(IDriver driver, SessionPoolConfig config, ILogger logger)
{
Driver = driver;
Config = config;
Expand Down
2 changes: 1 addition & 1 deletion src/Ydb.Sdk/src/Services/Table/CreateSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private ResultData(Session session)

public Session Session { get; }

internal static ResultData FromProto(CreateSessionResult resultProto, Driver driver)
internal static ResultData FromProto(CreateSessionResult resultProto, IDriver driver)
{
var session = new Session(
driver: driver,
Expand Down
10 changes: 6 additions & 4 deletions src/Ydb.Sdk/src/Services/Table/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ namespace Ydb.Sdk.Services.Table;
public partial class Session : SessionBase
{
private readonly SessionPool? _sessionPool;
private readonly IDriver _driver;

internal Session(Driver driver, SessionPool? sessionPool, string id, long nodeId)
: base(driver, id, nodeId, driver.LoggerFactory.CreateLogger<Session>())
internal Session(IDriver driver, SessionPool? sessionPool, string id, long nodeId)
: base(id, nodeId, driver.LoggerFactory.CreateLogger<Session>())
{
_driver = driver;
_sessionPool = sessionPool;
}

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

var client = new TableClient(Driver, new NoPool<Session>());
var client = new TableClient(_driver, new NoPool<Session>());
var task = client.DeleteSession(Id, new DeleteSessionSettings
{
TransportTimeout = DeleteSessionTimeout
Expand All @@ -74,7 +76,7 @@ private async Task<TResponse> UnaryCall<TRequest, TResponse>(
settings.NodeId = NodeId;
settings.TrailersHandler = OnResponseTrailers;

return await Driver.UnaryCall(
return await _driver.UnaryCall(
method: method,
request: request,
settings: settings
Expand Down
7 changes: 2 additions & 5 deletions src/Ydb.Sdk/src/Services/Table/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ internal sealed class SessionPool : SessionPoolBase<Session>
{
private readonly TableClient _tableClient;

public SessionPool(Driver driver, SessionPoolConfig config) :
base(
driver: driver,
config: config,
logger: driver.LoggerFactory.CreateLogger<SessionPool>())
public SessionPool(IDriver driver, SessionPoolConfig config) :
base(driver: driver, config: config, logger: driver.LoggerFactory.CreateLogger<SessionPool>())
{
_tableClient = new TableClient(driver, new NoPool());

Expand Down
9 changes: 6 additions & 3 deletions src/Ydb.Sdk/src/Services/Table/TableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public TableClientConfig(
public partial class TableClient : IDisposable
{
private readonly ISessionPool<Session> _sessionPool;
private readonly Driver _driver;
private readonly IDriver _driver;
private readonly string _database;

private bool _disposed;

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

_driver = driver;
_database = driver.Database;
_sessionPool = new SessionPool(driver, config.SessionPoolConfig);
}

internal TableClient(Driver driver, ISessionPool<Session> sessionPool)
internal TableClient(IDriver driver, ISessionPool<Session> sessionPool)
{
_driver = driver;
_sessionPool = sessionPool;
_database = ""; // stub legacy client
}

public void Dispose()
Expand All @@ -57,6 +60,6 @@ private void Dispose(bool disposing)

internal string MakeTablePath(string path)
{
return path.StartsWith('/') ? path : $"{_driver.Database}/{path}";
return path.StartsWith('/') ? path : $"{_database}/{path}";
}
}
2 changes: 1 addition & 1 deletion src/Ydb.Sdk/src/Services/Topic/TopicClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Ydb.Sdk.Services.Topic;

public class TopicClient
{
private readonly Driver _driver;
private readonly IDriver _driver;

public TopicClient(Driver driver)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Ydb.Sdk/tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<PropertyGroup Condition="$(TargetFramework.Equals('net7.0'))">
</PropertyGroup>

<PropertyGroup>
<DefineConstants>TEST</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0-rc.1.23419.4" />
Expand All @@ -40,5 +44,4 @@
<ItemGroup>
<ProjectReference Include="..\src\Ydb.Sdk.csproj" />
</ItemGroup>

</Project>
Loading