diff options
author | babenko <[email protected]> | 2023-10-09 15:41:13 +0300 |
---|---|---|
committer | babenko <[email protected]> | 2023-10-09 16:17:14 +0300 |
commit | a6caa774ac138c8863815d78c15c97479277f500 (patch) | |
tree | 7d30c84ca3211c53028978c1ef8da96f7bd3fbc7 | |
parent | c28d64ce1bb18a1c62601855ffc39ef3e69ae5ef (diff) |
Cosmetics
-rw-r--r-- | yt/yt/core/http/client.h | 3 | ||||
-rw-r--r-- | yt/yt/core/http/public.h | 6 | ||||
-rw-r--r-- | yt/yt/core/http/server.cpp | 80 | ||||
-rw-r--r-- | yt/yt/core/http/server.h | 7 |
4 files changed, 64 insertions, 32 deletions
diff --git a/yt/yt/core/http/client.h b/yt/yt/core/http/client.h index d768be22c7a..0f6ba0239fc 100644 --- a/yt/yt/core/http/client.h +++ b/yt/yt/core/http/client.h @@ -14,10 +14,9 @@ namespace NYT::NHttp { //////////////////////////////////////////////////////////////////////////////// -class IActiveRequest +struct IActiveRequest : public virtual TRefCounted { -public: virtual TFuture<IResponsePtr> Finish() = 0; virtual NConcurrency::IAsyncOutputStreamPtr GetRequestStream() = 0; virtual IResponsePtr GetResponse() = 0; diff --git a/yt/yt/core/http/public.h b/yt/yt/core/http/public.h index 95208767f58..ab1c86db276 100644 --- a/yt/yt/core/http/public.h +++ b/yt/yt/core/http/public.h @@ -11,13 +11,13 @@ DECLARE_REFCOUNTED_CLASS(THeaders) DECLARE_REFCOUNTED_STRUCT(IRequest) DECLARE_REFCOUNTED_STRUCT(IResponse) DECLARE_REFCOUNTED_STRUCT(IResponseWriter) -DECLARE_REFCOUNTED_CLASS(IActiveRequest) +DECLARE_REFCOUNTED_STRUCT(IActiveRequest) DECLARE_REFCOUNTED_STRUCT(IServer) DECLARE_REFCOUNTED_STRUCT(IClient) DECLARE_REFCOUNTED_STRUCT(IRetryingClient) DECLARE_REFCOUNTED_STRUCT(IResponseChecker) - +DECLARE_REFCOUNTED_STRUCT(IRequestPathMatcher) DECLARE_REFCOUNTED_STRUCT(IHttpHandler) DECLARE_REFCOUNTED_CLASS(THttpIOConfig) @@ -25,8 +25,8 @@ DECLARE_REFCOUNTED_CLASS(TServerConfig) DECLARE_REFCOUNTED_CLASS(TClientConfig) DECLARE_REFCOUNTED_CLASS(TRetryingClientConfig) DECLARE_REFCOUNTED_CLASS(TCorsConfig) + DECLARE_REFCOUNTED_CLASS(TConnectionPool) -DECLARE_REFCOUNTED_CLASS(IRequestPathMatcher) //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/http/server.cpp b/yt/yt/core/http/server.cpp index 1327a7cb101..b2c95d1dbd1 100644 --- a/yt/yt/core/http/server.cpp +++ b/yt/yt/core/http/server.cpp @@ -61,21 +61,21 @@ public: const IPollerPtr& poller, const IPollerPtr& acceptor, const IInvokerPtr& invoker, - const IRequestPathMatcherPtr& handlers, + const IRequestPathMatcherPtr& requestPathMatcher, bool ownPoller = false) : Config_(config) , Listener_(listener) , Poller_(poller) , Acceptor_(acceptor) , Invoker_(invoker) - , Handlers_(handlers) + , RequestPathMatcher_(requestPathMatcher) , OwnPoller_(ownPoller) { } void AddHandler(const TString& path, const IHttpHandlerPtr& handler) override { YT_VERIFY(!Started_); - Handlers_->Add(path, handler); + RequestPathMatcher_->Add(path, handler); } const TNetworkAddress& GetAddress() const override @@ -106,14 +106,14 @@ public: void SetPathMatcher(const IRequestPathMatcherPtr& matcher) override { - YT_VERIFY(Handlers_->IsEmpty()); - Handlers_ = matcher; - YT_LOG_INFO("Changed path matcher"); + YT_VERIFY(RequestPathMatcher_->IsEmpty()); + RequestPathMatcher_ = matcher; + YT_LOG_INFO("Request path matcher changed"); } IRequestPathMatcherPtr GetPathMatcher() override { - return Handlers_; + return RequestPathMatcher_; } private: @@ -122,14 +122,13 @@ private: const IPollerPtr Poller_; const IPollerPtr Acceptor_; const IInvokerPtr Invoker_; - IRequestPathMatcherPtr Handlers_; - bool OwnPoller_ = false; + IRequestPathMatcherPtr RequestPathMatcher_; + const bool OwnPoller_ = false; bool Started_ = false; - std::atomic<bool> Stopped_ = {false}; + std::atomic<bool> Stopped_ = false; - - std::atomic<ui64> ActiveConnections_{0}; + std::atomic<int> ActiveConnections_ = 0; TGauge ConnectionsActive_ = HttpProfiler.Gauge("/connections_active"); TCounter ConnectionsAccepted_ = HttpProfiler.Counter("/connections_accepted"); TCounter ConnectionsDropped_ = HttpProfiler.Counter("/connections_dropped"); @@ -157,7 +156,7 @@ private: auto connection = connectionOrError.ValueOrThrow(); auto count = ActiveConnections_.fetch_add(1) + 1; - if (count >= static_cast<ui64>(Config_->MaxSimultaneousConnections)) { + if (count >= Config_->MaxSimultaneousConnections) { ConnectionsDropped_.Increment(); ActiveConnections_--; YT_LOG_WARNING("Server is over max active connection limit (RemoteAddress: %v)", @@ -200,7 +199,7 @@ private: FindBalancerRealIP(request), FindUserAgent(request)); - auto handler = Handlers_->Match(path); + auto handler = RequestPathMatcher_->Match(path); if (handler) { closeResponse = false; @@ -255,7 +254,7 @@ private: void HandleConnection(const IConnectionPtr& connection, TGuid connectionId) { try { - connection->SubscribePeerDisconnect(BIND([config=Config_, canceler=GetCurrentFiberCanceler(), connectionId=connectionId] { + connection->SubscribePeerDisconnect(BIND([config = Config_, canceler = GetCurrentFiberCanceler(), connectionId = connectionId] { YT_LOG_DEBUG("Client closed TCP socket (ConnectionId: %v)", connectionId); if (config->CancelFiberOnConnectionClose) { @@ -381,7 +380,14 @@ IServerPtr CreateServer( bool ownPoller) { auto handlers = New<TRequestPathMatcher>(); - return New<TServer>(config, listener, poller, acceptor, invoker, handlers, ownPoller); + return New<TServer>( + config, + listener, + poller, + acceptor, + invoker, + handlers, + ownPoller); } IServerPtr CreateServer( @@ -416,7 +422,13 @@ IServerPtr CreateServer( const IListenerPtr& listener, const IPollerPtr& poller) { - return CreateServer(config, listener, poller, poller, poller->GetInvoker(), false); + return CreateServer( + config, + listener, + poller, + poller, + poller->GetInvoker(), + /*ownPoller*/ false); } IServerPtr CreateServer( @@ -425,17 +437,31 @@ IServerPtr CreateServer( const IPollerPtr& poller, const IPollerPtr& acceptor) { - return CreateServer(config, listener, poller, acceptor, poller->GetInvoker(), false); + return CreateServer( + config, + listener, + poller, + acceptor, + poller->GetInvoker(), + /*ownPoller*/ false); } IServerPtr CreateServer(const TServerConfigPtr& config, const IPollerPtr& poller, const IPollerPtr& acceptor) { - return CreateServer(config, poller, acceptor, poller->GetInvoker(), false); + return CreateServer( + config, + poller, + acceptor, + poller->GetInvoker(), + /*ownPoller*/ false); } IServerPtr CreateServer(const TServerConfigPtr& config, const IPollerPtr& poller) { - return CreateServer(config, poller, poller); + return CreateServer( + config, + poller, + poller); } IServerPtr CreateServer(int port, const IPollerPtr& poller) @@ -448,7 +474,12 @@ IServerPtr CreateServer(int port, const IPollerPtr& poller) IServerPtr CreateServer(const TServerConfigPtr& config, int pollerThreadCount) { auto poller = CreateThreadPoolPoller(pollerThreadCount, config->ServerName); - return CreateServer(config, poller, poller, poller->GetInvoker(), true); + return CreateServer( + config, + poller, + poller, + poller->GetInvoker(), + /*ownPoller*/ true); } IServerPtr CreateServer( @@ -456,7 +487,12 @@ IServerPtr CreateServer( const NConcurrency::IPollerPtr& poller, const IInvokerPtr& invoker) { - return CreateServer(config, poller, poller, invoker, false); + return CreateServer( + config, + poller, + poller, + invoker, + /*ownPoller*/ false); } //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/http/server.h b/yt/yt/core/http/server.h index 933c5359c08..a3341a576f8 100644 --- a/yt/yt/core/http/server.h +++ b/yt/yt/core/http/server.h @@ -24,7 +24,7 @@ public: void HandleRequest(const IRequestPtr& req, const IResponseWriterPtr& rsp) override; private: - TCallback<void(const IRequestPtr&, const IResponseWriterPtr&)> Handler_; + const TCallback<void(const IRequestPtr&, const IResponseWriterPtr&)> Handler_; }; //////////////////////////////////////////////////////////////////////////////// @@ -109,15 +109,13 @@ IServerPtr CreateServer( //////////////////////////////////////////////////////////////////////////////// //! IRequestPathMatcher is responsible for storing handlers and giving them back by path -class IRequestPathMatcher +struct IRequestPathMatcher : public virtual TRefCounted { -public: virtual void Add(const TString& pattern, const IHttpHandlerPtr& handler) = 0; virtual void Add(const TString& pattern, TCallback<void(const IRequestPtr&, const IResponseWriterPtr&)> handler) = 0; virtual IHttpHandlerPtr Match(TStringBuf path) = 0; virtual bool IsEmpty() const = 0; - }; DEFINE_REFCOUNTED_TYPE(IRequestPathMatcher) @@ -133,7 +131,6 @@ public: IHttpHandlerPtr Match(TStringBuf path) override; bool IsEmpty() const override; - private: THashMap<TString, IHttpHandlerPtr> Exact_; THashMap<TString, IHttpHandlerPtr> Subtrees_; |