From c13d8835fc0fe24770f80f28f396ab2bbbf262c4 Mon Sep 17 00:00:00 2001 From: Dongsheng Yang Date: Tue, 13 Nov 2018 01:45:27 -0500 Subject: [PATCH] Throttle: complete all m_blockers when we set average or max to 0 When we change the average or max to 0, we need to complete all m_blockers first. Fixes: http://tracker.ceph.com/issues/36715 Signed-off-by: Dongsheng Yang --- src/common/Throttle.cc | 2 ++ src/common/Throttle.h | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/common/Throttle.cc b/src/common/Throttle.cc index f3a3bd02f9b8..d933a86f333d 100644 --- a/src/common/Throttle.cc +++ b/src/common/Throttle.cc @@ -793,6 +793,8 @@ void TokenBucketThrottle::add_tokens() { std::lock_guard lock(m_lock); // put tokens into bucket. m_throttle.put(tokens_this_tick()); + if (0 == m_avg || 0 == m_throttle.max) + tmp_blockers.swap(m_blockers); // check the m_blockers from head to tail, if blocker can get // enough tokens, let it go. while (!m_blockers.empty()) { diff --git a/src/common/Throttle.h b/src/common/Throttle.h index f24c1a03656b..adacb0a5cc36 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -422,9 +422,9 @@ public: template bool get(uint64_t c, T *handler, I *item, uint64_t flag) { - if (0 == m_avg) + if (0 == c) return false; - + bool wait = false; uint64_t got = 0; std::lock_guard lock(m_lock); @@ -432,6 +432,9 @@ public: // Keep the order of requests, add item after previous blocked requests. wait = true; } else { + if (0 == m_throttle.max || 0 == m_avg) + return false; + got = m_throttle.get(c); if (got < c) { // Not enough tokens, add a blocker for it. -- 2.47.3