From 4d9b9c5115fa8107008c245964b16dbdfd0f1d6e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 4 Nov 2020 22:40:32 +0800 Subject: [PATCH] osd/PGLog: do not use unique_ptr explicitly * do not use unique_ptr<> explicitly, use `seastar::do_with()` for better readability * use seastar::do_until() instead of seastar::repeat() for better readability. plain boolean is simpler than `seastar::stop_iteration::yes` * do not capture variables using FuturizedStoreLogReader if we could pass them by instant parameters. * rename "start()" to "read()". as "read" is more specific in this context. Signed-off-by: Kefu Chai --- src/osd/PGLog.cc | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/osd/PGLog.cc b/src/osd/PGLog.cc index 6ca9c0e05cf..be3f7414d69 100644 --- a/src/osd/PGLog.cc +++ b/src/osd/PGLog.cc @@ -1018,12 +1018,10 @@ void PGLog::rebuild_missing_set_with_deletes( namespace { struct FuturizedStoreLogReader { crimson::os::FuturizedStore &store; - crimson::os::CollectionRef ch; const pg_info_t &info; PGLog::IndexedLog &log; std::set* log_keys_debug = NULL; pg_missing_tracker_t &missing; - ghobject_t pgmeta_oid; const DoutPrefixProvider *dpp; eversion_t on_disk_can_rollback_to; @@ -1084,32 +1082,26 @@ namespace { } } - seastar::future<> start() { + seastar::future<> read(crimson::os::CollectionRef ch, + ghobject_t pgmeta_oid) { // will get overridden if recorded on_disk_can_rollback_to = info.last_update; missing.may_include_deletes = false; - auto reader = std::unique_ptr(this); return store.get_omap_iterator(ch, pgmeta_oid).then([this](auto iter) { - return seastar::repeat([this, iter]() mutable { - if (!iter->valid()) { - return seastar::make_ready_future( - seastar::stop_iteration::yes); - } - process_entry(iter); - return iter->next().then([] { - return seastar::stop_iteration::no; - }); - }); - }).then([this, reader{std::move(reader)}]() { - log = PGLog::IndexedLog( - info.last_update, - info.log_tail, - on_disk_can_rollback_to, - on_disk_rollback_info_trimmed_to, - std::move(entries), - std::move(dups)); - return seastar::now(); + return seastar::do_until([iter] { return !iter->valid(); }, + [iter, this]() mutable { + process_entry(iter); + return iter->next(); + }); + }).then([this] { + log = PGLog::IndexedLog( + info.last_update, + info.log_tail, + on_disk_can_rollback_to, + on_disk_rollback_info_trimmed_to, + std::move(entries), + std::move(dups)); }); } }; @@ -1128,8 +1120,12 @@ seastar::future<> PGLog::read_log_and_missing_crimson( ldpp_dout(dpp, 20) << "read_log_and_missing coll " << ch->get_cid() << " " << pgmeta_oid << dendl; - return (new FuturizedStoreLogReader{ - store, ch, info, log, log_keys_debug, - missing, pgmeta_oid, dpp})->start(); + return seastar::do_with(FuturizedStoreLogReader{ + store, info, log, log_keys_debug, + missing, dpp}, + [ch, pgmeta_oid](FuturizedStoreLogReader& reader) { + return reader.read(ch, pgmeta_oid); + }); } + #endif