From: Xuehan Xu Date: Tue, 20 Apr 2021 07:45:43 +0000 (+0800) Subject: crimson/os: change get/set attrs value to the bufferlist type X-Git-Tag: v17.1.0~2072^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2dcb836e2db12354bf746e58639cdee2b4b653d8;p=ceph.git crimson/os: change get/set attrs value to the bufferlist type Signed-off-by: Xuehan Xu --- diff --git a/src/crimson/os/alienstore/alien_store.cc b/src/crimson/os/alienstore/alien_store.cc index 6b1c5bd5efa2..213750346f55 100644 --- a/src/crimson/os/alienstore/alien_store.cc +++ b/src/crimson/os/alienstore/alien_store.cc @@ -270,24 +270,24 @@ AlienStore::readv(CollectionRef ch, }); } -AlienStore::get_attr_errorator::future +AlienStore::get_attr_errorator::future AlienStore::get_attr(CollectionRef ch, const ghobject_t& oid, std::string_view name) const { logger().debug("{}", __func__); - return seastar::do_with(ceph::bufferptr{}, [=] (auto &value) { + return seastar::do_with(ceph::bufferlist{}, [=] (auto &value) { return tp->submit(ch->get_cid().hash_to_shard(tp->size()), [=, &value] { auto c =static_cast(ch.get()); return store->getattr(c->collection, oid, static_cast(name).c_str(), value); - }).then([oid, &value] (int r) -> get_attr_errorator::future { + }).then([oid, &value] (int r) -> get_attr_errorator::future { if (r == -ENOENT) { return crimson::ct_error::enoent::make(); } else if (r == -ENODATA) { return crimson::ct_error::enodata::make(); } else { - return get_attr_errorator::make_ready_future( + return get_attr_errorator::make_ready_future( std::move(value)); } }); diff --git a/src/crimson/os/alienstore/alien_store.h b/src/crimson/os/alienstore/alien_store.h index bc5376e0f6cd..4c5669e39ca7 100644 --- a/src/crimson/os/alienstore/alien_store.h +++ b/src/crimson/os/alienstore/alien_store.h @@ -59,7 +59,7 @@ public: uint32_t op_flags = 0) final; - get_attr_errorator::future get_attr(CollectionRef c, + get_attr_errorator::future get_attr(CollectionRef c, const ghobject_t& oid, std::string_view name) const final; get_attrs_ertr::future get_attrs(CollectionRef c, diff --git a/src/crimson/os/cyanstore/cyan_object.h b/src/crimson/os/cyanstore/cyan_object.h index f19b8721280f..624f9513a930 100644 --- a/src/crimson/os/cyanstore/cyan_object.h +++ b/src/crimson/os/cyanstore/cyan_object.h @@ -21,7 +21,7 @@ struct Object : public boost::intrusive_ref_counter< bufferlist data; // use transparent comparator for better performance, see // https://en.cppreference.com/w/cpp/utility/functional/less_void - std::map> xattr; + std::map> xattr; bufferlist omap_header; std::map omap; diff --git a/src/crimson/os/cyanstore/cyan_store.cc b/src/crimson/os/cyanstore/cyan_store.cc index e0be221ee594..330baab9db4c 100644 --- a/src/crimson/os/cyanstore/cyan_store.cc +++ b/src/crimson/os/cyanstore/cyan_store.cc @@ -220,7 +220,7 @@ CyanStore::read_errorator::future CyanStore::readv( } -CyanStore::get_attr_errorator::future CyanStore::get_attr( +CyanStore::get_attr_errorator::future CyanStore::get_attr( CollectionRef ch, const ghobject_t& oid, std::string_view name) const @@ -233,7 +233,7 @@ CyanStore::get_attr_errorator::future CyanStore::get_attr( return crimson::ct_error::enoent::make(); } if (auto found = o->xattr.find(name); found != o->xattr.end()) { - return get_attr_errorator::make_ready_future(found->second); + return get_attr_errorator::make_ready_future(found->second); } else { return crimson::ct_error::enodata::make(); } @@ -375,8 +375,8 @@ seastar::future<> CyanStore::do_transaction(CollectionRef ch, std::string name = i.decode_string(); ceph::bufferlist bl; i.decode_bl(bl); - std::map to_set; - to_set[name] = bufferptr(bl.c_str(), bl.length()); + std::map to_set; + to_set.emplace(name, std::move(bl)); r = _setattrs(cid, oid, to_set); } break; @@ -659,7 +659,7 @@ int CyanStore::_truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size } int CyanStore::_setattrs(const coll_t& cid, const ghobject_t& oid, - std::map& aset) + std::map& aset) { logger().debug("{} cid={} oid={}", __func__, cid, oid); @@ -670,7 +670,7 @@ int CyanStore::_setattrs(const coll_t& cid, const ghobject_t& oid, ObjectRef o = c->get_object(oid); if (!o) return -ENOENT; - for (std::map::const_iterator p = aset.begin(); + for (std::map::const_iterator p = aset.begin(); p != aset.end(); ++p) o->xattr[p->first] = p->second; return 0; diff --git a/src/crimson/os/cyanstore/cyan_store.h b/src/crimson/os/cyanstore/cyan_store.h index 6d802152dc44..85349b287149 100644 --- a/src/crimson/os/cyanstore/cyan_store.h +++ b/src/crimson/os/cyanstore/cyan_store.h @@ -89,7 +89,7 @@ public: interval_set& m, uint32_t op_flags = 0) final; - get_attr_errorator::future get_attr( + get_attr_errorator::future get_attr( CollectionRef c, const ghobject_t& oid, std::string_view name) const final; @@ -172,7 +172,7 @@ private: const std::string &last); int _truncate(const coll_t& cid, const ghobject_t& oid, uint64_t size); int _setattrs(const coll_t& cid, const ghobject_t& oid, - std::map& aset); + std::map& aset); int _rm_attr(const coll_t& cid, const ghobject_t& oid, string_view name); int _create_collection(const coll_t& cid, int bits); diff --git a/src/crimson/os/futurized_store.h b/src/crimson/os/futurized_store.h index d7d9c6f133ab..3cbc46fac74e 100644 --- a/src/crimson/os/futurized_store.h +++ b/src/crimson/os/futurized_store.h @@ -89,14 +89,14 @@ public: using get_attr_errorator = crimson::errorator< crimson::ct_error::enoent, crimson::ct_error::enodata>; - virtual get_attr_errorator::future get_attr( + virtual get_attr_errorator::future get_attr( CollectionRef c, const ghobject_t& oid, std::string_view name) const = 0; using get_attrs_ertr = crimson::errorator< crimson::ct_error::enoent>; - using attrs_t = std::map>; + using attrs_t = std::map>; virtual get_attrs_ertr::future get_attrs( CollectionRef c, const ghobject_t& oid) = 0; diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index 8a477b591d8d..e526ff3da89d 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -194,7 +194,7 @@ SeaStore::read_errorator::future SeaStore::readv( return read_errorator::make_ready_future(); } -SeaStore::get_attr_errorator::future SeaStore::get_attr( +SeaStore::get_attr_errorator::future SeaStore::get_attr( CollectionRef ch, const ghobject_t& oid, std::string_view name) const @@ -566,10 +566,9 @@ SeaStore::tm_ret SeaStore::_do_transaction_step( case Transaction::OP_SETATTR: { std::string name = i.decode_string(); - ceph::bufferlist bl; + std::map to_set; + ceph::bufferlist& bl = to_set[name]; i.decode_bl(bl); - std::map to_set; - to_set[name] = bufferptr(bl.c_str(), bl.length()); return _setattrs(ctx, get_onode(op->oid), std::move(to_set)); } break; @@ -809,7 +808,7 @@ SeaStore::tm_ret SeaStore::_truncate( SeaStore::tm_ret SeaStore::_setattrs( internal_context_t &ctx, OnodeRef &onode, - std::map &&aset) + std::map&& aset) { logger().debug("{} onode={}", __func__, *onode); diff --git a/src/crimson/os/seastore/seastore.h b/src/crimson/os/seastore/seastore.h index 7857ac0f6730..a84c479e7e5d 100644 --- a/src/crimson/os/seastore/seastore.h +++ b/src/crimson/os/seastore/seastore.h @@ -62,7 +62,7 @@ public: const ghobject_t& oid, interval_set& m, uint32_t op_flags = 0) final; - get_attr_errorator::future get_attr( + get_attr_errorator::future get_attr( CollectionRef c, const ghobject_t& oid, std::string_view name) const final; @@ -254,7 +254,7 @@ private: tm_ret _setattrs( internal_context_t &ctx, OnodeRef &onode, - std::map &&aset); + std::map&& aset); tm_ret _create_collection( internal_context_t &ctx, const coll_t& cid, int bits); diff --git a/src/crimson/osd/ops_executer.cc b/src/crimson/osd/ops_executer.cc index 2dd1d4060bce..3bd94b915f75 100644 --- a/src/crimson/osd/ops_executer.cc +++ b/src/crimson/osd/ops_executer.cc @@ -653,11 +653,9 @@ static PG::interruptible_future pgls_filter( logger().debug("pgls_filter: filter is interested in xattr={} for obj={}", xattr, sobj); return backend.getxattr(sobj, xattr).safe_then_interruptible( - [&filter, sobj] (ceph::bufferptr bp) { + [&filter, sobj] (ceph::bufferlist val) { logger().debug("pgls_filter: got xvalue for obj={}", sobj); - ceph::bufferlist val; - val.push_back(std::move(bp)); const bool filtered = filter.filter(sobj, val); return seastar::make_ready_future(filtered ? sobj : hobject_t{}); }, PGBackend::get_attr_errorator::all_same_way([&filter, sobj] { diff --git a/src/crimson/osd/pg_backend.cc b/src/crimson/osd/pg_backend.cc index ca112a0d146a..a76b88b25ff2 100644 --- a/src/crimson/osd/pg_backend.cc +++ b/src/crimson/osd/pg_backend.cc @@ -77,8 +77,7 @@ PGBackend::load_metadata(const hobject_t& oid) [oid](auto &&attrs) -> load_metadata_ertr::future{ loaded_object_md_t::ref ret(new loaded_object_md_t()); if (auto oiiter = attrs.find(OI_ATTR); oiiter != attrs.end()) { - bufferlist bl; - bl.push_back(std::move(oiiter->second)); + bufferlist bl = std::move(oiiter->second); ret->os = ObjectState( object_info_t(bl), true); @@ -91,8 +90,7 @@ PGBackend::load_metadata(const hobject_t& oid) if (oid.is_head()) { if (auto ssiter = attrs.find(SS_ATTR); ssiter != attrs.end()) { - bufferlist bl; - bl.push_back(std::move(ssiter->second)); + bufferlist bl = std::move(ssiter->second); ret->ss = SnapSet(bl); } else { /* TODO: add support for writing out snapsets @@ -793,17 +791,14 @@ PGBackend::get_attr_ierrorator::future<> PGBackend::getxattr( } logger().debug("getxattr on obj={} for attr={}", os.oi.soid, name); return getxattr(os.oi.soid, name).safe_then_interruptible( - [&osd_op] (ceph::bufferptr val) { - osd_op.outdata.clear(); - osd_op.outdata.push_back(std::move(val)); + [&osd_op] (ceph::bufferlist&& val) { + osd_op.outdata = std::move(val); osd_op.op.xattr.value_len = osd_op.outdata.length(); return get_attr_errorator::now(); - //ctx->delta_stats.num_rd_kb += shift_round_up(osd_op.outdata.length(), 10); }); - //ctx->delta_stats.num_rd++; } -PGBackend::get_attr_ierrorator::future +PGBackend::get_attr_ierrorator::future PGBackend::getxattr( const hobject_t& soid, std::string_view key) const diff --git a/src/crimson/osd/pg_backend.h b/src/crimson/osd/pg_backend.h index c8befbbb6f3f..7f5a52754551 100644 --- a/src/crimson/osd/pg_backend.h +++ b/src/crimson/osd/pg_backend.h @@ -181,7 +181,7 @@ public: get_attr_ierrorator::future<> getxattr( const ObjectState& os, OSDOp& osd_op) const; - get_attr_ierrorator::future getxattr( + get_attr_ierrorator::future getxattr( const hobject_t& soid, std::string_view key) const; get_attr_ierrorator::future<> get_xattrs( diff --git a/src/crimson/osd/replicated_recovery_backend.cc b/src/crimson/osd/replicated_recovery_backend.cc index e10c142296f3..7dab1852b6c5 100644 --- a/src/crimson/osd/replicated_recovery_backend.cc +++ b/src/crimson/osd/replicated_recovery_backend.cc @@ -453,8 +453,8 @@ ReplicatedRecoveryBackend::read_metadata_for_push_op( return eversion_t{}; } push_op->omap_header.claim_append(std::move(bl)); - for (auto&& [key, val] : std::move(attrs)) { - push_op->attrset[key].push_back(val); + for (auto&& [key, val] : attrs) { + push_op->attrset.emplace(std::move(key), std::move(val)); } logger().debug("read_metadata_for_push_op: {}", push_op->attrset[OI_ATTR]); object_info_t oi;