From 6b9c9f8c29c19ee4dfa5abc74dd78eb55927d172 Mon Sep 17 00:00:00 2001 From: Vadim Meleshuk Date: Tue, 12 Sep 2023 23:03:20 -0700 Subject: [PATCH] Rename some acceptor methods to reflect what they actually do Summary: Also factor out the state transition to Drained into a method. Reviewed By: HsiehYuho Differential Revision: D48693967 fbshipit-source-id: c888b637cb4b1200035f7c4929151b5c47280074 --- wangle/acceptor/Acceptor.cpp | 24 ++++++++++-------------- wangle/acceptor/Acceptor.h | 16 +++++++++++----- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/wangle/acceptor/Acceptor.cpp b/wangle/acceptor/Acceptor.cpp index 8a9bcb73f..fb52a5757 100644 --- a/wangle/acceptor/Acceptor.cpp +++ b/wangle/acceptor/Acceptor.cpp @@ -249,7 +249,7 @@ void Acceptor::setTLSTicketSecrets( } } -void Acceptor::drainAllConnections() { +void Acceptor::startDrainingAllConnections() { if (downstreamConnectionManager_) { downstreamConnectionManager_->initiateGracefulShutdown( gracefulShutdownTimeout_); @@ -507,7 +507,7 @@ void Acceptor::sslConnectionReady( connectionReady( std::move(sock), clientAddr, nextProtocol, secureTransportType, tinfo); if (state_ == State::kDraining) { - checkDrained(); + checkIfDrained(); } } @@ -515,7 +515,7 @@ void Acceptor::sslConnectionError(const folly::exception_wrapper&) { CHECK(numPendingSSLConns_ > 0); --numPendingSSLConns_; if (state_ == State::kDraining) { - checkDrained(); + checkIfDrained(); } } @@ -531,27 +531,27 @@ void Acceptor::acceptError(const std::exception& ex) noexcept { void Acceptor::acceptStopped() noexcept { VLOG(3) << "Acceptor " << this << " acceptStopped()"; // Drain the open client connections - drainAllConnections(); + startDrainingAllConnections(); // If we haven't yet finished draining, begin doing so by marking ourselves - // as in the draining state. We must be sure to hit checkDrained() here, as + // as in the draining state. We must be sure to hit checkIfDrained() here, as // if we're completely idle, we can should consider ourself drained // immediately (as there is no outstanding work to complete to cause us to // re-evaluate this). if (state_ != State::kDone) { state_ = State::kDraining; - checkDrained(); + checkIfDrained(); } } void Acceptor::onEmpty(const ConnectionManager&) { VLOG(3) << "Acceptor=" << this << " onEmpty()"; if (state_ == State::kDraining) { - checkDrained(); + checkIfDrained(); } } -void Acceptor::checkDrained() { +void Acceptor::checkIfDrained() { CHECK(state_ == State::kDraining); if (forceShutdownInProgress_ || !downstreamConnectionManager_ || (downstreamConnectionManager_->getNumConnections() != 0) || @@ -563,10 +563,7 @@ void Acceptor::checkDrained() { << base_; downstreamConnectionManager_.reset(); - - state_ = State::kDone; - - onConnectionsDrained(); + transitionToDrained(); } void Acceptor::drainConnections(double pctToDrain) { @@ -605,8 +602,7 @@ void Acceptor::dropAllConnections() { } CHECK(numPendingSSLConns_ == 0); - state_ = State::kDone; - onConnectionsDrained(); + transitionToDrained(); } void Acceptor::dropConnections(double pctToDrop) { diff --git a/wangle/acceptor/Acceptor.h b/wangle/acceptor/Acceptor.h index 1385331d7..90020a257 100644 --- a/wangle/acceptor/Acceptor.h +++ b/wangle/acceptor/Acceptor.h @@ -192,7 +192,7 @@ class Acceptor : public folly::AsyncServerSocket::AcceptCallback, } /** - * Time after drainAllConnections() or acceptStopped() during which + * Time after startDrainingAllConnections() or acceptStopped() during which * new requests on connections owned by the downstream * ConnectionManager will be processed normally. */ @@ -253,10 +253,11 @@ class Acceptor : public folly::AsyncServerSocket::AcceptCallback, TransportInfo& tinfo) noexcept; /** - * Drains all open connections of their outstanding transactions. When - * a connection's transaction count reaches zero, the connection closes. + * Starts draining all open connections of their outstanding transactions + * asynchronously. When a connection's transaction count reaches zero, the + * connection closes. */ - virtual void drainAllConnections(); + virtual void startDrainingAllConnections(); /** * Drain defined percentage of connections. @@ -539,6 +540,11 @@ class Acceptor : public folly::AsyncServerSocket::AcceptCallback, folly::AsyncTransport::UniquePtr transformTransport( folly::AsyncTransport::UniquePtr sock); + void transitionToDrained() { + state_ = State::kDone; + onConnectionsDrained(); + } + TLSTicketKeySeeds ticketSecrets_; std::shared_ptr fizzCertManager_{nullptr}; @@ -546,7 +552,7 @@ class Acceptor : public folly::AsyncServerSocket::AcceptCallback, Acceptor(Acceptor const&) = delete; Acceptor& operator=(Acceptor const&) = delete; - void checkDrained(); + void checkIfDrained(); State state_{State::kInit}; uint64_t numPendingSSLConns_{0};