Skip to content

Commit

Permalink
Rename some acceptor methods to reflect what they actually do
Browse files Browse the repository at this point in the history
Summary: Also factor out the state transition to Drained into a method.

Reviewed By: HsiehYuho

Differential Revision: D48693967

fbshipit-source-id: c888b637cb4b1200035f7c4929151b5c47280074
  • Loading branch information
meleshuk authored and facebook-github-bot committed Sep 13, 2023
1 parent 02d6666 commit 6b9c9f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
24 changes: 10 additions & 14 deletions wangle/acceptor/Acceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void Acceptor::setTLSTicketSecrets(
}
}

void Acceptor::drainAllConnections() {
void Acceptor::startDrainingAllConnections() {
if (downstreamConnectionManager_) {
downstreamConnectionManager_->initiateGracefulShutdown(
gracefulShutdownTimeout_);
Expand Down Expand Up @@ -507,15 +507,15 @@ void Acceptor::sslConnectionReady(
connectionReady(
std::move(sock), clientAddr, nextProtocol, secureTransportType, tinfo);
if (state_ == State::kDraining) {
checkDrained();
checkIfDrained();
}
}

void Acceptor::sslConnectionError(const folly::exception_wrapper&) {
CHECK(numPendingSSLConns_ > 0);
--numPendingSSLConns_;
if (state_ == State::kDraining) {
checkDrained();
checkIfDrained();
}
}

Expand All @@ -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) ||
Expand All @@ -563,10 +563,7 @@ void Acceptor::checkDrained() {
<< base_;

downstreamConnectionManager_.reset();

state_ = State::kDone;

onConnectionsDrained();
transitionToDrained();
}

void Acceptor::drainConnections(double pctToDrain) {
Expand Down Expand Up @@ -605,8 +602,7 @@ void Acceptor::dropAllConnections() {
}
CHECK(numPendingSSLConns_ == 0);

state_ = State::kDone;
onConnectionsDrained();
transitionToDrained();
}

void Acceptor::dropConnections(double pctToDrop) {
Expand Down
16 changes: 11 additions & 5 deletions wangle/acceptor/Acceptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -539,14 +540,19 @@ 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<fizz::server::CertManager> fizzCertManager_{nullptr};

// Forbidden copy constructor and assignment opererator
Acceptor(Acceptor const&) = delete;
Acceptor& operator=(Acceptor const&) = delete;

void checkDrained();
void checkIfDrained();

State state_{State::kInit};
uint64_t numPendingSSLConns_{0};
Expand Down

0 comments on commit 6b9c9f8

Please sign in to comment.