From: myoungwon oh Date: Mon, 18 Jan 2021 03:16:32 +0000 (+0900) Subject: src/test: fix to avoid fail notification when testing manifest refcount X-Git-Tag: v16.2.0~138^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=869dfe0becad071d8a78ef0640e53c7b858c3056;p=ceph.git src/test: fix to avoid fail notification when testing manifest refcount Due to false-positive design on manifest snap refcounting, a message to decrement the refcount can be missing. This commit checks whether the manifest object's state is correct when such mismatch happens to prevent aborting unit test. Signed-off-by: Myoungwon Oh (cherry-picked from commit d0369dc73ee9a911e39642f3b63c4d0f17b04ce3) --- diff --git a/src/test/librados/tier_cxx.cc b/src/test/librados/tier_cxx.cc index dcfea88785f..fbb01c60ca1 100644 --- a/src/test/librados/tier_cxx.cc +++ b/src/test/librados/tier_cxx.cc @@ -23,6 +23,9 @@ #include #include +#include "cls/cas/cls_cas_client.h" +#include "cls/cas/cls_cas_internal.h" + using namespace librados; using std::map; using std::ostringstream; @@ -155,6 +158,38 @@ string get_fp_oid(string oid, std::string fp_algo = NULL) return string(); } +void is_intended_refcount_state(librados::IoCtx& src_ioctx, + std::string src_oid, + librados::IoCtx& dst_ioctx, + std::string dst_oid, + int expected_refcount) +{ + int src_refcount = 0, dst_refcount = 0; + bufferlist t; + int r = dst_ioctx.getxattr(dst_oid, CHUNK_REFCOUNT_ATTR, t); + if (r == -ENOENT) { + dst_refcount = 0; + } else { + chunk_refs_t refs; + try { + auto iter = t.cbegin(); + decode(refs, iter); + } catch (buffer::error& err) { + ceph_assert(0); + } + dst_refcount = refs.count(); + } + r = cls_cas_references_chunk(src_ioctx, src_oid, dst_oid); + if (r == -ENOENT || r == -ENOLINK) { + src_refcount = 0; + } else { + src_refcount = r; + } + ASSERT_TRUE(src_refcount >= 0); + ASSERT_TRUE(src_refcount == expected_refcount); + ASSERT_TRUE(src_refcount <= dst_refcount); +} + class LibRadosTwoPoolsPP : public RadosTestPP { public: @@ -3613,15 +3648,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapRefcount) { sha1_gen.Update((const unsigned char *)"hi", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - chunk_refs_t refs; - try { - auto iter = t.cbegin(); - decode(refs, iter); - } catch (buffer::error& err) { - ASSERT_TRUE(0); - } - ASSERT_EQ(1u, refs.count()); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 1); } // check chunk's refcount @@ -3666,15 +3693,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapRefcount) { sha1_gen.Update((const unsigned char *)"hi", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - chunk_refs_t refs; - try { - auto iter = t.cbegin(); - decode(refs, iter); - } catch (buffer::error& err) { - ASSERT_TRUE(0); - } - ASSERT_EQ(1u, refs.count()); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 1); } // remove snap @@ -3697,15 +3716,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapRefcount) { sha1_gen.Update((const unsigned char *)"bb", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - chunk_refs_t refs; - try { - auto iter = t.cbegin(); - decode(refs, iter); - } catch (buffer::error& err) { - ASSERT_TRUE(0); - } - ASSERT_EQ(1u, refs.count()); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 1); } // remove snap @@ -3727,15 +3738,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapRefcount) { sha1_gen.Update((const unsigned char *)"bb", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - chunk_refs_t refs; - try { - auto iter = t.cbegin(); - decode(refs, iter); - } catch (buffer::error& err) { - ASSERT_TRUE(0); - } - ASSERT_EQ(1u, refs.count()); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 1); } // check chunk's refcount @@ -3748,15 +3751,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapRefcount) { sha1_gen.Update((const unsigned char *)"hi", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - chunk_refs_t refs; - try { - auto iter = t.cbegin(); - decode(refs, iter); - } catch (buffer::error& err) { - ASSERT_TRUE(0); - } - ASSERT_EQ(1u, refs.count()); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 1); } } @@ -3979,8 +3974,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapRefcount2) { sha1_gen.Update((const unsigned char *)"BB", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - int r = cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - ASSERT_EQ(-ENOENT, r); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 0); } } @@ -4310,8 +4304,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestCheckRefcountWhenModification) { sha1_gen.Update((const unsigned char *)"ai", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - int r = cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - ASSERT_EQ(-ENOENT, r); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 0); } // foo snap[0]: [er] [hi] [HI] @@ -4364,8 +4357,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestCheckRefcountWhenModification) { sha1_gen.Update((const unsigned char *)"Er", size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - int r = cache_ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t); - ASSERT_EQ(-ENOENT, r); + is_intended_refcount_state(ioctx, "foo", cache_ioctx, p_str, 0); } } @@ -4482,8 +4474,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapIncCount) { sleep(10); // check chunk's refcount - check_fp_oid_refcount(cache_ioctx, "chunk4", 1u, ""); - + is_intended_refcount_state(ioctx, "foo", cache_ioctx, "chunk4", 1); } TEST_F(LibRadosTwoPoolsPP, ManifestEvict) { @@ -5391,8 +5382,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestFlushDupCount) { sha1_gen.Update((const unsigned char *)chunk2.c_str(), size); sha1_gen.Final(fingerprint); buf_to_hex(fingerprint, CEPH_CRYPTO_SHA1_DIGESTSIZE, p_str); - tgt_oid = string(p_str); - ASSERT_EQ(-ENOENT, ioctx.getxattr(p_str, CHUNK_REFCOUNT_ATTR, t)); + is_intended_refcount_state(cache_ioctx, "foo", ioctx, p_str, 0); } } @@ -5470,8 +5460,6 @@ TEST_F(LibRadosTwoPoolsPP, TierFlushDuringFlush) { } -#include "cls/cas/cls_cas_client.h" -#include "cls/cas/cls_cas_internal.h" TEST_F(LibRadosTwoPoolsPP, ManifestSnapHasChunk) { // skip test if not yet octopus if (_get_required_osd_release(cluster) < "octopus") {