Skip to content

Commit

Permalink
Expose connectivity api for grpc channels
Browse files Browse the repository at this point in the history
commit_hash:f8240948024f6fa2898b60d65635d3c9922359d3
  • Loading branch information
vtyulb committed Nov 20, 2024
1 parent a0d9f14 commit 38b4419
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 7 additions & 2 deletions yt/yt/core/rpc/grpc/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ DEFINE_ENUM(EClientCallStage,
);

class TChannel
: public IChannel
: public NYT::NRpc::NGrpc::IGrpcChannel
{
public:
explicit TChannel(TChannelConfigPtr config)
Expand Down Expand Up @@ -221,6 +221,11 @@ class TChannel
return MemoryUsageTracker_;
}

grpc_connectivity_state CheckConnectivityState(bool tryToConnect) override
{
return grpc_channel_check_connectivity_state(Channel_.Unwrap(), tryToConnect);
}

private:
const TChannelConfigPtr Config_;
const TString EndpointAddress_;
Expand Down Expand Up @@ -736,7 +741,7 @@ class TChannelFactory

} // namespace

IChannelPtr CreateGrpcChannel(TChannelConfigPtr config)
IGrpcChannelPtr CreateGrpcChannel(TChannelConfigPtr config)
{
return New<TChannel>(std::move(config));
}
Expand Down
16 changes: 15 additions & 1 deletion yt/yt/core/rpc/grpc/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
#include "public.h"

#include <yt/yt/core/rpc/public.h>
#include <yt/yt/core/rpc/channel.h>

#include <contrib/libs/grpc/include/grpc/impl/connectivity_state.h>

namespace NYT::NRpc::NGrpc {

////////////////////////////////////////////////////////////////////////////////

struct IGrpcChannel
: public NRpc::IChannel
{
public:
virtual grpc_connectivity_state CheckConnectivityState(bool tryToConnect) = 0;
};

DEFINE_REFCOUNTED_TYPE(IGrpcChannel)

////////////////////////////////////////////////////////////////////////////////

//! Creates a channel implemented via GRPC.
NRpc::IChannelPtr CreateGrpcChannel(TChannelConfigPtr config);
IGrpcChannelPtr CreateGrpcChannel(TChannelConfigPtr config);

//! Returns the factory for creating GRPC channels.
NRpc::IChannelFactoryPtr GetGrpcChannelFactory();
Expand Down
2 changes: 2 additions & 0 deletions yt/yt/core/rpc/grpc/public.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ DECLARE_REFCOUNTED_CLASS(TChannelCredentialsConfig)
DECLARE_REFCOUNTED_CLASS(TChannelConfigTemplate)
DECLARE_REFCOUNTED_CLASS(TChannelConfig)

DECLARE_REFCOUNTED_STRUCT(IGrpcChannel)

////////////////////////////////////////////////////////////////////////////////

extern const char* const TracingTraceIdMetadataKey;
Expand Down

0 comments on commit 38b4419

Please sign in to comment.