proxygen
wangle::ConnectionManager::DrainHelper Class Reference
Inheritance diagram for wangle::ConnectionManager::DrainHelper:
folly::EventBase::LoopCallback folly::AsyncTimeout

Public Member Functions

 DrainHelper (ConnectionManager &manager)
 
ShutdownState getShutdownState ()
 
void setShutdownState (ShutdownState state)
 
void startDrainPartial (double pct, std::chrono::milliseconds idleGrace)
 
void startDrainAll (std::chrono::milliseconds idleGrace)
 
void runLoopCallback () noexceptoverride
 
void timeoutExpired () noexceptoverride
 
void drainConnections ()
 
void idleGracefulTimeoutExpired ()
 
void startDrain (std::chrono::milliseconds idleGrace)
 
ConnectionIterator drainStartIterator () const
 
- Public Member Functions inherited from folly::EventBase::LoopCallback
virtual ~LoopCallback ()=default
 
void cancelLoopCallback ()
 
bool isLoopCallbackScheduled () const
 
- Public Member Functions inherited from folly::AsyncTimeout
 AsyncTimeout (TimeoutManager *timeoutManager)
 
 AsyncTimeout (EventBase *eventBase)
 
 AsyncTimeout (TimeoutManager *timeoutManager, InternalEnum internal)
 
 AsyncTimeout (EventBase *eventBase, InternalEnum internal)
 
 AsyncTimeout ()
 
virtual ~AsyncTimeout ()
 
bool scheduleTimeout (uint32_t milliseconds)
 
bool scheduleTimeout (TimeoutManager::timeout_type timeout)
 
void cancelTimeout ()
 
bool isScheduled () const
 
void attachTimeoutManager (TimeoutManager *timeoutManager, InternalEnum internal=InternalEnum::NORMAL)
 
void attachEventBase (EventBase *eventBase, InternalEnum internal=InternalEnum::NORMAL)
 
void detachTimeoutManager ()
 
void detachEventBase ()
 
const TimeoutManagergetTimeoutManager ()
 
struct event * getEvent ()
 

Private Attributes

bool all_ {true}
 
double pct_ {1.0}
 
ConnectionManagermanager_
 
ShutdownState shutdownState_ {ShutdownState::NONE}
 

Additional Inherited Members

- Public Types inherited from folly::AsyncTimeout
typedef TimeoutManager::InternalEnum InternalEnum
 
- Static Public Member Functions inherited from folly::AsyncTimeout
template<typename TCallback >
static std::unique_ptr< AsyncTimeoutmake (TimeoutManager &manager, TCallback &&callback)
 
template<typename TCallback >
static std::unique_ptr< AsyncTimeoutschedule (TimeoutManager::timeout_type timeout, TimeoutManager &manager, TCallback &&callback)
 

Detailed Description

Definition at line 186 of file ConnectionManager.h.

Constructor & Destructor Documentation

wangle::ConnectionManager::DrainHelper::DrainHelper ( ConnectionManager manager)
inlineexplicit

Definition at line 190 of file ConnectionManager.h.

191  : folly::AsyncTimeout(manager.eventBase_),
192  manager_(manager) {}

Member Function Documentation

void wangle::ConnectionManager::DrainHelper::drainConnections ( )

Definition at line 184 of file ConnectionManager.cpp.

References wangle::ManagedConnection::fireCloseWhenIdle(), wangle::ManagedConnection::fireNotifyPendingShutdown(), g(), and wangle::ManagedConnection::isBusy().

184  {
185  DestructorGuard g(&manager_);
186  size_t numCleared = 0;
187  size_t numKept = 0;
188 
189  auto it = manager_.drainIterator_;
190 
193  while (it != manager_.conns_.end() && (numKept + numCleared) < 64) {
194  ManagedConnection& conn = *it++;
196  conn.fireNotifyPendingShutdown();
197  numKept++;
198  } else { // CLOSE_WHEN_IDLE
199  // Second time around: close idle sessions. If they aren't idle yet,
200  // have them close when they are idle
201  if (conn.isBusy()) {
202  numKept++;
203  } else {
204  numCleared++;
205  }
206  conn.fireCloseWhenIdle(!manager_.notifyPendingShutdown_);
207  }
208  }
209 
211  VLOG(2) << "Idle connections cleared: " << numCleared <<
212  ", busy conns kept: " << numKept;
213  } else {
214  VLOG(3) << this << " notified n=" << numKept;
215  }
217  if (it != manager_.conns_.end()) {
219  } else {
221  VLOG(3) << this << " finished notify_pending_shutdown";
223  if (!isScheduled()) {
224  // The idle grace timer already fired, start over immediately
228  }
229  } else {
231  }
232  }
233 }
ConnectionIterator drainStartIterator() const
folly::EventBase * eventBase_
ConnectionIterator drainIterator_
void runInLoop(LoopCallback *callback, bool thisIteration=false)
Definition: EventBase.cpp:520
g_t g(f_t)
folly::CountedIntrusiveList< ManagedConnection,&ManagedConnection::listHook_ > conns_
bool isScheduled() const
ConnectionIterator wangle::ConnectionManager::DrainHelper::drainStartIterator ( ) const
inline

Definition at line 225 of file ConnectionManager.h.

225  {
226  if (all_) {
227  return manager_.conns_.begin();
228  }
229  auto it = manager_.conns_.begin();
230  const auto conns_size = manager_.conns_.size();
231  const auto numToDrain =
232  std::max<size_t>(0, std::min<size_t>(conns_size, conns_size * pct_));
233  std::advance(it, conns_size - numToDrain);
234  return it;
235  }
folly::CountedIntrusiveList< ManagedConnection,&ManagedConnection::listHook_ > conns_
ShutdownState wangle::ConnectionManager::DrainHelper::getShutdownState ( )
inline

Definition at line 194 of file ConnectionManager.h.

References wangle::ConnectionManager::NONE.

194  {
195  // only cares about full shutdown state
196  if (!all_) {
197  return ShutdownState::NONE;
198  }
199  return shutdownState_;
200  }
void wangle::ConnectionManager::DrainHelper::idleGracefulTimeoutExpired ( )

Definition at line 236 of file ConnectionManager.cpp.

236  {
237  VLOG(2) << this << " idleGracefulTimeoutExpired";
238  if (shutdownState_ ==
243  } else {
244  VLOG(4) << this << " idleGracefulTimeoutExpired during "
245  "NOTIFY_PENDING_SHUTDOWN, ignoring";
246  }
247 }
ConnectionIterator drainStartIterator() const
ConnectionIterator drainIterator_
void wangle::ConnectionManager::DrainHelper::runLoopCallback ( )
inlineoverridevirtualnoexcept

Implements folly::EventBase::LoopCallback.

Definition at line 209 of file ConnectionManager.h.

References wangle::ConnectionManager::drainConnections().

209  {
210  VLOG(3) << "Draining more conns from loop callback";
212  }
void wangle::ConnectionManager::DrainHelper::setShutdownState ( ShutdownState  state)
inline

Definition at line 202 of file ConnectionManager.h.

202  {
204  }
state
Definition: http_parser.c:272
void wangle::ConnectionManager::DrainHelper::startDrain ( std::chrono::milliseconds  idleGrace)

Definition at line 168 of file ConnectionManager.cpp.

169  {
170  if (idleGrace.count() > 0) {
172  scheduleTimeout(idleGrace);
173  VLOG(3) << "Scheduling idle grace period of " << idleGrace.count() << "ms";
174  } else {
177  VLOG(3) << "proceeding directly to closing idle connections";
178  }
181 }
ConnectionIterator drainStartIterator() const
ConnectionIterator drainIterator_
bool scheduleTimeout(uint32_t milliseconds)
void wangle::ConnectionManager::DrainHelper::startDrainAll ( std::chrono::milliseconds  idleGrace)

Definition at line 157 of file ConnectionManager.cpp.

158  {
159  all_ = true;
160  pct_ = 1.0;
161  if (isScheduled()) {
162  // if we are in the middle of a partial, abort and convert to all
163  cancelTimeout();
164  }
165  startDrain(idleGrace);
166 }
void startDrain(std::chrono::milliseconds idleGrace)
bool isScheduled() const
void wangle::ConnectionManager::DrainHelper::startDrainPartial ( double  pct,
std::chrono::milliseconds  idleGrace 
)

Definition at line 150 of file ConnectionManager.cpp.

151  {
152  all_ = false;
153  pct_ = pct;
154  startDrain(idleGrace);
155 }
void startDrain(std::chrono::milliseconds idleGrace)
void wangle::ConnectionManager::DrainHelper::timeoutExpired ( )
inlineoverridevirtualnoexcept

timeoutExpired() is invoked when the timeout period has expired.

Implements folly::AsyncTimeout.

Definition at line 214 of file ConnectionManager.h.

References wangle::ConnectionManager::drainConnections(), and wangle::ConnectionManager::idleGracefulTimeoutExpired().

214  {
215  VLOG(3) << "Idle grace expired";
217  }

Member Data Documentation

bool wangle::ConnectionManager::DrainHelper::all_ {true}
private

Definition at line 238 of file ConnectionManager.h.

ConnectionManager& wangle::ConnectionManager::DrainHelper::manager_
private

Definition at line 240 of file ConnectionManager.h.

double wangle::ConnectionManager::DrainHelper::pct_ {1.0}
private

Definition at line 239 of file ConnectionManager.h.

ShutdownState wangle::ConnectionManager::DrainHelper::shutdownState_ {ShutdownState::NONE}
private

Definition at line 241 of file ConnectionManager.h.


The documentation for this class was generated from the following files: