From 09db3b9410bc41070a0ff9d849c0504029ca0993 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rados=C5=82aw=20Zarzy=C5=84ski?= Date: Tue, 28 Nov 2023 14:55:58 +0100 Subject: [PATCH] osd: shuffle UnstableHashInfoRegistry to ECCommon MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Radosław Zarzyński --- src/osd/ECBackend.cc | 48 --------------------------------------- src/osd/ECBackend.h | 24 +------------------- src/osd/ECCommon.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++ src/osd/ECCommon.h | 25 +++++++++++++++++++++ 4 files changed, 79 insertions(+), 71 deletions(-) diff --git a/src/osd/ECBackend.cc b/src/osd/ECBackend.cc index 4a537766d0b..472acdf8848 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 745ad4546b6..1f10269947a 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 e1bbfce7796..2c6534d081f 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 46f8bb14772..83e1712b043 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, -- 2.39.5