]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test: fix wrong alarm
authormyoungwon oh <ohmyoungwon@gmail.com>
Fri, 30 Jul 2021 10:34:02 +0000 (19:34 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Fri, 30 Jul 2021 12:15:32 +0000 (21:15 +0900)
This is not a serious bug. Please look over the following scenario
in HitSetWrite test:

1. append object, which causes to add the object to the hitset
2. call hit_set_get to get the object accessed recently
3. see the hitset to check that appened object is in the hitset

After step 2, assert occurs because plpg_on_pool_change,
which invokes hit_set_clear, is called
between step 1 and step 2.
So, the object this unit test want to add to the hitset
is not in the hitset sometime.
To avoid this, this commit adds retry logic.

Fixes: https://tracker.ceph.com/issues/45423
Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/test/librados/tier_cxx.cc

index ff87975ad3c60b24608c0c075d879ef978ea169f..06c3f77dc430fbcdb4918ef11884c7197cda391f 100644 (file)
@@ -2653,56 +2653,31 @@ static int _get_pg_num(Rados& cluster, string pool_name)
   return -1;
 }
 
-TEST_F(LibRadosTwoPoolsPP, HitSetWrite) {
-  int num_pg = _get_pg_num(cluster, pool_name);
-  ceph_assert(num_pg > 0);
-
-  // make it a tier
-  bufferlist inbl;
-  ASSERT_EQ(0, cluster.mon_command(
-    "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
-    "\", \"tierpool\": \"" + cache_pool_name +
-    "\", \"force_nonempty\": \"--force-nonempty\" }",
-    inbl, NULL, NULL));
-
-  // enable hitset tracking for this pool
-  ASSERT_EQ(0, cluster.mon_command(set_pool_str(cache_pool_name, "hit_set_count", 8),
-                                               inbl, NULL, NULL));
-  ASSERT_EQ(0, cluster.mon_command(set_pool_str(cache_pool_name, "hit_set_period", 600),
-                                               inbl, NULL, NULL));
-  ASSERT_EQ(0, cluster.mon_command(set_pool_str(cache_pool_name, "hit_set_type",
-                                               "explicit_hash"),
-                                  inbl, NULL, NULL));
-
-  // wait for maps to settle
-  cluster.wait_for_latest_osdmap();
-
-  cache_ioctx.set_namespace("");
-
-  int num = 200;
-
+int make_hitset(Rados& cluster, librados::IoCtx& cache_ioctx, int num_pg, 
+    int num, std::map<int, HitSet>& hitsets, std::string& cache_pool_name) 
+{
+  int pg = num_pg;
   // do a bunch of writes
   for (int i=0; i<num; ++i) {
     bufferlist bl;
     bl.append("a");
-    ASSERT_EQ(0, cache_ioctx.write(stringify(i), bl, 1, 0));
+    ceph_assert(0 == cache_ioctx.write(stringify(i), bl, 1, 0));
   }
 
   // get HitSets
-  std::map<int,HitSet> hitsets;
-  for (int i=0; i<num_pg; ++i) {
+  for (int i=0; i<pg; ++i) {
     list< pair<time_t,time_t> > ls;
     AioCompletion *c = librados::Rados::aio_create_completion();
-    ASSERT_EQ(0, cache_ioctx.hit_set_list(i, c, &ls));
+    ceph_assert(0 == cache_ioctx.hit_set_list(i, c, &ls));
     c->wait_for_complete();
     c->release();
     std::cout << "pg " << i << " ls " << ls << std::endl;
-    ASSERT_FALSE(ls.empty());
+    ceph_assert(!ls.empty());
 
     // get the latest
     c = librados::Rados::aio_create_completion();
     bufferlist bl;
-    ASSERT_EQ(0, cache_ioctx.hit_set_get(i, c, ls.back().first, &bl));
+    ceph_assert(0 == cache_ioctx.hit_set_get(i, c, ls.back().first, &bl));
     c->wait_for_complete();
     c->release();
 
@@ -2718,9 +2693,45 @@ TEST_F(LibRadosTwoPoolsPP, HitSetWrite) {
     }
 
     // cope with racing splits by refreshing pg_num
-    if (i == num_pg - 1)
-      num_pg = _get_pg_num(cluster, cache_pool_name);
+    if (i == pg - 1)
+      pg = _get_pg_num(cluster, cache_pool_name);
   }
+  return pg;
+}
+
+TEST_F(LibRadosTwoPoolsPP, HitSetWrite) {
+  int num_pg = _get_pg_num(cluster, pool_name);
+  ceph_assert(num_pg > 0);
+
+  // make it a tier
+  bufferlist inbl;
+  ASSERT_EQ(0, cluster.mon_command(
+    "{\"prefix\": \"osd tier add\", \"pool\": \"" + pool_name +
+    "\", \"tierpool\": \"" + cache_pool_name +
+    "\", \"force_nonempty\": \"--force-nonempty\" }",
+    inbl, NULL, NULL));
+
+  // enable hitset tracking for this pool
+  ASSERT_EQ(0, cluster.mon_command(set_pool_str(cache_pool_name, "hit_set_count", 8),
+                                               inbl, NULL, NULL));
+  ASSERT_EQ(0, cluster.mon_command(set_pool_str(cache_pool_name, "hit_set_period", 600),
+                                               inbl, NULL, NULL));
+  ASSERT_EQ(0, cluster.mon_command(set_pool_str(cache_pool_name, "hit_set_type",
+                                               "explicit_hash"),
+                                  inbl, NULL, NULL));
+
+  // wait for maps to settle
+  cluster.wait_for_latest_osdmap();
+
+  cache_ioctx.set_namespace("");
+
+  int num = 200;
+
+  std::map<int,HitSet> hitsets;
+
+  num_pg = make_hitset(cluster, cache_ioctx, num_pg, num, hitsets, cache_pool_name);
+
+  int retry = 0;
 
   for (int i=0; i<num; ++i) {
     string n = stringify(i);
@@ -2736,6 +2747,12 @@ TEST_F(LibRadosTwoPoolsPP, HitSetWrite) {
        break;
       }
     }
+    if (!found && retry < 5) {
+      num_pg = make_hitset(cluster, cache_ioctx, num_pg, num, hitsets, cache_pool_name);
+      i--;
+      retry++;
+      continue;
+    }
     ASSERT_TRUE(found);
   }
 }