Skip to content

Commit acaca39

Browse files
authored
Merge 4b5d890 into 2f073c6
2 parents 2f073c6 + 4b5d890 commit acaca39

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

ydb/library/grpc/client/grpc_client_low.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,8 @@ void TChannelPool::GetStubsHolderLocked(
141141
}
142142
}
143143
}
144-
TGRpcKeepAliveSocketMutator* mutator = nullptr;
144+
auto mutator = NImpl::CreateGRpcKeepAliveSocketMutator(TcpKeepAliveSettings_);
145145
// will be destroyed inside grpc
146-
if (TcpKeepAliveSettings_.Enabled) {
147-
mutator = new TGRpcKeepAliveSocketMutator(
148-
TcpKeepAliveSettings_.Idle,
149-
TcpKeepAliveSettings_.Count,
150-
TcpKeepAliveSettings_.Interval
151-
);
152-
}
153146
cb(Pool_.emplace(channelId, CreateChannelInterface(config, mutator)).first->second);
154147
LastUsedQueue_.emplace(Pool_.at(channelId).GetLastUseTime(), channelId);
155148
}
@@ -588,4 +581,16 @@ void TGRpcClientLow::ForgetContext(TContextImpl* context) {
588581
}
589582
}
590583

584+
grpc_socket_mutator* NImpl::CreateGRpcKeepAliveSocketMutator(const TTcpKeepAliveSettings& TcpKeepAliveSettings_) {
585+
TGRpcKeepAliveSocketMutator* mutator = nullptr;
586+
if (TcpKeepAliveSettings_.Enabled) {
587+
mutator = new TGRpcKeepAliveSocketMutator(
588+
TcpKeepAliveSettings_.Idle,
589+
TcpKeepAliveSettings_.Count,
590+
TcpKeepAliveSettings_.Interval
591+
);
592+
}
593+
return mutator;
594+
}
595+
591596
} // namespace NGRpc

ydb/library/grpc/client/grpc_client_low.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ class IStreamRequestReadWriteProcessor : public IStreamRequestReadProcessor<TRes
451451

452452
class TGRpcKeepAliveSocketMutator;
453453

454+
namespace NImpl {
455+
grpc_socket_mutator* CreateGRpcKeepAliveSocketMutator(const TTcpKeepAliveSettings& TcpKeepAliveSettings_);
456+
} // NImpl
457+
454458
// Class to hold stubs allocated on channel.
455459
// It is poor documented part of grpc. See KIKIMR-6109 and comment to this commit
456460

@@ -1386,6 +1390,13 @@ class TGRpcClientLow
13861390
return std::unique_ptr<TServiceConnection<TGRpcService>>(new TServiceConnection<TGRpcService>(CreateChannelInterface(config), this));
13871391
}
13881392

1393+
template<typename TGRpcService>
1394+
std::unique_ptr<TServiceConnection<TGRpcService>> CreateGRpcServiceConnection(const TGRpcClientConfig& config, const TTcpKeepAliveSettings& keepAlive) {
1395+
auto mutator = NImpl::CreateGRpcKeepAliveSocketMutator(keepAlive);
1396+
// will be destroyed inside grpc
1397+
return std::unique_ptr<TServiceConnection<TGRpcService>>(new TServiceConnection<TGRpcService>(CreateChannelInterface(config, mutator), this));
1398+
}
1399+
13891400
template<typename TGRpcService>
13901401
std::unique_ptr<TServiceConnection<TGRpcService>> CreateGRpcServiceConnection(TStubsHolder& holder) {
13911402
return std::unique_ptr<TServiceConnection<TGRpcService>>(new TServiceConnection<TGRpcService>(holder, this));

ydb/library/yql/providers/generic/connector/libcpp/client.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ namespace NYql::NConnector {
4444
GrpcClient_ = std::make_unique<NYdbGrpc::TGRpcClientLow>();
4545

4646
// FIXME: is it OK to use single connection during the client lifetime?
47-
GrpcConnection_ = GrpcClient_->CreateGRpcServiceConnection<NApi::Connector>(GrpcConfig_);
47+
GrpcConnection_ = GrpcClient_->CreateGRpcServiceConnection<NApi::Connector>(GrpcConfig_, NYdbGrpc::TTcpKeepAliveSettings {
48+
// TODO configure hardcoded values
49+
.Enabled = true,
50+
.Idle = 30,
51+
.Count = 5,
52+
.Interval = 10
53+
});
4854
}
4955

5056
virtual TDescribeTableAsyncResult DescribeTable(const NApi::TDescribeTableRequest& request) override {

0 commit comments

Comments
 (0)