From: Kefu Chai Date: Thu, 15 Apr 2021 03:28:35 +0000 (+0800) Subject: test/cls_cas: allow multi hobjects tracked by cls_cas X-Git-Tag: v17.1.0~2253^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=972bb2e1e6b51790782cb8269cb4acc046716323;p=ceph.git test/cls_cas: allow multi hobjects tracked by cls_cas 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 --- diff --git a/src/test/cls_cas/test_cls_cas.cc b/src/test/cls_cas/test_cls_cas.cc index e730f0d128a55..b011b4b8eec7c 100644 --- a/src/test/cls_cas/test_cls_cas.cc +++ b/src/test/cls_cas/test_cls_cas.cc @@ -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)