From: myoungwon oh Date: Sat, 20 Jun 2020 06:04:46 +0000 (+0900) Subject: cls/cas: replace bool get() with void get() X-Git-Tag: v16.1.0~1738^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=befe27ae2d57dcb138aa7086d9fe345688f10a04;p=ceph.git cls/cas: replace bool get() with void get() Since we allow multiple hoject_t to store in refs_t due to supporting snapshot, bool is not necessary. Signed-off-by: Myoungwon Oh --- diff --git a/src/cls/cas/cls_cas.cc b/src/cls/cas/cls_cas.cc index 0df07bcf5616..e7b9bec7dcd5 100644 --- a/src/cls/cas/cls_cas.cc +++ b/src/cls/cas/cls_cas.cc @@ -107,15 +107,7 @@ static int chunk_create_or_get_ref(cls_method_context_t hctx, CLS_LOG(10, "inc ref oid=%s\n", op.source.oid.name.c_str()); - if (!objr.get(op.source)) { - // we could perhaps return -EEXIST here, but instead we will - // behave in an idempotent fashion, since we know that it is possible - // for references to be leaked. If A has a ref, tries to drop it and - // fails (leaks), and then later tries to take it again, we should - // simply succeed if we know we already have it. This will serve to - // silently correct the mistake. - return 0; - } + objr.get(op.source); ret = chunk_set_refcount(hctx, objr); if (ret < 0) { @@ -148,15 +140,7 @@ static int chunk_get_ref(cls_method_context_t hctx, // existing chunk; inc ref CLS_LOG(10, "oid=%s\n", op.source.oid.name.c_str()); - if (!objr.get(op.source)) { - // we could perhaps return -EEXIST here, but instead we will - // behave in an idempotent fashion, since we know that it is possible - // for references to be leaked. If A has a ref, tries to drop it and - // fails (leaks), and then later tries to take it again, we should - // simply succeed if we know we already have it. This will serve to - // silently correct the mistake. - return 0; - } + objr.get(op.source); ret = chunk_set_refcount(hctx, objr); if (ret < 0) { diff --git a/src/cls/cas/cls_cas_internal.h b/src/cls/cas/cls_cas_internal.h index 1fdb94926659..14d3119a9d24 100644 --- a/src/cls/cas/cls_cas_internal.h +++ b/src/cls/cas/cls_cas_internal.h @@ -39,7 +39,7 @@ struct chunk_refs_t { virtual uint8_t get_type() const = 0; virtual bool empty() const = 0; virtual uint64_t count() const = 0; - virtual bool get(const hobject_t& o) = 0; + virtual void get(const hobject_t& o) = 0; virtual bool put(const hobject_t& o) = 0; virtual void dump(Formatter *f) const = 0; virtual std::string describe_encoding() const { @@ -72,8 +72,8 @@ struct chunk_refs_t { return r->count(); } - bool get(const hobject_t& o) { - return r->get(o); + void get(const hobject_t& o) { + r->get(o); } bool put(const hobject_t& o) { bool ret = r->put(o); @@ -115,9 +115,8 @@ struct chunk_refs_by_object_t : public chunk_refs_t::refs_t { uint64_t count() const override { return by_object.size(); } - bool get(const hobject_t& o) override { + void get(const hobject_t& o) override { by_object.insert(o); - return true; } bool put(const hobject_t& o) override { auto p = by_object.find(o); @@ -196,10 +195,9 @@ struct chunk_refs_by_hash_t : public chunk_refs_t::refs_t { uint64_t count() const override { return total; } - bool get(const hobject_t& o) override { + void get(const hobject_t& o) override { by_hash[make_pair(o.pool, o.get_hash() & mask())]++; ++total; - return true; } bool put(const hobject_t& o) override { auto p = by_hash.find(make_pair(o.pool, o.get_hash() & mask())); @@ -286,10 +284,9 @@ struct chunk_refs_by_pool_t : public chunk_refs_t::refs_t { uint64_t count() const override { return total; } - bool get(const hobject_t& o) override { + void get(const hobject_t& o) override { ++by_pool[o.pool]; ++total; - return true; } bool put(const hobject_t& o) override { auto p = by_pool.find(o.pool); @@ -364,9 +361,8 @@ struct chunk_refs_count_t : public chunk_refs_t::refs_t { uint64_t count() const override { return total; } - bool get(const hobject_t& o) override { + void get(const hobject_t& o) override { ++total; - return true; } bool put(const hobject_t& o) override { if (!total) { diff --git a/src/test/cls_cas/test_cls_cas.cc b/src/test/cls_cas/test_cls_cas.cc index 870b573fb06f..01db8a32be6a 100644 --- a/src/test/cls_cas/test_cls_cas.cc +++ b/src/test/cls_cas/test_cls_cas.cc @@ -310,8 +310,7 @@ TEST(chunk_refs_t, size) for (size_t i = 1; i <= max; ++i) { hobject_t h(sobject_t(object_t("foo"s + stringify(i)), i)); h.pool = i > pool_cutoff ? i : (i & pool_mask); - bool ret = r.get(h); - ASSERT_TRUE(ret); + r.get(h); if (count_bits(i) <= 2) { bufferlist bl; r.dynamic_encode(bl, 512);