]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Throttle: fix wait/get() with new max
authorHenry Chang <henry@bigtera.com>
Wed, 22 Apr 2015 11:02:24 +0000 (19:02 +0800)
committerHenry Chang <henry@bigtera.com>
Thu, 23 Apr 2015 14:23:01 +0000 (22:23 +0800)
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 <henry@bigtera.com>
src/common/Throttle.cc
src/test/common/Throttle.cc

index 18a8bb1975b69a35dfaf0580db12f5537c6323c2..f0dd91d4db9e42fe01277909d6569127fa48a2bb 100644 (file)
@@ -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;
   }
 
index 0964cbeffaf6650f2c1383e3e36a48db5e5b68da..dc2d24886771b641f55703f2a6258dfa9f500714 100644 (file)
@@ -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;