From 23e963bb1ac4d289a6866f717e955454312b9255 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 11 Sep 2020 16:43:37 +0800 Subject: [PATCH] crimson/osd: pass the the cause by string_view in future, string_view can be used almost every where string can be used. in this change, `const char*` is instead passed to the constructor of system_error, as we can ensure that the string_view instances are always constructed from a `const char*` ended with `\0`. we need this change for two reasons: * better performance * prefer for the world where string_view rules. Signed-off-by: Kefu Chai --- src/crimson/osd/recovery_backend.cc | 2 +- src/crimson/osd/recovery_backend.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/crimson/osd/recovery_backend.cc b/src/crimson/osd/recovery_backend.cc index deb0ca4a07b91..77a5480a97509 100644 --- a/src/crimson/osd/recovery_backend.cc +++ b/src/crimson/osd/recovery_backend.cc @@ -30,7 +30,7 @@ hobject_t RecoveryBackend::get_temp_recovery_object( } void RecoveryBackend::clean_up(ceph::os::Transaction& t, - const std::string& why) + std::string_view why) { for (auto& soid : temp_contents) { t.remove(pg.get_collection_ref()->get_cid(), diff --git a/src/crimson/osd/recovery_backend.h b/src/crimson/osd/recovery_backend.h index b9d63c1d04172..b529fda5a15c8 100644 --- a/src/crimson/osd/recovery_backend.h +++ b/src/crimson/osd/recovery_backend.h @@ -155,16 +155,16 @@ protected: void set_push_failed(pg_shard_t shard, std::exception_ptr e) { pushes.at(shard).set_exception(e); } - void interrupt(const std::string& why) { + void interrupt(std::string_view why) { readable.set_exception(std::system_error( - std::make_error_code(std::errc::interrupted), why)); + std::make_error_code(std::errc::interrupted), why.data())); recovered.set_exception(std::system_error( - std::make_error_code(std::errc::interrupted), why)); + std::make_error_code(std::errc::interrupted), why.data())); pulled.set_exception(std::system_error( - std::make_error_code(std::errc::interrupted), why)); + std::make_error_code(std::errc::interrupted), why.data())); for (auto& [pg_shard, pr] : pushes) { - pr.set_exception(std::system_error( - std::make_error_code(std::errc::interrupted), why)); + pr.set_exception(std::system_error( + std::make_error_code(std::errc::interrupted), why.data())); } } void stop(); @@ -184,6 +184,6 @@ protected: void clear_temp_obj(const hobject_t &oid) { temp_contents.erase(oid); } - void clean_up(ceph::os::Transaction& t, const std::string& why); + void clean_up(ceph::os::Transaction& t, std::string_view why); virtual seastar::future<> on_stop() = 0; }; -- 2.47.3