proxygen
proxygen::HTTP2PriorityQueue::Node Class Reference
Inheritance diagram for proxygen::HTTP2PriorityQueue::Node:
folly::HHWheelTimer::Callback

Classes

struct  IdHash
 
struct  IdNodeEqual
 
struct  PendingNode
 

Public Types

using PendingList = std::deque< PendingNode >
 

Public Member Functions

 Node (HTTP2PriorityQueue &queue, Node *inParent, HTTPCodec::StreamID id, uint8_t weight, HTTPTransaction *txn)
 
 ~Node () override
 
void setPermanent ()
 
NodegetParent () const
 
HTTPCodec::StreamID getID () const
 
HTTPCodec::StreamID parentID () const
 
HTTPTransactiongetTransaction () const
 
void clearTransaction ()
 
NodeemplaceNode (std::unique_ptr< Node > node, bool exclusive)
 
void removeFromTree ()
 
void signalPendingEgress ()
 
void clearPendingEgress ()
 
uint16_t getWeight () const
 
void updateWeight (uint8_t weight)
 
Nodereparent (Node *newParent, bool exclusive)
 
bool isDescendantOf (Node *node) const
 
bool isEnqueued () const override
 
bool inEgressTree () const
 
double getRelativeWeight () const
 
double getRelativeEnqueuedWeight () const
 
bool iterate (const std::function< bool(HTTPCodec::StreamID, HTTPTransaction *, double)> &fn, const std::function< bool()> &stopFn, bool all)
 
bool visitBFS (double relativeParentWeight, const std::function< bool(HTTP2PriorityQueue &queue, HTTPCodec::StreamID, HTTPTransaction *, double)> &fn, bool all, PendingList &pendingNodes, bool enqueuedChildren)
 
void updateEnqueuedWeight (bool activeNodes)
 
void dropPriorityNodes ()
 
void convertVirtualNode (HTTPTransaction *txn)
 
uint64_t calculateDepth (bool includeVirtual=true) const override
 
void flattenSubtree ()
 
void flattenSubtreeDFS (Node *subtreeRoot)
 
- Public Member Functions inherited from folly::HHWheelTimer::Callback
 Callback ()=default
 
virtual ~Callback ()
 
virtual void callbackCanceled () noexcept
 
void cancelTimeout ()
 
bool isScheduled () const
 
std::chrono::milliseconds getTimeRemaining ()
 

Static Public Member Functions

static void addChildToNewSubtreeRoot (std::unique_ptr< Node > child, Node *subtreeRoot)
 

Static Public Attributes

static const uint16_t kDefaultWeight = 16
 

Private Member Functions

NodeaddChild (std::unique_ptr< Node > child)
 
void addChildren (std::list< std::unique_ptr< Node >> &&children)
 
std::unique_ptr< NodedetachChild (Node *node)
 
void addEnqueuedChild (HTTP2PriorityQueue::Node *node)
 
void removeEnqueuedChild (HTTP2PriorityQueue::Node *node)
 
void timeoutExpired () noexceptoverride
 
void refreshTimeout ()
 

Static Private Member Functions

static void propagatePendingEgressSignal (Node *node)
 
static void propagatePendingEgressClear (Node *node)
 

Private Attributes

HTTP2PriorityQueuequeue_
 
Nodeparent_ {nullptr}
 
HTTPCodec::StreamID id_ {0}
 
uint16_t weight_ {kDefaultWeight}
 
HTTPTransactiontxn_ {nullptr}
 
bool isPermanent_ {false}
 
bool enqueued_ {false}
 
uint64_t totalEnqueuedWeightCheck_ {0}
 
uint64_t totalEnqueuedWeight_ {0}
 
uint64_t totalChildWeight_ {0}
 
std::list< std::unique_ptr< Node > > children_
 
std::list< std::unique_ptr< Node > >::iterator self_
 
folly::IntrusiveListHook enqueuedHook_
 
folly::IntrusiveList< Node,&Node::enqueuedHook_enqueuedChildren_
 

Friends

bool operator== (const Node &lhs, const Node &rhs)
 
std::size_t hash_value (const Node &node)
 

Additional Inherited Members

- Protected Member Functions inherited from folly::HHWheelTimer::Callback
virtual std::chrono::steady_clock::time_point getCurTime ()
 

Detailed Description

Definition at line 196 of file HTTP2PriorityQueue.h.

Member Typedef Documentation

Constructor & Destructor Documentation

proxygen::HTTP2PriorityQueue::Node::Node ( HTTP2PriorityQueue queue,
HTTP2PriorityQueue::Node inParent,
HTTPCodec::StreamID  id,
uint8_t  weight,
HTTPTransaction txn 
)

Definition at line 21 of file HTTP2PriorityQueue.cpp.

References id_, proxygen::HTTP2PriorityQueue::nodes_, and queue_.

25  : queue_(queue),
26  parent_(inParent),
27  id_(id),
28  weight_(weight + 1),
29  txn_(txn) {
30  DCHECK(queue_.nodes_.find(id_,
31  IdHash(), IdNodeEqual()) == queue_.nodes_.end());
32  queue_.nodes_.insert(*this);
33 }
proxygen::HTTP2PriorityQueue::Node::~Node ( )
override

Definition at line 35 of file HTTP2PriorityQueue.cpp.

References proxygen::HTTP2PriorityQueue::numVirtualNodes_, queue_, and txn_.

35  {
36  if (!txn_) {
38  }
39 }

Member Function Documentation

HTTP2PriorityQueue::Node * proxygen::HTTP2PriorityQueue::Node::addChild ( std::unique_ptr< Node child)
private

Definition at line 91 of file HTTP2PriorityQueue.cpp.

References folly::HHWheelTimer::Callback::cancelTimeout(), children_, id_, folly::gen::move, self_, and totalChildWeight_.

Referenced by addChildren(), and emplaceNode().

92  {
93  CHECK_NE(id_, child->id_) << "Tried to create a loop in the tree";
94  child->parent_ = this;
95  totalChildWeight_ += child->weight_;
96  Node* raw = child.get();
97  raw->self_ = children_.insert(children_.end(), std::move(child));
98  cancelTimeout();
99  return raw;
100 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Node(HTTP2PriorityQueue &queue, Node *inParent, HTTPCodec::StreamID id, uint8_t weight, HTTPTransaction *txn)
std::list< std::unique_ptr< Node > > children_
void proxygen::HTTP2PriorityQueue::Node::addChildren ( std::list< std::unique_ptr< Node >> &&  children)
private

Definition at line 67 of file HTTP2PriorityQueue.cpp.

References addChild(), addEnqueuedChild(), child, inEgressTree(), folly::gen::move, propagatePendingEgressSignal(), folly::f14::swap(), totalEnqueuedWeight_, and uint64_t.

Referenced by removeFromTree().

67  {
68  list<unique_ptr<Node>> emptyChilden;
69  uint64_t totalEnqueuedWeight = 0;
70  for (auto& child: children) {
71  if (child->inEgressTree()) {
72  totalEnqueuedWeight += child->weight_;
73  child->parent_->removeEnqueuedChild(child.get());
74  CHECK(!child->enqueuedHook_.is_linked());
75  addEnqueuedChild(child.get());
76  } else {
77  CHECK(!child->enqueuedHook_.is_linked());
78  }
80  }
81  std::swap(children, emptyChilden);
82  if (totalEnqueuedWeight > 0) {
83  if (!inEgressTree()) {
85  }
86  totalEnqueuedWeight_ += totalEnqueuedWeight;
87  }
88 }
Node * addChild(std::unique_ptr< Node > child)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void addEnqueuedChild(HTTP2PriorityQueue::Node *node)
static void propagatePendingEgressSignal(Node *node)
folly::Function< void()> child
Definition: AtFork.cpp:35
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
void proxygen::HTTP2PriorityQueue::Node::addChildToNewSubtreeRoot ( std::unique_ptr< Node child,
Node subtreeRoot 
)
static

Definition at line 417 of file HTTP2PriorityQueue.cpp.

References children_, kDefaultWeight, folly::gen::move, and self_.

Referenced by flattenSubtree(), and flattenSubtreeDFS().

418  {
419  child->children_.clear();
420  child->parent_ = subtreeRoot;
421  child->weight_ = kDefaultWeight;
422  child->totalChildWeight_ = 0;
423  child->totalEnqueuedWeight_ = 0;
424 #ifndef NDEBUG
425  child->totalEnqueuedWeightCheck_ = 0;
426 #endif
427  Node* raw = child.get();
428  raw->self_ = subtreeRoot->children_.insert(subtreeRoot->children_.end(),
429  std::move(child));
430 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Node(HTTP2PriorityQueue &queue, Node *inParent, HTTPCodec::StreamID id, uint8_t weight, HTTPTransaction *txn)
void proxygen::HTTP2PriorityQueue::Node::addEnqueuedChild ( HTTP2PriorityQueue::Node node)
private

Definition at line 160 of file HTTP2PriorityQueue.cpp.

References enqueuedChildren_, and enqueuedHook_.

Referenced by addChildren(), and propagatePendingEgressSignal().

160  {
161  CHECK(!node->enqueuedHook_.is_linked());
162  enqueuedChildren_.push_back(*node);
163 }
folly::IntrusiveList< Node,&Node::enqueuedHook_ > enqueuedChildren_
uint64_t proxygen::HTTP2PriorityQueue::Node::calculateDepth ( bool  includeVirtual = true) const
override

Definition at line 365 of file HTTP2PriorityQueue.cpp.

References getParent(), txn_, and uint64_t.

Referenced by proxygen::HTTP2PriorityQueue::updatePriority().

365  {
366  uint64_t depth = 0;
367  const Node* cur = this;
368  while (cur->getParent() != nullptr) {
369  if (cur->txn_ || includeVirtual) {
370  depth += 1;
371  }
372  cur = cur->getParent();
373  }
374  return depth;
375 }
Node(HTTP2PriorityQueue &queue, Node *inParent, HTTPCodec::StreamID id, uint8_t weight, HTTPTransaction *txn)
void proxygen::HTTP2PriorityQueue::Node::clearPendingEgress ( )

Definition at line 195 of file HTTP2PriorityQueue.cpp.

References enqueued_, and propagatePendingEgressClear().

Referenced by proxygen::HTTP2PriorityQueue::removeTransaction().

195  {
196  CHECK(enqueued_);
197  enqueued_ = false;
199 }
static void propagatePendingEgressClear(Node *node)
void proxygen::HTTP2PriorityQueue::Node::clearTransaction ( )
inline
void proxygen::HTTP2PriorityQueue::Node::convertVirtualNode ( HTTPTransaction txn)
unique_ptr< HTTP2PriorityQueue::Node > proxygen::HTTP2PriorityQueue::Node::detachChild ( Node node)
private

Definition at line 103 of file HTTP2PriorityQueue.cpp.

References children_, isEnqueued(), isPermanent_, folly::gen::move, parent_, queue_, proxygen::HTTP2PriorityQueue::scheduleNodeExpiration(), self_, totalChildWeight_, txn_, and weight_.

Referenced by removeFromTree(), and reparent().

103  {
104  CHECK(!node->isEnqueued());
105  totalChildWeight_ -= node->weight_;
106  auto it = node->self_;
107  auto res = std::move(*node->self_);
108  children_.erase(it);
109  node->parent_ = nullptr;
110  if (children_.empty() && !txn_ && !isPermanent_) {
112  }
113  return res;
114 }
void scheduleNodeExpiration(Node *node)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::list< std::unique_ptr< Node > > children_
void proxygen::HTTP2PriorityQueue::Node::dropPriorityNodes ( )

Definition at line 344 of file HTTP2PriorityQueue.cpp.

References child, children_, isPermanent_, removeFromTree(), and txn_.

Referenced by proxygen::HTTP2PriorityQueue::detachThreadLocals().

344  {
345  for (auto it = children_.begin(); it != children_.end(); ) {
346  auto& child = *it++;
347  child->dropPriorityNodes();
348  }
349  if (!txn_ && !isPermanent_) {
350  removeFromTree();
351  }
352 }
folly::Function< void()> child
Definition: AtFork.cpp:35
std::list< std::unique_ptr< Node > > children_
HTTP2PriorityQueue::Node * proxygen::HTTP2PriorityQueue::Node::emplaceNode ( std::unique_ptr< Node node,
bool  exclusive 
)

Definition at line 43 of file HTTP2PriorityQueue.cpp.

References addChild(), children_, id_, inEgressTree(), folly::gen::move, propagatePendingEgressClear(), folly::f14::swap(), totalChildWeight_, totalEnqueuedWeight_, and totalEnqueuedWeightCheck_.

Referenced by reparent().

44  {
45  CHECK(!node->isEnqueued());
46  list<unique_ptr<Node>> children;
47  CHECK_NE(id_, node->id_) << "Tried to create a loop in the tree";
48  if (exclusive) {
49  // this->children become new node's children
50  std::swap(children, children_);
52  bool wasInEgressTree = inEgressTree();
54 #ifndef NDEBUG
56 #endif
57  if (wasInEgressTree && !inEgressTree()) {
59  }
60  }
61  auto res = addChild(std::move(node));
62  res->addChildren(std::move(children));
63  return res;
64 }
Node * addChild(std::unique_ptr< Node > child)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
static void propagatePendingEgressClear(Node *node)
std::list< std::unique_ptr< Node > > children_
void proxygen::HTTP2PriorityQueue::Node::flattenSubtree ( )

Definition at line 378 of file HTTP2PriorityQueue.cpp.

References addChildToNewSubtreeRoot(), child, children_, for_each(), folly::gen::move, folly::f14::swap(), totalChildWeight_, totalEnqueuedWeight_, and totalEnqueuedWeightCheck_.

Referenced by proxygen::HTTP2PriorityQueue::rebuildTree().

378  {
379  std::list<std::unique_ptr<Node>> oldChildren_;
380  // Move the old children to a temporary list
381  std::swap(oldChildren_, children_);
382  // Reparent the children
383  for (auto& child : oldChildren_) {
384  child->flattenSubtreeDFS(this);
386  }
387  // Update the weights
389 #ifndef NDEBUG
391 #endif
392  totalChildWeight_ = 0;
394  children_.begin(),
395  children_.end(),
396  [this](const std::unique_ptr<Node>& child) {
397  totalChildWeight_ += child->weight_;
398  if (child->enqueued_) {
399  totalEnqueuedWeight_ += child->weight_;
400 #ifndef NDEBUG
401  totalEnqueuedWeightCheck_ += child->weight_;
402 #endif
403  }
404  }
405  );
406 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static void addChildToNewSubtreeRoot(std::unique_ptr< Node > child, Node *subtreeRoot)
folly::Function< void()> child
Definition: AtFork.cpp:35
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
void for_each(T const &range, Function< void(typename T::value_type const &) const > const &func)
std::list< std::unique_ptr< Node > > children_
void proxygen::HTTP2PriorityQueue::Node::flattenSubtreeDFS ( Node subtreeRoot)

Definition at line 409 of file HTTP2PriorityQueue.cpp.

References addChildToNewSubtreeRoot(), child, children_, and folly::gen::move.

409  {
410  for (auto& child : children_) {
411  child->flattenSubtreeDFS(subtreeRoot);
413  }
414 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static void addChildToNewSubtreeRoot(std::unique_ptr< Node > child, Node *subtreeRoot)
folly::Function< void()> child
Definition: AtFork.cpp:35
std::list< std::unique_ptr< Node > > children_
Node* proxygen::HTTP2PriorityQueue::Node::getParent ( ) const
inline

Definition at line 237 of file HTTP2PriorityQueue.h.

Referenced by calculateDepth(), and proxygen::HTTP2PriorityQueue::updatePriority().

237  {
238  return parent_;
239  }
double proxygen::HTTP2PriorityQueue::Node::getRelativeEnqueuedWeight ( ) const
inline

Definition at line 301 of file HTTP2PriorityQueue.h.

Referenced by visitBFS().

301  {
302  if (!parent_) {
303  return 1.0;
304  }
305 
306  if (parent_->totalEnqueuedWeight_ == 0) {
307  return 0.0;
308  }
309 
310  return static_cast<double>(weight_) / parent_->totalEnqueuedWeight_;
311  }
double proxygen::HTTP2PriorityQueue::Node::getRelativeWeight ( ) const
inline

Definition at line 293 of file HTTP2PriorityQueue.h.

Referenced by iterate().

293  {
294  if (!parent_) {
295  return 1.0;
296  }
297 
298  return static_cast<double>(weight_) / parent_->totalChildWeight_;
299  }
HTTPTransaction* proxygen::HTTP2PriorityQueue::Node::getTransaction ( ) const
inline

Definition at line 252 of file HTTP2PriorityQueue.h.

252  {
253  return txn_;
254  }
uint16_t proxygen::HTTP2PriorityQueue::Node::getWeight ( ) const
inline

Definition at line 270 of file HTTP2PriorityQueue.h.

References uint8_t.

270  {
271  return weight_;
272  }
bool proxygen::HTTP2PriorityQueue::Node::inEgressTree ( ) const
inline
bool proxygen::HTTP2PriorityQueue::Node::isDescendantOf ( HTTP2PriorityQueue::Node node) const

Definition at line 145 of file HTTP2PriorityQueue.cpp.

References id_, and parent_.

Referenced by proxygen::HTTP2PriorityQueue::updatePriority().

145  {
146  Node* cur = parent_;
147  while (cur) {
148  if (cur->id_ == node->id_) {
149  return true;
150  }
151  cur = cur->parent_;
152  }
153  return false;
154 }
Node(HTTP2PriorityQueue &queue, Node *inParent, HTTPCodec::StreamID id, uint8_t weight, HTTPTransaction *txn)
bool proxygen::HTTP2PriorityQueue::Node::isEnqueued ( ) const
inlineoverride
bool proxygen::HTTP2PriorityQueue::Node::iterate ( const std::function< bool(HTTPCodec::StreamID, HTTPTransaction *, double)> &  fn,
const std::function< bool()> &  stopFn,
bool  all 
)

Definition at line 261 of file HTTP2PriorityQueue.cpp.

References child, children_, getRelativeWeight(), id_, isEnqueued(), parent_, stop(), totalEnqueuedWeight_, totalEnqueuedWeightCheck_, and txn_.

264  {
265  bool stop = false;
266  if (stopFn()) {
267  return true;
268  }
269 #ifndef NDEBUG
271 #endif
272  if (parent_ /* exclude root */ && (all || isEnqueued())) {
273  stop = fn(id_, txn_, getRelativeWeight());
274  }
275  for (auto& child: children_) {
276  if (stop || stopFn()) {
277  return true;
278  }
279  stop = child->iterate(fn, stopFn, all);
280  }
281  return stop;
282 }
static void stop()
folly::Function< void()> child
Definition: AtFork.cpp:35
std::list< std::unique_ptr< Node > > children_
Composed all(Predicate pred=Predicate())
Definition: Base.h:786
HTTPCodec::StreamID proxygen::HTTP2PriorityQueue::Node::parentID ( ) const
inline

Definition at line 245 of file HTTP2PriorityQueue.h.

Referenced by proxygen::HTTP2PriorityQueue::updatePriority().

245  {
246  if (parent_) {
247  return parent_->id_;
248  }
249  return 0;
250  }
void proxygen::HTTP2PriorityQueue::Node::propagatePendingEgressClear ( HTTP2PriorityQueue::Node node)
staticprivate

Definition at line 202 of file HTTP2PriorityQueue.cpp.

References inEgressTree(), parent, parent_, removeEnqueuedChild(), stop(), totalEnqueuedWeight_, and weight_.

Referenced by clearPendingEgress(), emplaceNode(), removeFromTree(), and reparent().

203  {
204  Node* parent = node->parent_;
205  bool stop = node->inEgressTree();
206  // Continue subtracting node->weight_ from parent_->totalEnqueuedWeight_
207  // as long as node state changes from egress-in-subtree to
208  // no-egress-in-subtree
209  while (parent && !stop) {
210  CHECK_GE(parent->totalEnqueuedWeight_, node->weight_);
211  parent->totalEnqueuedWeight_ -= node->weight_;
212  parent->removeEnqueuedChild(node);
213  stop = parent->inEgressTree();
214  node = parent;
215  parent = parent->parent_;
216  }
217 }
static void stop()
Node(HTTP2PriorityQueue &queue, Node *inParent, HTTPCodec::StreamID id, uint8_t weight, HTTPTransaction *txn)
folly::Function< void()> parent
Definition: AtFork.cpp:34
void proxygen::HTTP2PriorityQueue::Node::propagatePendingEgressSignal ( HTTP2PriorityQueue::Node node)
staticprivate

Definition at line 178 of file HTTP2PriorityQueue.cpp.

References addEnqueuedChild(), inEgressTree(), parent, parent_, stop(), totalEnqueuedWeight_, and weight_.

Referenced by addChildren(), reparent(), and signalPendingEgress().

179  {
180  Node* parent = node->parent_;
181  bool stop = node->totalEnqueuedWeight_ > 0;
182  // Continue adding node->weight_ to parent_->totalEnqueuedWeight_ as
183  // long as node state changed from no-egress-in-subtree to
184  // egress-in-subtree
185  while (parent && !stop) {
186  stop = parent->inEgressTree();
187  parent->totalEnqueuedWeight_ += node->weight_;
188  parent->addEnqueuedChild(node);
189  node = parent;
190  parent = parent->parent_;
191  }
192 }
static void stop()
Node(HTTP2PriorityQueue &queue, Node *inParent, HTTPCodec::StreamID id, uint8_t weight, HTTPTransaction *txn)
folly::Function< void()> parent
Definition: AtFork.cpp:34
void proxygen::HTTP2PriorityQueue::Node::refreshTimeout ( )
inlineprivate

Definition at line 380 of file HTTP2PriorityQueue.h.

Referenced by updateWeight().

void proxygen::HTTP2PriorityQueue::Node::removeEnqueuedChild ( HTTP2PriorityQueue::Node node)
private

Definition at line 166 of file HTTP2PriorityQueue.cpp.

References enqueuedChildren_, and enqueuedHook_.

Referenced by propagatePendingEgressClear().

166  {
167  CHECK(node->enqueuedHook_.is_linked());
168  enqueuedChildren_.erase(enqueuedChildren_.iterator_to(*node));
169 }
folly::IntrusiveList< Node,&Node::enqueuedHook_ > enqueuedChildren_
void proxygen::HTTP2PriorityQueue::Node::removeFromTree ( )

Definition at line 233 of file HTTP2PriorityQueue.cpp.

References addChildren(), child, children_, detachChild(), inEgressTree(), isEnqueued(), max, folly::gen::move, parent_, propagatePendingEgressClear(), totalChildWeight_, totalEnqueuedWeight_, uint64_t, uint8_t, and weight_.

Referenced by dropPriorityNodes(), and proxygen::HTTP2PriorityQueue::removeTransaction().

233  {
234  if (!children_.empty()) {
235  // update child weights so they sum to (approximately) this node's weight.
236  double r = double(weight_) / totalChildWeight_;
237  for (auto& child: children_) {
238  uint64_t newWeight = std::max(uint64_t(child->weight_ * r), uint64_t(1));
239  CHECK_LE(newWeight, 256);
240  child->updateWeight(uint8_t(newWeight) - 1);
241  }
242  }
243 
244  CHECK(!isEnqueued());
245  if (inEgressTree()) {
246  // Gah this is tricky.
247  // The children of this node are moving to this node's parent. We need the
248  // tree in a consistent state before calling addChildren, so mark the
249  // current node's totalEnqueuedWeight_ as 0 and propagate the clear upwards.
250  // addChildren will handle re-signalling egress.
253  }
254 
255  // move my children to my parent
256  parent_->addChildren(std::move(children_));
257  (void)parent_->detachChild(this);
258 }
LogLevel max
Definition: LogLevel.cpp:31
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void addChildren(std::list< std::unique_ptr< Node >> &&children)
std::unique_ptr< Node > detachChild(Node *node)
folly::Function< void()> child
Definition: AtFork.cpp:35
static void propagatePendingEgressClear(Node *node)
std::list< std::unique_ptr< Node > > children_
HTTP2PriorityQueue::Node * proxygen::HTTP2PriorityQueue::Node::reparent ( HTTP2PriorityQueue::Node newParent,
bool  exclusive 
)

Definition at line 117 of file HTTP2PriorityQueue.cpp.

References detachChild(), emplaceNode(), enqueued_, inEgressTree(), folly::gen::move, parent_, propagatePendingEgressClear(), propagatePendingEgressSignal(), totalEnqueuedWeight_, and uint64_t.

Referenced by proxygen::HTTP2PriorityQueue::updatePriority().

118  {
119  // Save enqueued_ and totalEnqueuedWeight_, clear them and restore
120  // after reparenting
121  bool wasInEgressTree = inEgressTree();
122  bool enqueued = enqueued_;
123  uint64_t totalEnqueuedWeight = totalEnqueuedWeight_;
125  enqueued_ = false;
126  if (wasInEgressTree) {
128  }
129 
130  auto self = parent_->detachChild(this);
131  (void)newParent->emplaceNode(std::move(self), exclusive);
132 
133  // Restore state
134  enqueued_ = enqueued;
135  if (wasInEgressTree) {
137  }
138  totalEnqueuedWeight_ += totalEnqueuedWeight;
139 
140  return this;
141 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< Node > detachChild(Node *node)
static void propagatePendingEgressSignal(Node *node)
static void propagatePendingEgressClear(Node *node)
void proxygen::HTTP2PriorityQueue::Node::setPermanent ( )
inline

Definition at line 233 of file HTTP2PriorityQueue.h.

233  {
234  isPermanent_ = true;
235  }
void proxygen::HTTP2PriorityQueue::Node::signalPendingEgress ( )

Definition at line 172 of file HTTP2PriorityQueue.cpp.

References enqueued_, and propagatePendingEgressSignal().

172  {
173  enqueued_ = true;
175 }
static void propagatePendingEgressSignal(Node *node)
void proxygen::HTTP2PriorityQueue::Node::timeoutExpired ( )
inlineoverrideprivatevirtualnoexcept

timeoutExpired() is invoked when the timeout has expired.

Implements folly::HHWheelTimer::Callback.

Definition at line 373 of file HTTP2PriorityQueue.h.

373  {
374  VLOG(5) << "Node=" << id_ << " expired";
375  CHECK(txn_ == nullptr);
377  removeFromTree();
378  }
void proxygen::HTTP2PriorityQueue::Node::updateEnqueuedWeight ( bool  activeNodes)

Definition at line 325 of file HTTP2PriorityQueue.cpp.

References child, children_, enqueuedHook_, isEnqueued(), parent_, totalChildWeight_, totalEnqueuedWeightCheck_, and weight_.

Referenced by proxygen::HTTP2PriorityQueue::iterateBFS(), proxygen::HTTP2PriorityQueue::nextEgress(), and proxygen::HTTP2PriorityQueue::updateEnqueuedWeight().

325  {
327  for (auto& child: children_) {
328  child->updateEnqueuedWeight(activeNodes);
329  }
330  if (activeNodes) {
331  if (totalEnqueuedWeightCheck_ == 0 && !isEnqueued()) {
332  // Must only be called with activeCount_ > 0, root cannot be dequeued
333  CHECK_NOTNULL(parent_)->totalEnqueuedWeightCheck_ -= weight_;
334  } else {
335  CHECK(parent_ == nullptr || enqueuedHook_.is_linked());
336  }
337  } else {
339  }
340 }
folly::IntrusiveListHook enqueuedHook_
folly::Function< void()> child
Definition: AtFork.cpp:35
std::list< std::unique_ptr< Node > > children_
void proxygen::HTTP2PriorityQueue::Node::updateWeight ( uint8_t  weight)
bool proxygen::HTTP2PriorityQueue::Node::visitBFS ( double  relativeParentWeight,
const std::function< bool(HTTP2PriorityQueue &queue, HTTPCodec::StreamID, HTTPTransaction *, double)> &  fn,
bool  all,
PendingList pendingNodes,
bool  enqueuedChildren 
)

Definition at line 285 of file HTTP2PriorityQueue.cpp.

References child, children_, enqueuedChildren_, getRelativeEnqueuedWeight(), id_, folly::pushmi::invoke, isEnqueued(), parent_, queue_, totalEnqueuedWeight_, totalEnqueuedWeightCheck_, and txn_.

Referenced by proxygen::HTTP2PriorityQueue::iterateBFS(), and proxygen::HTTP2PriorityQueue::nextEgress().

290  {
291  bool invoke = (parent_ != nullptr && (all || isEnqueued()));
292  auto relativeEnqueuedWeight = getRelativeEnqueuedWeight();
293 
294 #ifndef NDEBUG
296 #endif
297  // Add children when all==true, or for any not invoked node with
298  // pending children
299  if (all || (!invoke && totalEnqueuedWeight_ > 0)) {
300  double newRelWeight = relativeParentWeight * relativeEnqueuedWeight;
301  if (enqueuedChildren) {
302  for (auto child = enqueuedChildren_.begin();
303  child != enqueuedChildren_.end();
304  child++) {
305  pendingNodes.emplace_back(child->id_, &(*child), newRelWeight);
306  }
307  } else {
308  for (auto& child: children_) {
309  pendingNodes.emplace_back(child->id_, child.get(), newRelWeight);
310  }
311  }
312  }
313 
314  // Invoke fn last in case it deletes this node
315  if (invoke && fn(queue_, id_, txn_,
316  relativeParentWeight * relativeEnqueuedWeight)) {
317  return true;
318  }
319 
320  return false;
321 }
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::invoke_fn invoke
folly::IntrusiveList< Node,&Node::enqueuedHook_ > enqueuedChildren_
folly::Function< void()> child
Definition: AtFork.cpp:35
std::list< std::unique_ptr< Node > > children_
Composed all(Predicate pred=Predicate())
Definition: Base.h:786

Friends And Related Function Documentation

std::size_t hash_value ( const Node node)
friend

Definition at line 229 of file HTTP2PriorityQueue.h.

229  {
230  return IdHash()(node.id_);
231  }
bool operator== ( const Node lhs,
const Node rhs 
)
friend

Definition at line 226 of file HTTP2PriorityQueue.h.

226  {
227  return lhs.id_ == rhs.id_;
228  }
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649

Member Data Documentation

std::list<std::unique_ptr<Node> > proxygen::HTTP2PriorityQueue::Node::children_
private
bool proxygen::HTTP2PriorityQueue::Node::enqueued_ {false}
private

Definition at line 392 of file HTTP2PriorityQueue.h.

Referenced by clearPendingEgress(), reparent(), and signalPendingEgress().

folly::IntrusiveList<Node, &Node::enqueuedHook_> proxygen::HTTP2PriorityQueue::Node::enqueuedChildren_
private

Definition at line 404 of file HTTP2PriorityQueue.h.

Referenced by addEnqueuedChild(), removeEnqueuedChild(), and visitBFS().

folly::IntrusiveListHook proxygen::HTTP2PriorityQueue::Node::enqueuedHook_
private
HTTPCodec::StreamID proxygen::HTTP2PriorityQueue::Node::id_ {0}
private
bool proxygen::HTTP2PriorityQueue::Node::isPermanent_ {false}
private

Definition at line 391 of file HTTP2PriorityQueue.h.

Referenced by convertVirtualNode(), detachChild(), and dropPriorityNodes().

const uint16_t proxygen::HTTP2PriorityQueue::Node::kDefaultWeight = 16
static

Definition at line 201 of file HTTP2PriorityQueue.h.

Referenced by addChildToNewSubtreeRoot().

HTTP2PriorityQueue& proxygen::HTTP2PriorityQueue::Node::queue_
private

Definition at line 386 of file HTTP2PriorityQueue.h.

Referenced by convertVirtualNode(), detachChild(), Node(), visitBFS(), and ~Node().

std::list<std::unique_ptr<Node> >::iterator proxygen::HTTP2PriorityQueue::Node::self_
private

Definition at line 399 of file HTTP2PriorityQueue.h.

Referenced by addChild(), addChildToNewSubtreeRoot(), and detachChild().

uint64_t proxygen::HTTP2PriorityQueue::Node::totalChildWeight_ {0}
private
uint64_t proxygen::HTTP2PriorityQueue::Node::totalEnqueuedWeight_ {0}
private
uint64_t proxygen::HTTP2PriorityQueue::Node::totalEnqueuedWeightCheck_ {0}
private
HTTPTransaction* proxygen::HTTP2PriorityQueue::Node::txn_ {nullptr}
private
uint16_t proxygen::HTTP2PriorityQueue::Node::weight_ {kDefaultWeight}
private

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