diff --git a/src/Ydb.Sdk/CHANGELOG.md b/src/Ydb.Sdk/CHANGELOG.md index 23011212..578cc048 100644 --- a/src/Ydb.Sdk/CHANGELOG.md +++ b/src/Ydb.Sdk/CHANGELOG.md @@ -1,3 +1,4 @@ +- Added `EnableMultipleHttp2Connections` setting to grpc channel. - `Connection.State` is set to `Broken` when the session is deactivated. ## v0.16.2 diff --git a/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs b/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs index 66a96619..45251720 100644 --- a/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs +++ b/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs @@ -29,6 +29,7 @@ private void InitDefaultValues() _useTls = false; _keepAlivePingDelay = SocketHttpHandlerDefaults.DefaultKeepAlivePingSeconds; _keepAlivePingTimeout = SocketHttpHandlerDefaults.DefaultKeepAlivePingTimeoutSeconds; + _enableMultipleHttp2Connections = false; } public string Host @@ -174,6 +175,18 @@ public int KeepAlivePingTimeout private int _keepAlivePingTimeout; + public bool EnableMultipleHttp2Connections + { + get => _enableMultipleHttp2Connections; + set + { + _enableMultipleHttp2Connections = value; + SaveValue(nameof(EnableMultipleHttp2Connections), value); + } + } + + private bool _enableMultipleHttp2Connections; + public ILoggerFactory? LoggerFactory { get; init; } public ICredentialsProvider? CredentialsProvider { get; init; } @@ -237,7 +250,8 @@ internal Task BuildDriver() ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(KeepAlivePingTimeout), User = User, - Password = Password + Password = Password, + EnableMultipleHttp2Connections = EnableMultipleHttp2Connections }, LoggerFactory); } @@ -316,13 +330,16 @@ static YdbConnectionOption() AddOption(new YdbConnectionOption(IntExtractor, (builder, keepAlivePingTimeout) => builder.KeepAlivePingTimeout = keepAlivePingTimeout), "KeepAlivePingTimeout", "Keep Alive Ping Timeout"); + AddOption(new YdbConnectionOption(BoolExtractor, (builder, enableMultipleHttp2Connections) => + builder.EnableMultipleHttp2Connections = enableMultipleHttp2Connections), + "EnableMultipleHttp2Connections", "Enable Multiple Http2 Connections"); } private static void AddOption(YdbConnectionOption option, params string[] keys) { foreach (var key in keys) { - KeyToOption.Add(key, option); + KeyToOption.Add(key.Trim(), option); KeyToOption.Add(key.ToLower(), option); } } diff --git a/src/Ydb.Sdk/src/DriverConfig.cs b/src/Ydb.Sdk/src/DriverConfig.cs index 28eb457d..353f3a89 100644 --- a/src/Ydb.Sdk/src/DriverConfig.cs +++ b/src/Ydb.Sdk/src/DriverConfig.cs @@ -16,6 +16,8 @@ public class DriverConfig public TimeSpan KeepAlivePingTimeout { get; init; } = TimeSpan.FromSeconds(SocketHttpHandlerDefaults.DefaultKeepAlivePingTimeoutSeconds); + public bool EnableMultipleHttp2Connections { get; init; } + public string? User { get; init; } public string? Password { get; init; } diff --git a/src/Ydb.Sdk/src/Pool/ChannelPool.cs b/src/Ydb.Sdk/src/Pool/ChannelPool.cs index b8788020..a5060079 100644 --- a/src/Ydb.Sdk/src/Pool/ChannelPool.cs +++ b/src/Ydb.Sdk/src/Pool/ChannelPool.cs @@ -103,7 +103,8 @@ public GrpcChannel CreateChannel(string endpoint) // https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md KeepAlivePingDelay = _config.KeepAlivePingDelay, KeepAlivePingTimeout = _config.KeepAlivePingTimeout, - KeepAlivePingPolicy = HttpKeepAlivePingPolicy.Always + KeepAlivePingPolicy = HttpKeepAlivePingPolicy.Always, + EnableMultipleHttp2Connections = _config.EnableMultipleHttp2Connections }; // https://github.com/grpc/grpc-dotnet/issues/2312#issuecomment-1790661801 diff --git a/src/Ydb.Sdk/tests/Ado/YdbConnectionStringBuilderTests.cs b/src/Ydb.Sdk/tests/Ado/YdbConnectionStringBuilderTests.cs index 661aba4f..a5bf4caa 100644 --- a/src/Ydb.Sdk/tests/Ado/YdbConnectionStringBuilderTests.cs +++ b/src/Ydb.Sdk/tests/Ado/YdbConnectionStringBuilderTests.cs @@ -19,6 +19,7 @@ public void InitDefaultValues_WhenEmptyConstructorInvoke_ReturnDefaultConnection Assert.Equal(10, connectionString.KeepAlivePingDelay); Assert.Equal(10, connectionString.KeepAlivePingTimeout); Assert.Equal("", connectionString.ConnectionString); + Assert.False(connectionString.EnableMultipleHttp2Connections); } [Fact] @@ -36,7 +37,8 @@ public void InitConnectionStringBuilder_WhenExpectedKeys_ReturnUpdatedConnection { var connectionString = new YdbConnectionStringBuilder("Host=server;Port=2135;Database=/my/path;User=Kirill;UseTls=true;" + - "KeepAlivePingDelay=30;KeepAlivePingTimeout=60"); + "KeepAlivePingDelay=30;KeepAlivePingTimeout=60;" + + "EnableMultipleHttp2Connections=true"); Assert.Equal(2135, connectionString.Port); Assert.Equal("server", connectionString.Host); @@ -46,8 +48,10 @@ public void InitConnectionStringBuilder_WhenExpectedKeys_ReturnUpdatedConnection Assert.Equal(30, connectionString.KeepAlivePingDelay); Assert.Equal(60, connectionString.KeepAlivePingTimeout); Assert.Null(connectionString.Password); + Assert.True(connectionString.EnableMultipleHttp2Connections); Assert.Equal("Host=server;Port=2135;Database=/my/path;User=Kirill;UseTls=True;" + - "KeepAlivePingDelay=30;KeepAlivePingTimeout=60", connectionString.ConnectionString); + "KeepAlivePingDelay=30;KeepAlivePingTimeout=60;" + + "EnableMultipleHttp2Connections=True", connectionString.ConnectionString); } [Fact] @@ -62,4 +66,21 @@ public void Host_WhenSetInProperty_ReturnUpdatedConnectionString() Assert.Equal("Host=new_server;Port=2135;Database=/my/path;User=Kirill", connectionString.ConnectionString); } + + [Fact] + public void SetProperty_WhenPropertyNeedsTrimOperation_ReturnUpdatedConnectionString() + { + var connectionString = + new YdbConnectionStringBuilder(" Host =server;Port=2135; EnableMultipleHttp2Connections =true"); + + Assert.Equal(2135, connectionString.Port); + Assert.Equal("server", connectionString.Host); + Assert.True(connectionString.EnableMultipleHttp2Connections); + + Assert.Equal("Host=server;Port=2135;EnableMultipleHttp2Connections=True", connectionString.ConnectionString); + + connectionString.EnableMultipleHttp2Connections = false; + + Assert.Equal("Host=server;Port=2135;EnableMultipleHttp2Connections=False", connectionString.ConnectionString); + } }