]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Fixes issue with lru_clear() + add new test
authorSahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
Wed, 11 Jun 2014 13:37:45 +0000 (15:37 +0200)
committerSahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
Mon, 16 Jun 2014 13:54:53 +0000 (15:54 +0200)
The method lru_clear() must set attribute lru_num to zero
after lru_top, lru_bot and lru_mid are reseted. indeed, lru_num
is the total number of elements found in all of them.

Also the test insures the good behavior of the method
lru_adjust() - lru_touch() calls lru_adjust every time
to balance lru_top and lru_bot by the value of lru_midpoint.

Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
src/include/lru.h
src/test/common/test_lru.cc

index bb3c551ccbcc3c3d96e82008ee3adbdfd737cdab..7024042e1602701e60ea9ce5c11c0a02543c478c 100644 (file)
@@ -150,6 +150,7 @@ class LRU {
     lru_top.clear();
     lru_bot.clear();
     lru_pintail.clear();
+    lru_num = 0;
   }
 
   // insert at top of lru
index a3f92e2ea77445720454ce1086e040565000ca3f..7a0a1413cf1a3389df37fb8dac3b4ccaf9db96d8 100644 (file)
@@ -67,6 +67,28 @@ TEST(lru, InsertBot) {
   ASSERT_EQ(99, (static_cast<Item*>(lru.lru_expire()))->id);
 }
 
+TEST(lru, Adjust) {
+  LRU lru = LRU(10);
+
+  lru.lru_set_midpoint(.6); // 60% of 10 elements.
+  for (int i=0; i<100; i++) {
+    lru.lru_touch(new Item(i));
+  }
+  ASSERT_EQ(6, lru.lru_get_top());
+  ASSERT_EQ(94, lru.lru_get_bot());
+  ASSERT_EQ(100, lru.lru_get_size());
+
+  lru.lru_clear();
+
+  lru.lru_set_midpoint(1.2); // 120% of 10 elements.
+  for (int i=0; i<100; i++) {
+    lru.lru_touch(new Item(i));
+  }
+  ASSERT_EQ(12, lru.lru_get_top());
+  ASSERT_EQ(88, lru.lru_get_bot());
+  ASSERT_EQ(100, lru.lru_get_size());
+}
+
 
 /*
  * Local Variables: