diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index 4a0f56a87d9..e9685bc3a1f 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -55,7 +55,7 @@ inline auto do_for_each(Container& c, AsyncAction action) { } template -inline auto do_until(AsyncAction action) { +inline auto repeat(AsyncAction action) { using errorator_t = typename ::seastar::futurize_t>::errorator_type; @@ -71,11 +71,11 @@ inline auto do_until(AsyncAction action) { } } else { return std::move(f)._then( - [action = std::move(action)] (auto &&done) mutable { - if (done) { + [action = std::move(action)] (auto stop) mutable { + if (stop == seastar::stop_iteration::yes) { return errorator_t::template make_ready_future<>(); } - return ::crimson::do_until( + return ::crimson::repeat( std::move(action)); }); } @@ -280,9 +280,9 @@ public: std::invoke(std::forward(errfunc), ErrorT::error_t::from_exception_ptr(std::move(ep))); } else { - static_assert(_impl::always_false::value, - "return of Error Visitor is not assignable to future"); - // do nothing with `ep`. + result = FuturatorT::type::errorator_type::template make_ready_future( + std::invoke(std::forward(errfunc), + ErrorT::error_t::from_exception_ptr(std::move(ep)))); } } } @@ -704,7 +704,7 @@ private: AsyncAction action); template - friend inline auto ::crimson::do_until(AsyncAction action); + friend inline auto ::crimson::repeat(AsyncAction action); template friend class ::seastar::future; diff --git a/src/crimson/common/interruptible_future.h b/src/crimson/common/interruptible_future.h index 69ecbe11054..d2ae5e8880c 100644 --- a/src/crimson/common/interruptible_future.h +++ b/src/crimson/common/interruptible_future.h @@ -1029,7 +1029,7 @@ public: ); } else { return make_interruptible( - ::crimson::do_until( + ::crimson::repeat( [action=std::move(action), interrupt_condition=interrupt_cond] { return call_with_interruption( @@ -1057,7 +1057,7 @@ public: ); } else { return make_interruptible( - ::crimson::do_until( + ::crimson::repeat( [action=std::move(action), interrupt_condition=interrupt_cond] { return call_with_interruption( diff --git a/src/crimson/os/seastore/journal.cc b/src/crimson/os/seastore/journal.cc index 5a317c2cc50..9ff9ad40e76 100644 --- a/src/crimson/os/seastore/journal.cc +++ b/src/crimson/os/seastore/journal.cc @@ -705,9 +705,9 @@ Journal::scan_valid_records_ret Journal::scan_valid_records( } auto retref = std::make_unique(0); auto budget_used = *retref; - return crimson::do_until( + return crimson::repeat( [=, &cursor, &budget_used, &handler]() mutable - -> scan_valid_records_ertr::future { + -> scan_valid_records_ertr::future { return [=, &handler, &cursor, &budget_used] { if (!cursor.last_valid_header_found) { return read_validate_record_metadata(cursor.offset, nonce @@ -737,7 +737,7 @@ Journal::scan_valid_records_ret Journal::scan_valid_records( return scan_valid_records_ertr::now(); } }).safe_then([=, &cursor, &budget_used, &handler] { - return crimson::do_until( + return crimson::repeat( [=, &budget_used, &cursor, &handler] { logger().debug( "Journal::scan_valid_records: valid record read, processing queue"); @@ -747,11 +747,13 @@ Journal::scan_valid_records_ret Journal::scan_valid_records( * location since it itself cannot yet have been committed * at its own time of submission. Thus, the most recently * read record must always fall after cursor.last_committed */ - return scan_valid_records_ertr::make_ready_future(true); + return scan_valid_records_ertr::make_ready_future< + seastar::stop_iteration>(seastar::stop_iteration::yes); } auto &next = cursor.pending_records.front(); if (next.offset > cursor.last_committed) { - return scan_valid_records_ertr::make_ready_future(true); + return scan_valid_records_ertr::make_ready_future< + seastar::stop_iteration>(seastar::stop_iteration::yes); } budget_used += next.header.dlength + next.header.mdlength; @@ -761,7 +763,8 @@ Journal::scan_valid_records_ret Journal::scan_valid_records( next.mdbuffer ).safe_then([&cursor] { cursor.pending_records.pop_front(); - return scan_valid_records_ertr::make_ready_future(false); + return scan_valid_records_ertr::make_ready_future< + seastar::stop_iteration>(seastar::stop_iteration::no); }); }); }); @@ -787,8 +790,11 @@ Journal::scan_valid_records_ret Journal::scan_valid_records( }); } }().safe_then([=, &budget_used, &cursor] { - return scan_valid_records_ertr::make_ready_future( - cursor.is_complete() || budget_used >= budget); + if (cursor.is_complete() || budget_used >= budget) { + return seastar::stop_iteration::yes; + } else { + return seastar::stop_iteration::no; + } }); }).safe_then([retref=std::move(retref)]() mutable -> scan_valid_records_ret { return scan_valid_records_ret( diff --git a/src/crimson/os/seastore/lba_manager/btree/lba_btree_node_impl.cc b/src/crimson/os/seastore/lba_manager/btree/lba_btree_node_impl.cc index 2adb8eff281..23955e23563 100644 --- a/src/crimson/os/seastore/lba_manager/btree/lba_btree_node_impl.cc +++ b/src/crimson/os/seastore/lba_manager/btree/lba_btree_node_impl.cc @@ -236,9 +236,11 @@ LBAInternalNode::find_hole_ret LBAInternalNode::find_hole( begin, L_ADDR_NULL, [this, c, min_addr, len, end=end](auto &i, auto &ret) { - return crimson::do_until([=, &i, &ret]() -> find_hole_ertr::future { + return crimson::repeat([=, &i, &ret]() + -> find_hole_ertr::future { if (i == end) { - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } return get_lba_btree_extent( c, @@ -255,10 +257,12 @@ LBAInternalNode::find_hole_ret LBAInternalNode::find_hole( }).safe_then([&i, &ret](auto addr) mutable { if (addr == L_ADDR_NULL) { ++i; - return false; + return seastar::make_ready_future( + seastar::stop_iteration::no); } else { ret = addr; - return true; + return seastar::make_ready_future( + seastar::stop_iteration::yes); } }); }).safe_then([&ret, ref=LBANodeRef(this)] { diff --git a/src/crimson/os/seastore/omap_manager/btree/omap_btree_node_impl.cc b/src/crimson/os/seastore/omap_manager/btree/omap_btree_node_impl.cc index be496dd1e7b..64ca500e6d9 100644 --- a/src/crimson/os/seastore/omap_manager/btree/omap_btree_node_impl.cc +++ b/src/crimson/os/seastore/omap_manager/btree/omap_btree_node_impl.cc @@ -209,11 +209,12 @@ OMapInnerNode::list( [=, &start](auto &biter, auto &eiter, auto &ret) { auto &complete = std::get<0>(ret); auto &result = std::get<1>(ret); - return crimson::do_until( - [&, config, oc, this]() -> list_ertr::future { + return crimson::repeat( + [&, config, oc, this]() -> list_ertr::future { if (biter == eiter || result.size() == config.max_result_size) { complete = biter == eiter; - return list_ertr::make_ready_future(true); + return list_ertr::make_ready_future( + seastar::stop_iteration::yes); } auto laddr = biter->get_val(); return omap_load_extent( @@ -235,7 +236,8 @@ OMapInnerNode::list( result.merge(std::move(child_result)); ++biter; assert(child_complete || result.size() == config.max_result_size); - return list_ertr::make_ready_future(false); + return list_ertr::make_ready_future( + seastar::stop_iteration::no); }); }); }).safe_then([&ret, ref = OMapNodeRef(this)] { diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.cc index d995a83eaa0..7693157ee23 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.cc @@ -127,17 +127,19 @@ FLTreeOnodeManager::list_onodes_ret FLTreeOnodeManager::list_onodes( std::move(cursor), list_onodes_bare_ret(), [this, &trans, end] (auto& to_list, auto& current_cursor, auto& ret) { - return crimson::do_until( + return crimson::repeat( [this, &trans, end, &to_list, ¤t_cursor, &ret] () mutable - -> eagain_future { + -> eagain_future { if (current_cursor.is_end() || current_cursor.get_ghobj() >= end) { std::get<1>(ret) = end; - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } if (to_list == 0) { std::get<1>(ret) = current_cursor.get_ghobj(); - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } std::get<0>(ret).emplace_back(current_cursor.get_ghobj()); return tree.get_next(trans, current_cursor @@ -146,7 +148,7 @@ FLTreeOnodeManager::list_onodes_ret FLTreeOnodeManager::list_onodes( // accelerate tree lookup. --to_list; current_cursor = next_cursor; - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; }); }).safe_then([&ret] () mutable { return seastar::make_ready_future( diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc index 6eea71f4c08..9fab9a8caa0 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc @@ -1272,25 +1272,26 @@ eagain_future<> InternalNode::do_get_tree_stats( [this, this_ref, c, &stats](auto& pos, auto& p_child_addr) { pos = search_position_t::begin(); impl->get_slot(pos, nullptr, &p_child_addr); - return crimson::do_until( - [this, this_ref, c, &stats, &pos, &p_child_addr]() -> eagain_future { + return crimson::repeat( + [this, this_ref, c, &stats, &pos, &p_child_addr]() + -> eagain_future { return get_or_track_child(c, pos, p_child_addr->value ).safe_then([c, &stats](auto child) { return child->do_get_tree_stats(c, stats); }).safe_then([this, this_ref, &pos, &p_child_addr] { if (pos.is_end()) { - return seastar::make_ready_future(true); + return seastar::stop_iteration::yes; } else { impl->get_next_slot(pos, nullptr, &p_child_addr); if (pos.is_end()) { if (impl->is_level_tail()) { p_child_addr = impl->get_tail_value(); - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; } else { - return seastar::make_ready_future(true); + return seastar::stop_iteration::yes; } } else { - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; } } }); diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/tree_utils.h b/src/crimson/os/seastore/onode_manager/staged-fltree/tree_utils.h index cd60a103fa8..4aa4dcec901 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/tree_utils.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/tree_utils.h @@ -338,12 +338,14 @@ class TreeBuilder { auto cursors = seastar::make_lw_shared>(); logger().warn("start inserting {} kvs ...", kvs.size()); auto start_time = mono_clock::now(); - return crimson::do_until([&t, this, cursors, ref_kv_iter, - start_time]() -> eagain_future { + return crimson::repeat([&t, this, cursors, ref_kv_iter, + start_time]() + -> eagain_future { if (*ref_kv_iter == kvs.random_end()) { std::chrono::duration duration = mono_clock::now() - start_time; logger().warn("Insert done! {}s", duration.count()); - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } else { return insert_one(t, *ref_kv_iter ).safe_then([cursors, ref_kv_iter] (auto cursor) { @@ -351,7 +353,7 @@ class TreeBuilder { cursors->emplace_back(cursor); } ++(*ref_kv_iter); - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; }); } }).safe_then([&t, this, cursors, ref_kv_iter] { @@ -361,11 +363,13 @@ class TreeBuilder { return seastar::do_with( cursors->begin(), [&t, this, cursors, ref_kv_iter] (auto& c_iter) { - return crimson::do_until( - [&t, this, &c_iter, cursors, ref_kv_iter] () -> eagain_future { + return crimson::repeat( + [&t, this, &c_iter, cursors, ref_kv_iter] () + -> eagain_future { if (*ref_kv_iter == kvs.random_end()) { logger().info("Verify done!"); - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } assert(c_iter != cursors->end()); auto p_kv = **ref_kv_iter; @@ -377,7 +381,7 @@ class TreeBuilder { validate_cursor_from_item(p_kv->key, p_kv->value, *c_iter); ++(*ref_kv_iter); ++c_iter; - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; }); }); }); @@ -419,12 +423,14 @@ class TreeBuilder { logger().info("Tracking cursors before erase ..."); *ref_kv_iter = kvs.begin(); auto start_time = mono_clock::now(); - return crimson::do_until( - [&t, this, cursors, ref_kv_iter, start_time] () -> eagain_future { + return crimson::repeat( + [&t, this, cursors, ref_kv_iter, start_time] () + -> eagain_future { if (*ref_kv_iter == kvs.end()) { std::chrono::duration duration = mono_clock::now() - start_time; logger().info("Track done! {}s", duration.count()); - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } auto p_kv = **ref_kv_iter; return tree->find(t, p_kv->key).safe_then([this, cursors, ref_kv_iter](auto cursor) { @@ -432,7 +438,7 @@ class TreeBuilder { validate_cursor_from_item(p_kv->key, p_kv->value, cursor); cursors->emplace(p_kv->key, cursor); ++(*ref_kv_iter); - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; }); }); } else { @@ -443,17 +449,19 @@ class TreeBuilder { logger().warn("start erasing {}/{} kvs ...", erase_end - kvs.random_begin(), kvs.size()); auto start_time = mono_clock::now(); - return crimson::do_until([&t, this, ref_kv_iter, - start_time, erase_end] () -> eagain_future { + return crimson::repeat([&t, this, ref_kv_iter, + start_time, erase_end] () + -> eagain_future { if (*ref_kv_iter == erase_end) { std::chrono::duration duration = mono_clock::now() - start_time; logger().warn("Erase done! {}s", duration.count()); - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } else { return erase_one(t, *ref_kv_iter ).safe_then([ref_kv_iter] { ++(*ref_kv_iter); - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; }); } }); diff --git a/src/crimson/os/seastore/random_block_manager/nvme_manager.cc b/src/crimson/os/seastore/random_block_manager/nvme_manager.cc index 8326162b866..b0fe1bc709c 100644 --- a/src/crimson/os/seastore/random_block_manager/nvme_manager.cc +++ b/src/crimson/os/seastore/random_block_manager/nvme_manager.cc @@ -174,7 +174,7 @@ NVMeManager::find_block_ret NVMeManager::find_free_block(Transaction &t, size_t interval_set(), bp, [&, this] (auto &allocated, auto &addr, auto &alloc_extent, auto &bp) mutable { - return crimson::do_until( + return crimson::repeat( [&, this] () mutable { return device->read( addr, @@ -213,12 +213,12 @@ NVMeManager::find_block_ret NVMeManager::find_free_block(Transaction &t, size_t logger().debug("find_free_list: allocated: {} alloc_extent {}", allocated, alloc_extent); if (((uint64_t)size)/super.block_size == allocated) { - return find_block_ertr::make_ready_future(true); + return seastar::stop_iteration::yes; } else if (addr >= super.start_data_area) { alloc_extent.clear(); - return find_block_ertr::make_ready_future(true); + return seastar::stop_iteration::yes; } - return find_block_ertr::make_ready_future(false); + return seastar::stop_iteration::no; }); }).safe_then([&allocated, &alloc_extent, size, this] () { logger().debug(" allocated: {} size {} ", @@ -598,7 +598,7 @@ NVMeManager::check_bitmap_blocks_ertr::future<> NVMeManager::check_bitmap_blocks auto bp = bufferptr(ceph::buffer::create_page_aligned(super.block_size)); return seastar::do_with(uint64_t(super.start_alloc_area), uint64_t(0), bp, [&, this] (auto &addr, auto &free_blocks, auto &bp) mutable { - return crimson::do_until([&, this] () mutable { + return crimson::repeat([&, this] () mutable { return device->read(addr,bp).safe_then( [&bp, &addr, &free_blocks, this]() mutable { logger().debug("verify_bitmap_blocks: addr {}", addr); @@ -614,9 +614,9 @@ NVMeManager::check_bitmap_blocks_ertr::future<> NVMeManager::check_bitmap_blocks } addr += super.block_size; if (addr >= super.start_data_area) { - return find_block_ertr::make_ready_future(true); + return seastar::stop_iteration::yes; } - return find_block_ertr::make_ready_future(false); + return seastar::stop_iteration::no; }); }).safe_then([&free_blocks, this] () { logger().debug(" free_blocks: {} ", free_blocks); diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index f2d2783e3b4..f6006f6ac14 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -618,16 +618,18 @@ seastar::future<> SeaStore::do_transaction( *ctx.transaction, ctx.iter.get_objects() ).safe_then([this, &ctx](auto &&read_onodes) { ctx.onodes = std::move(read_onodes); - return crimson::do_until( - [this, &ctx]() -> tm_ertr::future { + return crimson::repeat( + [this, &ctx]() -> tm_ertr::future { if (ctx.iter.have_op()) { return _do_transaction_step( ctx, ctx.ch, ctx.onodes, ctx.iter ).safe_then([] { - return seastar::make_ready_future(false); + return seastar::make_ready_future( + seastar::stop_iteration::no); }); } else { - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); }; }); }).safe_then([this, &ctx] { diff --git a/src/crimson/os/seastore/transaction_manager.h b/src/crimson/os/seastore/transaction_manager.h index 9f398c8a400..2fb7df7922b 100644 --- a/src/crimson/os/seastore/transaction_manager.h +++ b/src/crimson/os/seastore/transaction_manager.h @@ -37,15 +37,15 @@ auto repeat_eagain(F &&f) { return seastar::do_with( std::forward(f), [FNAME](auto &f) { - return crimson::do_until( + return crimson::repeat( [FNAME, &f] { return std::invoke(f ).safe_then([] { - return true; + return seastar::stop_iteration::yes; }).handle_error( [FNAME](const crimson::ct_error::eagain &e) { DEBUG("hit eagain, restarting"); - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; }, crimson::ct_error::pass_further_all{} ); diff --git a/src/test/crimson/seastore/onode_tree/test_staged_fltree.cc b/src/test/crimson/seastore/onode_tree/test_staged_fltree.cc index 498b58a87c1..010c0230163 100644 --- a/src/test/crimson/seastore/onode_tree/test_staged_fltree.cc +++ b/src/test/crimson/seastore/onode_tree/test_staged_fltree.cc @@ -1103,9 +1103,11 @@ class DummyChildPool { ).safe_then([this](auto initial_child) { // split splitable_nodes.insert(initial_child); - return crimson::do_until([this] () -> eagain_future { + return crimson::repeat([this] () + -> eagain_future { if (splitable_nodes.empty()) { - return seastar::make_ready_future(true); + return seastar::make_ready_future( + seastar::stop_iteration::yes); } auto index = rd() % splitable_nodes.size(); auto iter = splitable_nodes.begin(); @@ -1113,7 +1115,7 @@ class DummyChildPool { Ref child = *iter; return child->populate_split(get_context(), splitable_nodes ).safe_then([] { - return seastar::make_ready_future(false); + return seastar::stop_iteration::no; }); }); }).safe_then([this] { diff --git a/src/test/crimson/test_errorator.cc b/src/test/crimson/test_errorator.cc index 8d6cf9a00c3..939c6cde81a 100644 --- a/src/test/crimson/test_errorator.cc +++ b/src/test/crimson/test_errorator.cc @@ -14,12 +14,14 @@ struct errorator_test_t : public seastar_test_suite_t { using ertr = crimson::errorator; ertr::future<> test_do_until() { - return crimson::do_until([i=0]() mutable { + return crimson::repeat([i=0]() mutable { if (i < 5) { ++i; - return ertr::make_ready_future(false); + return ertr::make_ready_future( + seastar::stop_iteration::no); } else { - return ertr::make_ready_future(true); + return ertr::make_ready_future( + seastar::stop_iteration::yes); } }); }