From: Radosław Zarzyński Date: Tue, 28 Nov 2023 13:55:58 +0000 (+0100) Subject: osd: shuffle UnstableHashInfoRegistry to ECCommon X-Git-Tag: v19.3.0~13^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=09db3b9410bc41070a0ff9d849c0504029ca0993;p=ceph.git osd: shuffle UnstableHashInfoRegistry to ECCommon Signed-off-by: Radosław Zarzyński --- diff --git a/src/osd/ECBackend.cc b/src/osd/ECBackend.cc index 4a537766d0b5..472acdf88487 100644 --- a/src/osd/ECBackend.cc +++ b/src/osd/ECBackend.cc @@ -1408,54 +1408,6 @@ void ECBackend::submit_transaction( rmw_pipeline.start_rmw(std::move(op)); } -ECUtil::HashInfoRef ECBackend::UnstableHashInfoRegistry::maybe_put_hash_info( - const hobject_t &hoid, - ECUtil::HashInfo &&hinfo) -{ - return registry.lookup_or_create(hoid, hinfo); -} - -ECUtil::HashInfoRef ECBackend::UnstableHashInfoRegistry::get_hash_info( - const hobject_t &hoid, - bool create, - const map>& attrs, - uint64_t size) -{ - dout(10) << __func__ << ": Getting attr on " << hoid << dendl; - ECUtil::HashInfoRef ref = registry.lookup(hoid); - if (!ref) { - dout(10) << __func__ << ": not in cache " << hoid << dendl; - ECUtil::HashInfo hinfo(ec_impl->get_chunk_count()); - bufferlist bl; - map::const_iterator k = attrs.find(ECUtil::get_hinfo_key()); - if (k == attrs.end()) { - dout(5) << __func__ << " " << hoid << " missing hinfo attr" << dendl; - } else { - bl = k->second; - } - if (bl.length() > 0) { - auto bp = bl.cbegin(); - try { - decode(hinfo, bp); - } catch(...) { - dout(0) << __func__ << ": Can't decode hinfo for " << hoid << dendl; - return ECUtil::HashInfoRef(); - } - if (hinfo.get_total_chunk_size() != size) { - dout(0) << __func__ << ": Mismatch of total_chunk_size " - << hinfo.get_total_chunk_size() << dendl; - return ECUtil::HashInfoRef(); - } - } else if (size == 0) { // If empty object and no hinfo, create it - create = true; - } - if (create) { - ref = registry.lookup_or_create(hoid, hinfo); - } - } - return ref; -} - int ECBackend::objects_read_sync( const hobject_t &hoid, uint64_t off, diff --git a/src/osd/ECBackend.h b/src/osd/ECBackend.h index 745ad4546b68..1f10269947a4 100644 --- a/src/osd/ECBackend.h +++ b/src/osd/ECBackend.h @@ -324,29 +324,7 @@ public: const ECUtil::stripe_info_t sinfo; - class UnstableHashInfoRegistry { - CephContext *cct; - ceph::ErasureCodeInterfaceRef ec_impl; - /// If modified, ensure that the ref is held until the update is applied - SharedPtrRegistry registry; - - public: - UnstableHashInfoRegistry( - CephContext *cct, - ceph::ErasureCodeInterfaceRef ec_impl) - : cct(cct), - ec_impl(std::move(ec_impl)) {} - - ECUtil::HashInfoRef maybe_put_hash_info( - const hobject_t &hoid, - ECUtil::HashInfo &&hinfo); - - ECUtil::HashInfoRef get_hash_info( - const hobject_t &hoid, - bool create, - const std::map>& attr, - uint64_t size); - } unstable_hashinfo_registry; + ECCommon::UnstableHashInfoRegistry unstable_hashinfo_registry; int object_stat(const hobject_t &hoid, struct stat* st); diff --git a/src/osd/ECCommon.cc b/src/osd/ECCommon.cc index e1bbfce7796c..2c6534d081f1 100644 --- a/src/osd/ECCommon.cc +++ b/src/osd/ECCommon.cc @@ -58,6 +58,11 @@ static ostream& _prefix(std::ostream *_dout, ECCommon::RMWPipeline *rmw_pipeline static ostream& _prefix(std::ostream *_dout, ECCommon::ReadPipeline *read_pipeline) { return read_pipeline->get_parent()->gen_dbg_prefix(*_dout); } +static ostream& _prefix(std::ostream *_dout, + ECCommon::UnstableHashInfoRegistry *unstable_hash_info_registry) { + // TODO: backref to ECListener? + return *_dout; +} ostream &operator<<(ostream &lhs, const ECCommon::RMWPipeline::pipeline_state_t &rhs) { switch (rhs.pipeline_state) { @@ -1074,3 +1079,51 @@ void ECCommon::RMWPipeline::call_write_ordered(std::function &&cb) { cb(); } } + +ECUtil::HashInfoRef ECCommon::UnstableHashInfoRegistry::maybe_put_hash_info( + const hobject_t &hoid, + ECUtil::HashInfo &&hinfo) +{ + return registry.lookup_or_create(hoid, hinfo); +} + +ECUtil::HashInfoRef ECCommon::UnstableHashInfoRegistry::get_hash_info( + const hobject_t &hoid, + bool create, + const map>& attrs, + uint64_t size) +{ + dout(10) << __func__ << ": Getting attr on " << hoid << dendl; + ECUtil::HashInfoRef ref = registry.lookup(hoid); + if (!ref) { + dout(10) << __func__ << ": not in cache " << hoid << dendl; + ECUtil::HashInfo hinfo(ec_impl->get_chunk_count()); + bufferlist bl; + map::const_iterator k = attrs.find(ECUtil::get_hinfo_key()); + if (k == attrs.end()) { + dout(5) << __func__ << " " << hoid << " missing hinfo attr" << dendl; + } else { + bl = k->second; + } + if (bl.length() > 0) { + auto bp = bl.cbegin(); + try { + decode(hinfo, bp); + } catch(...) { + dout(0) << __func__ << ": Can't decode hinfo for " << hoid << dendl; + return ECUtil::HashInfoRef(); + } + if (hinfo.get_total_chunk_size() != size) { + dout(0) << __func__ << ": Mismatch of total_chunk_size " + << hinfo.get_total_chunk_size() << dendl; + return ECUtil::HashInfoRef(); + } + } else if (size == 0) { // If empty object and no hinfo, create it + create = true; + } + if (create) { + ref = registry.lookup_or_create(hoid, hinfo); + } + } + return ref; +} diff --git a/src/osd/ECCommon.h b/src/osd/ECCommon.h index 46f8bb14772b..83e1712b0438 100644 --- a/src/osd/ECCommon.h +++ b/src/osd/ECCommon.h @@ -17,6 +17,7 @@ #include #include +#include "common/sharedptr_registry.hpp" #include "erasure-code/ErasureCodeInterface.h" #include "ECUtil.h" #if WITH_SEASTAR @@ -581,6 +582,30 @@ struct ECCommon { ec_backend(ec_backend) { } }; + + class UnstableHashInfoRegistry { + CephContext *cct; + ceph::ErasureCodeInterfaceRef ec_impl; + /// If modified, ensure that the ref is held until the update is applied + SharedPtrRegistry registry; + + public: + UnstableHashInfoRegistry( + CephContext *cct, + ceph::ErasureCodeInterfaceRef ec_impl) + : cct(cct), + ec_impl(std::move(ec_impl)) {} + + ECUtil::HashInfoRef maybe_put_hash_info( + const hobject_t &hoid, + ECUtil::HashInfo &&hinfo); + + ECUtil::HashInfoRef get_hash_info( + const hobject_t &hoid, + bool create, + const std::map>& attr, + uint64_t size); + }; }; std::ostream &operator<<(std::ostream &lhs,