]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/cls_cas: allow multi hobjects tracked by cls_cas 40867/head
authorKefu Chai <kchai@redhat.com>
Thu, 15 Apr 2021 03:28:35 +0000 (11:28 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 15 Apr 2021 03:36:43 +0000 (11:36 +0800)
in d2737fd41a146e8efe3162cdc39845226bd5a756, we started to use multiset
for tracking the references of hobject for snapshot support. as the same
hobject maps to multiple snapshots. and we don't want to consider
different snapshots as the same entry tracked by cls_cas.

but cls_cas.dup_get() still tries to verify that the `get` operation
is able to dedup the same referenced "source". but this does not apply
to "by_object" trunk ref type anymore.

since we cannot check/choose the chunk ref type used by OSD from the
client of the cls_cas, in this change, cls_cas.dup_get() is updated
to adapt the change solely for "by_object". otherwise we could skip
this test for "by_object" type and/or define another test for other
chunk ref types.

Fixes: https://tracker.ceph.com/issues/50339
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/cls_cas/test_cls_cas.cc

index e730f0d128a55c0919471a855d0868ffefb0c2e0..b011b4b8eec7c4717edb1754a6fc9f6be8060cde 100644 (file)
@@ -172,32 +172,46 @@ TEST_F(cls_cas, dup_get)
   bufferlist t;
   ASSERT_EQ(-ENOENT, ioctx.read(oid, t, 0, 0));
 
+  // duplicated entries are allowed by "by_object". as it tracks refs of the same
+  // hobject_t for snapshot support.
+  int n_refs = 0;
   // write
   {
     auto op = new_op();
     cls_cas_chunk_create_or_get_ref(*op, ref1, bl);
     ASSERT_EQ(0, ioctx.operate(oid, op));
+    n_refs++;
   }
   ASSERT_EQ(bl.length(), ioctx.read(oid, t, 0, 0));
 
-  // dup create_or_get_ref, get_ref will succeed but take no additional ref.
+  // dup create_or_get_ref, get_ref will succeed but take no additional ref
+  // only if the chunk_refs' type is not "by_object"
   {
     auto op = new_op();
     cls_cas_chunk_create_or_get_ref(*op, ref1, bl);
     ASSERT_EQ(0, ioctx.operate(oid, op));
+    n_refs++;
   }
   {
     auto op = new_op();
     cls_cas_chunk_get_ref(*op, ref1);
     ASSERT_EQ(0, ioctx.operate(oid, op));
+    n_refs++;
   }
 
-  {
+  for (int i = 0; i < n_refs; i++) {
     auto op = new_op();
     cls_cas_chunk_put_ref(*op, ref1);
     ASSERT_EQ(0, ioctx.operate(oid, op));
+    if (i < n_refs - 1) {
+      // should not referenced anymore, but by_object is an exception
+      // and by_object is used by default.
+      ASSERT_EQ(bl.length(), ioctx.read(oid, t, 0, 0));
+    } else {
+      // the last reference was removed
+      ASSERT_EQ(-ENOENT, ioctx.read(oid, t, 0, 0));
+    }
   }
-  ASSERT_EQ(-ENOENT, ioctx.read(oid, t, 0, 0));
 }
 
 TEST_F(cls_cas, dup_put)