]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd, test: return the number of references of chunked object
authormyoungwon oh <ohmyoungwon@gmail.com>
Fri, 8 Jan 2021 06:17:16 +0000 (15:17 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Thu, 21 Jan 2021 06:12:46 +0000 (15:12 +0900)
Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/cls/cas/cls_cas.cc
src/crimson/osd/objclass.cc
src/objclass/objclass.h
src/osd/PrimaryLogPG.cc
src/osd/PrimaryLogPG.h
src/osd/objclass.cc
src/test/librados/tier_cxx.cc

index e7b9bec7dcd58448dbf679bac7d40fd6121fc310..26aecd8943db2e20446ea0bcdbd6c7430442b8c4 100644 (file)
@@ -199,9 +199,9 @@ static int references_chunk(cls_method_context_t hctx,
   }
   CLS_LOG(10, "fp_oid: %s \n", fp_oid.c_str());
 
-  bool ret = cls_has_chunk(hctx, fp_oid);
+  int ret = cls_get_manifest_ref_count(hctx, fp_oid);
   if (ret) {
-    return 0;
+    return ret;
   }
   return -ENOLINK;
 }
index 0017a21b02aa753b4d86ee56a521540d398ba613..bc3284e26612603d49f4b1bc90e2b696f95bce82 100644 (file)
@@ -473,7 +473,7 @@ int cls_cxx_chunk_write_and_set(cls_method_context_t hctx,
   return 0;
 }
 
-bool cls_has_chunk(cls_method_context_t hctx, string fp_oid)
+int cls_get_manifest_ref_count(cls_method_context_t hctx, string fp_oid)
 {
   return 0;
 }
index b16e9e01a741efc10728552e82adcc306f39d988..403f3543291da5b3afefc6da2cbacdb9a096ca6b 100644 (file)
@@ -157,7 +157,7 @@ extern int cls_get_snapset_seq(cls_method_context_t hctx, uint64_t *snap_seq);
 int cls_cxx_chunk_write_and_set(cls_method_context_t hctx, int ofs, int len,
                    ceph::buffer::list *write_inbl, uint32_t op_flags, ceph::buffer::list *set_inbl,
                   int set_len);
-bool cls_has_chunk(cls_method_context_t hctx, std::string fp_oid);
+int cls_get_manifest_ref_count(cls_method_context_t hctx, std::string fp_oid);
 
 extern uint64_t cls_get_osd_min_alloc_size(cls_method_context_t hctx);
 extern uint64_t cls_get_pool_stripe_width(cls_method_context_t hctx);
index 4b065f9508168048378aa2895361525c772b3d2c..6cafd70ad9523a20a74feadb46026ec90413d8f2 100644 (file)
@@ -3328,32 +3328,44 @@ void PrimaryLogPG::cancel_manifest_ops(bool requeue, vector<ceph_tid_t> *tids)
   }
 }
 
-bool PrimaryLogPG::has_manifest_chunk(ObjectContextRef obc, std::string& fp_oid) 
+int PrimaryLogPG::get_manifest_ref_count(ObjectContextRef obc, std::string& fp_oid) 
 {
+  int cnt = 0;
   // head
   for (auto &p : obc->obs.oi.manifest.chunk_map) {
     if (p.second.oid.oid.name == fp_oid) {
-      return true;
+      cnt++;
     }
   }
   // snap
   SnapSet& ss = obc->ssc->snapset;
-  for (vector<snapid_t>::const_iterator p = ss.clones.begin();
-      p != ss.clones.end();
+  for (vector<snapid_t>::const_reverse_iterator p = ss.clones.rbegin();
+      p != ss.clones.rend();
       ++p) {
+    object_ref_delta_t refs;
+    ObjectContextRef obc_l = nullptr;
+    ObjectContextRef obc_g = nullptr;
     hobject_t clone_oid = obc->obs.oi.soid;
     clone_oid.snap = *p;
     ObjectContextRef clone_obc = get_object_context(clone_oid, false);
-    if (clone_obc && clone_obc->obs.oi.has_manifest()) {
-      for (auto &p : clone_obc->obs.oi.manifest.chunk_map) {
-       if (p.second.oid.oid.name == fp_oid) {
-         return true;
+    if (!clone_obc) {
+      break;
+    }
+    get_adjacent_clones(clone_obc, obc_l, obc_g);
+    clone_obc->obs.oi.manifest.calc_refs_to_inc_on_set(
+      obc_g ? &(obc_g->obs.oi.manifest) : nullptr ,
+      nullptr,
+      refs);
+    if (!refs.is_empty()) {
+      for (auto p = refs.begin(); p != refs.end(); ++p) {
+       if (p->first.oid.name == fp_oid && p->second > 0) {
+         cnt += p->second;
        }
       }
     }
   }
 
-  return false;
+  return cnt;
 }
 
 ObjectContextRef PrimaryLogPG::get_prev_clone_obc(ObjectContextRef obc)
index 189c61a4da966172c7f7f64b3dad6fdac5eb641a..134b3ba1a937a7a40b6bf7b8cd94fb118e8606a5 100644 (file)
@@ -1848,7 +1848,7 @@ public:
   void maybe_kick_recovery(const hobject_t &soid);
   void wait_for_unreadable_object(const hobject_t& oid, OpRequestRef op);
 
-  bool has_manifest_chunk(ObjectContextRef obc, std::string& fp_oid);
+  int get_manifest_ref_count(ObjectContextRef obc, std::string& fp_oid);
 
   bool check_laggy(OpRequestRef& op);
   bool check_laggy_requeue(OpRequestRef& op);
index 7507a55d1c90922529f2c6fc6236eb42b92ed6ac..6130ecce2256d2cb6db6c4f36e24cb48f863838a 100644 (file)
@@ -682,10 +682,10 @@ int cls_cxx_chunk_write_and_set(cls_method_context_t hctx, int ofs, int len,
   return (*pctx)->pg->do_osd_ops(*pctx, ops);
 }
 
-bool cls_has_chunk(cls_method_context_t hctx, string fp_oid)
+int cls_get_manifest_ref_count(cls_method_context_t hctx, string fp_oid)
 {
   PrimaryLogPG::OpContext *ctx = *(PrimaryLogPG::OpContext **)hctx;
-  return ctx->pg->has_manifest_chunk(ctx->obc, fp_oid);
+  return ctx->pg->get_manifest_ref_count(ctx->obc, fp_oid);
 }
 
 uint64_t cls_get_osd_min_alloc_size(cls_method_context_t hctx) {
index 78075887ebf64c50b05035e51045012b86e2af4c..dcfea88785f1dd2a5cfd19e1561a8bbe41e894cd 100644 (file)
@@ -5488,7 +5488,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapHasChunk) {
   // create object
   {
     bufferlist bl;
-    bl.append("there hiHI");
+    bl.append("there HIHI");
     ObjectWriteOperation op;
     op.write_full(bl);
     ASSERT_EQ(0, ioctx.operate("foo", &op));
@@ -5573,7 +5573,7 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapHasChunk) {
   }
 
   // set-chunk (dedup)
-  manifest_set_chunk(cluster, cache_ioctx, ioctx, 6, 2, hi_fp_oid, "foo");
+  manifest_set_chunk(cluster, cache_ioctx, ioctx, 6, 2, HI_fp_oid, "foo");
   // set-chunk (dedup)
   manifest_set_chunk(cluster, cache_ioctx, ioctx, 8, 2, HI_fp_oid, "foo");
 
@@ -5634,19 +5634,18 @@ TEST_F(LibRadosTwoPoolsPP, ManifestSnapHasChunk) {
     ASSERT_EQ(0, ioctx.write("foo", bl, 1, 6));
   }
 
-  // foo snap[1]:      [hi] [HI]
+  // foo snap[1]:      [HI] [HI]
   // foo snap[0]: [er] [ai] [SI]
   // foo head   : [er] [bi] [SI]
 
   // set-chunk (dedup)
   manifest_set_chunk(cluster, cache_ioctx, ioctx, 6, 2, bi_fp_oid, "foo");
 
-
   {
-    ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", SI_fp_oid));
-    ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", er_fp_oid));
-    ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", ai_fp_oid));
-    ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", HI_fp_oid));
+    ASSERT_EQ(1, cls_cas_references_chunk(ioctx, "foo", SI_fp_oid));
+    ASSERT_EQ(1, cls_cas_references_chunk(ioctx, "foo", er_fp_oid));
+    ASSERT_EQ(1, cls_cas_references_chunk(ioctx, "foo", ai_fp_oid));
+    ASSERT_EQ(2, cls_cas_references_chunk(ioctx, "foo", HI_fp_oid));
     ASSERT_EQ(-ENOLINK, cls_cas_references_chunk(ioctx, "foo", Hi_fp_oid));
   }
 }