From: Henry Chang Date: Wed, 22 Apr 2015 11:02:24 +0000 (+0800) Subject: Throttle: fix wait/get() with new max X-Git-Tag: v9.0.1~81^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d7de5858ca5208604f072eef947ef913d52c883e;p=ceph.git Throttle: fix wait/get() with new max We were unable to set a new non-zero max if the original max was 0. Fix it. Also, add test cases for it. Signed-off-by: Henry Chang --- diff --git a/src/common/Throttle.cc b/src/common/Throttle.cc index 18a8bb1975b6..f0dd91d4db9e 100644 --- a/src/common/Throttle.cc +++ b/src/common/Throttle.cc @@ -124,7 +124,7 @@ bool Throttle::_wait(int64_t c) bool Throttle::wait(int64_t m) { - if (0 == max.read()) { + if (0 == max.read() && 0 == m) { return false; } @@ -158,7 +158,7 @@ int64_t Throttle::take(int64_t c) bool Throttle::get(int64_t c, int64_t m) { - if (0 == max.read()) { + if (0 == max.read() && 0 == m) { return false; } diff --git a/src/test/common/Throttle.cc b/src/test/common/Throttle.cc index 0964cbeffaf6..dc2d24886771 100644 --- a/src/test/common/Throttle.cc +++ b/src/test/common/Throttle.cc @@ -74,7 +74,15 @@ TEST_F(ThrottleTest, take) { TEST_F(ThrottleTest, get) { int64_t throttle_max = 10; - Throttle throttle(g_ceph_context, "throttle", throttle_max); + Throttle throttle(g_ceph_context, "throttle"); + + // test increasing max from 0 to throttle_max + { + ASSERT_FALSE(throttle.get(throttle_max, throttle_max)); + ASSERT_EQ(throttle.get_max(), throttle_max); + ASSERT_EQ(throttle.put(throttle_max), 0); + } + ASSERT_THROW(throttle.get(-1), FailedAssertion); ASSERT_FALSE(throttle.get(5)); ASSERT_EQ(throttle.put(5), 0); @@ -161,7 +169,13 @@ TEST_F(ThrottleTest, get_or_fail) { TEST_F(ThrottleTest, wait) { int64_t throttle_max = 10; - Throttle throttle(g_ceph_context, "throttle", throttle_max); + Throttle throttle(g_ceph_context, "throttle"); + + // test increasing max from 0 to throttle_max + { + ASSERT_FALSE(throttle.wait(throttle_max)); + ASSERT_EQ(throttle.get_max(), throttle_max); + } useconds_t delay = 1;