From: myoungwon oh Date: Tue, 17 Nov 2020 09:11:24 +0000 (+0900) Subject: osd: move create_or_get_ref to refcount_manifest() X-Git-Tag: v16.1.0~374^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e03e05bf93303f361018f06910a87344fb2b862a;p=ceph.git osd: move create_or_get_ref to refcount_manifest() Signed-off-by: Myoungwon Oh --- diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 73b59d05a31f..a15af53c47c9 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -3224,6 +3224,28 @@ struct C_SetManifestRefCountDone : public Context { } }; +struct C_SetDedupChunks : public Context { + PrimaryLogPGRef pg; + hobject_t oid; + epoch_t last_peering_reset; + ceph_tid_t tid; + uint64_t offset; + + C_SetDedupChunks(PrimaryLogPG *p, hobject_t o, epoch_t lpr, uint64_t offset) + : pg(p), oid(o), last_peering_reset(lpr), + tid(0), offset(offset) + {} + void finish(int r) override { + if (r == -ECANCELED) + return; + std::scoped_lock locker{*pg}; + if (last_peering_reset != pg->get_last_peering_reset()) { + return; + } + pg->finish_set_dedup(oid, r, tid, offset); + } +}; + void PrimaryLogPG::cancel_manifest_ops(bool requeue, vector *tids) { dout(10) << __func__ << dendl; @@ -3265,7 +3287,7 @@ void PrimaryLogPG::dec_refcount(const hobject_t& soid, const object_ref_delta_t& while (dec_ref_count < 0) { dout(10) << __func__ << ": decrement reference on offset oid: " << p->first << dendl; refcount_manifest(soid, p->first, - refcount_t::DECREMENT_REF, NULL); + refcount_t::DECREMENT_REF, NULL, std::nullopt); dec_ref_count++; } } @@ -3326,14 +3348,14 @@ bool PrimaryLogPG::inc_refcount_by_set(OpContext* ctx, object_manifest_t& set_ch */ RefCountCallback *fin = new RefCountCallback(ctx, osd_op); refcount_manifest(ctx->obs->oi.soid, p->first, - refcount_t::INCREMENT_REF, fin); + refcount_t::INCREMENT_REF, fin, std::nullopt); return true; } else if (inc_ref_count < 0) { hobject_t src = ctx->obs->oi.soid; hobject_t tgt = p->first; ctx->register_on_commit( [src, tgt, this](){ - refcount_manifest(src, tgt, refcount_t::DECREMENT_REF, NULL); + refcount_manifest(src, tgt, refcount_t::DECREMENT_REF, NULL, std::nullopt); }); return false; } @@ -3398,38 +3420,51 @@ void PrimaryLogPG::dec_all_refcount_manifest(const object_info_t& oi, OpContext* ctx->register_on_commit( [oi, this](){ refcount_manifest(oi.soid, oi.manifest.redirect_target, - refcount_t::DECREMENT_REF, NULL); + refcount_t::DECREMENT_REF, NULL, std::nullopt); }); } } -void PrimaryLogPG::refcount_manifest(hobject_t src_soid, hobject_t tgt_soid, refcount_t type, - RefCountCallback* cb) +ceph_tid_t PrimaryLogPG::refcount_manifest(hobject_t src_soid, hobject_t tgt_soid, refcount_t type, + Context *cb, std::optional chunk) { unsigned flags = CEPH_OSD_FLAG_IGNORE_CACHE | CEPH_OSD_FLAG_IGNORE_OVERLAY | - CEPH_OSD_FLAG_RWORDERED; + CEPH_OSD_FLAG_RWORDERED; + + dout(10) << __func__ << " Start refcount from " << src_soid + << " to " << tgt_soid << dendl; - dout(10) << __func__ << " Start refcount from " << src_soid - << " to " << tgt_soid << dendl; - ObjectOperation obj_op; bufferlist in; - if (type == refcount_t::INCREMENT_REF) { + if (type == refcount_t::INCREMENT_REF) { cls_cas_chunk_get_ref_op call; call.source = src_soid.get_head(); - ::encode(call, in); + ::encode(call, in); obj_op.call("cas", "chunk_get_ref", in); - } else if (type == refcount_t::DECREMENT_REF) { + } else if (type == refcount_t::DECREMENT_REF) { cls_cas_chunk_put_ref_op call; call.source = src_soid.get_head(); - ::encode(call, in); + ::encode(call, in); obj_op.call("cas", "chunk_put_ref", in); - } - - Context *c = nullptr; + } else if (type == refcount_t::CREATE_OR_GET_REF) { + cls_cas_chunk_create_or_get_ref_op get_call; + get_call.source = src_soid.get_head(); + ceph_assert(chunk); + get_call.data = move(*chunk); + ::encode(get_call, in); + obj_op.call("cas", "chunk_create_or_get_ref", in); + } else { + ceph_assert(0 == "unrecognized type"); + } + + Context *c = nullptr, *fin = nullptr; if (cb) { - C_SetManifestRefCountDone *fin = - new C_SetManifestRefCountDone(cb, src_soid); + if (type == refcount_t::INCREMENT_REF || + type == refcount_t::DECREMENT_REF) { + fin = new C_SetManifestRefCountDone(static_cast(cb), src_soid); + } else if (type == refcount_t::CREATE_OR_GET_REF) { + fin = cb; + } c = new C_OnFinisher(fin, osd->get_objecter_finisher(get_pg_shard())); } @@ -3441,10 +3476,14 @@ void PrimaryLogPG::refcount_manifest(hobject_t src_soid, hobject_t tgt_soid, ref ceph::real_clock::from_ceph_timespec(src_obc->obs.oi.mtime), flags, c); if (cb) { - manifest_ops[src_soid] = std::make_shared(cb, tid); - src_obc->start_block(); + if (type == refcount_t::INCREMENT_REF || + type == refcount_t::DECREMENT_REF) { + manifest_ops[src_soid] = std::make_shared(static_cast(cb), tid); + src_obc->start_block(); + } } -} + return tid; +} void PrimaryLogPG::do_proxy_chunked_read(OpRequestRef op, ObjectContextRef obc, int op_index, uint64_t chunk_index, uint64_t req_offset, uint64_t req_length, @@ -6785,7 +6824,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector& ops) new SetManifestFinisher(osd_op)); RefCountCallback *fin = new RefCountCallback(ctx, osd_op); refcount_manifest(ctx->obc->obs.oi.soid, target, - refcount_t::INCREMENT_REF, fin); + refcount_t::INCREMENT_REF, fin, std::nullopt); result = -EINPROGRESS; } else { // finish @@ -9983,29 +10022,6 @@ struct C_Flush : public Context { } }; -struct C_SetDedupChunks : public Context { - PrimaryLogPGRef pg; - hobject_t oid; - epoch_t last_peering_reset; - ceph_tid_t tid; - uint64_t offset; - - C_SetDedupChunks(PrimaryLogPG *p, hobject_t o, epoch_t lpr, uint64_t offset) - : pg(p), oid(o), last_peering_reset(lpr), - tid(0), offset(offset) - {} - void finish(int r) override { - if (r == -ECANCELED) - return; - std::scoped_lock locker{*pg}; - if (last_peering_reset != pg->get_last_peering_reset()) { - return; - } - pg->finish_set_dedup(oid, r, tid, offset); - } -}; - - int PrimaryLogPG::start_dedup(OpRequestRef op, ObjectContextRef obc) { bufferlist bl; @@ -10060,29 +10076,14 @@ int PrimaryLogPG::start_dedup(OpRequestRef op, ObjectContextRef obc) if (refs.find(target) == refs.end()) { continue; } - // make a create_or_get_ref op - bufferlist t; - ObjectOperation obj_op; - cls_cas_chunk_create_or_get_ref_op get_call; - get_call.source = soid.get_head(); - get_call.data = chunks[p.first]; - ::encode(get_call, t); - obj_op.call("cas", "chunk_create_or_get_ref", t); - - // issue create_or_get_ref_op C_SetDedupChunks *fin = new C_SetDedupChunks(this, soid, get_last_peering_reset(), p.first); - object_locator_t oloc(target); - unsigned flags = CEPH_OSD_FLAG_IGNORE_CACHE | CEPH_OSD_FLAG_IGNORE_OVERLAY | - CEPH_OSD_FLAG_RWORDERED; - ceph_tid_t tid = osd->objecter->mutate( - target.oid, oloc, obj_op, SnapContext(), - ceph::real_clock::from_ceph_timespec(obc->obs.oi.mtime), - flags, new C_OnFinisher(fin, osd->get_objecter_finisher(get_pg_shard()))); - fin->tid = tid; - mop->tids[p.first] = tid; + ceph_tid_t tid = refcount_manifest(soid, target, refcount_t::CREATE_OR_GET_REF, + fin, move(chunks[p.first])); mop->chunks[target] = make_pair(p.first, p.second.length()); mop->num_chunks++; - dout(10) << __func__ << " oid: " << soid << " tid: " << tid + mop->tids[p.first] = tid; + fin->tid = tid; + dout(10) << __func__ << " oid: " << soid << " tid: " << tid << " target: " << target << " offset: " << p.first << " length: " << p.second.length() << dendl; } diff --git a/src/osd/PrimaryLogPG.h b/src/osd/PrimaryLogPG.h index a2191b3548fe..80b373b5b3a3 100644 --- a/src/osd/PrimaryLogPG.h +++ b/src/osd/PrimaryLogPG.h @@ -1489,6 +1489,7 @@ protected: enum class refcount_t { INCREMENT_REF, DECREMENT_REF, + CREATE_OR_GET_REF, }; void do_proxy_chunked_op(OpRequestRef op, const hobject_t& missing_oid, ObjectContextRef obc, bool write_ordered); @@ -1501,8 +1502,8 @@ protected: void finish_promote_manifest(int r, CopyResults *results, ObjectContextRef obc); void cancel_and_requeue_proxy_ops(hobject_t oid); void cancel_manifest_ops(bool requeue, vector *tids); - void refcount_manifest(hobject_t src_soid, hobject_t tgt_soid, refcount_t type, - RefCountCallback* cb); + ceph_tid_t refcount_manifest(hobject_t src_soid, hobject_t tgt_soid, refcount_t type, + Context *cb, std::optional chunk); void dec_all_refcount_manifest(const object_info_t& oi, OpContext* ctx); void dec_refcount(const hobject_t& soid, const object_ref_delta_t& refs); void dec_refcount_by_dirty(OpContext* ctx);