Merge pull request #41984 from tchaikov/wip-crimson-repeat

crimson: s/crimson::do_until/crimson::repeat/

Reviewed-by: Ronen Friedman <rfriedma@redhat.com>
Reviewed-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
This commit is contained in:
Kefu Chai 2021-06-23 21:43:34 +08:00 committed by GitHub
commit 97abe4a1be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 102 additions and 73 deletions

View File

@ -55,7 +55,7 @@ inline auto do_for_each(Container& c, AsyncAction action) {
}
template<typename AsyncAction>
inline auto do_until(AsyncAction action) {
inline auto repeat(AsyncAction action) {
using errorator_t =
typename ::seastar::futurize_t<std::invoke_result_t<AsyncAction>>::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<ErrorVisitorT>(errfunc),
ErrorT::error_t::from_exception_ptr(std::move(ep)));
} else {
static_assert(_impl::always_false<return_t>::value,
"return of Error Visitor is not assignable to future");
// do nothing with `ep`.
result = FuturatorT::type::errorator_type::template make_ready_future<return_t>(
std::invoke(std::forward<ErrorVisitorT>(errfunc),
ErrorT::error_t::from_exception_ptr(std::move(ep))));
}
}
}
@ -704,7 +704,7 @@ private:
AsyncAction action);
template<typename AsyncAction>
friend inline auto ::crimson::do_until(AsyncAction action);
friend inline auto ::crimson::repeat(AsyncAction action);
template <typename Result>
friend class ::seastar::future;

View File

@ -1029,7 +1029,7 @@ public:
);
} else {
return make_interruptible(
::crimson::do_until(
::crimson::repeat(
[action=std::move(action),
interrupt_condition=interrupt_cond<InterruptCond>] {
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<InterruptCond>] {
return call_with_interruption(

View File

@ -705,9 +705,9 @@ Journal::scan_valid_records_ret Journal::scan_valid_records(
}
auto retref = std::make_unique<size_t>(0);
auto budget_used = *retref;
return crimson::do_until(
return crimson::repeat(
[=, &cursor, &budget_used, &handler]() mutable
-> scan_valid_records_ertr::future<bool> {
-> scan_valid_records_ertr::future<seastar::stop_iteration> {
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<bool>(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<bool>(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<bool>(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<bool>(
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(

View File

@ -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<bool> {
return crimson::repeat([=, &i, &ret]()
-> find_hole_ertr::future<seastar::stop_iteration> {
if (i == end) {
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
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>(
seastar::stop_iteration::no);
} else {
ret = addr;
return true;
return seastar::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::yes);
}
});
}).safe_then([&ret, ref=LBANodeRef(this)] {

View File

@ -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<bool> {
return crimson::repeat(
[&, config, oc, this]() -> list_ertr::future<seastar::stop_iteration> {
if (biter == eiter || result.size() == config.max_result_size) {
complete = biter == eiter;
return list_ertr::make_ready_future<bool>(true);
return list_ertr::make_ready_future<seastar::stop_iteration>(
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<bool>(false);
return list_ertr::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::no);
});
});
}).safe_then([&ret, ref = OMapNodeRef(this)] {

View File

@ -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, &current_cursor, &ret] () mutable
-> eagain_future<bool> {
-> eagain_future<seastar::stop_iteration> {
if (current_cursor.is_end() ||
current_cursor.get_ghobj() >= end) {
std::get<1>(ret) = end;
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::yes);
}
if (to_list == 0) {
std::get<1>(ret) = current_cursor.get_ghobj();
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
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<bool>(false);
return seastar::stop_iteration::no;
});
}).safe_then([&ret] () mutable {
return seastar::make_ready_future<list_onodes_bare_ret>(

View File

@ -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<bool> {
return crimson::repeat(
[this, this_ref, c, &stats, &pos, &p_child_addr]()
-> eagain_future<seastar::stop_iteration> {
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<bool>(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<bool>(false);
return seastar::stop_iteration::no;
} else {
return seastar::make_ready_future<bool>(true);
return seastar::stop_iteration::yes;
}
} else {
return seastar::make_ready_future<bool>(false);
return seastar::stop_iteration::no;
}
}
});

View File

@ -338,12 +338,14 @@ class TreeBuilder {
auto cursors = seastar::make_lw_shared<std::vector<BtreeCursor>>();
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<bool> {
return crimson::repeat([&t, this, cursors, ref_kv_iter,
start_time]()
-> eagain_future<seastar::stop_iteration> {
if (*ref_kv_iter == kvs.random_end()) {
std::chrono::duration<double> duration = mono_clock::now() - start_time;
logger().warn("Insert done! {}s", duration.count());
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
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<bool>(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<bool> {
return crimson::repeat(
[&t, this, &c_iter, cursors, ref_kv_iter] ()
-> eagain_future<seastar::stop_iteration> {
if (*ref_kv_iter == kvs.random_end()) {
logger().info("Verify done!");
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
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<bool>(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<bool> {
return crimson::repeat(
[&t, this, cursors, ref_kv_iter, start_time] ()
-> eagain_future<seastar::stop_iteration> {
if (*ref_kv_iter == kvs.end()) {
std::chrono::duration<double> duration = mono_clock::now() - start_time;
logger().info("Track done! {}s", duration.count());
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
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<bool>(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<bool> {
return crimson::repeat([&t, this, ref_kv_iter,
start_time, erase_end] ()
-> eagain_future<seastar::stop_iteration> {
if (*ref_kv_iter == erase_end) {
std::chrono::duration<double> duration = mono_clock::now() - start_time;
logger().warn("Erase done! {}s", duration.count());
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
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<bool>(false);
return seastar::stop_iteration::no;
});
}
});

View File

@ -174,7 +174,7 @@ NVMeManager::find_block_ret NVMeManager::find_free_block(Transaction &t, size_t
interval_set<blk_id_t>(),
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<bool>(true);
return seastar::stop_iteration::yes;
} else if (addr >= super.start_data_area) {
alloc_extent.clear();
return find_block_ertr::make_ready_future<bool>(true);
return seastar::stop_iteration::yes;
}
return find_block_ertr::make_ready_future<bool>(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<bool>(true);
return seastar::stop_iteration::yes;
}
return find_block_ertr::make_ready_future<bool>(false);
return seastar::stop_iteration::no;
});
}).safe_then([&free_blocks, this] () {
logger().debug(" free_blocks: {} ", free_blocks);

View File

@ -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<bool> {
return crimson::repeat(
[this, &ctx]() -> tm_ertr::future<seastar::stop_iteration> {
if (ctx.iter.have_op()) {
return _do_transaction_step(
ctx, ctx.ch, ctx.onodes, ctx.iter
).safe_then([] {
return seastar::make_ready_future<bool>(false);
return seastar::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::no);
});
} else {
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::yes);
};
});
}).safe_then([this, &ctx] {

View File

@ -37,15 +37,15 @@ auto repeat_eagain(F &&f) {
return seastar::do_with(
std::forward<F>(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<bool>(false);
return seastar::stop_iteration::no;
},
crimson::ct_error::pass_further_all{}
);

View File

@ -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<bool> {
return crimson::repeat([this] ()
-> eagain_future<seastar::stop_iteration> {
if (splitable_nodes.empty()) {
return seastar::make_ready_future<bool>(true);
return seastar::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::yes);
}
auto index = rd() % splitable_nodes.size();
auto iter = splitable_nodes.begin();
@ -1113,7 +1115,7 @@ class DummyChildPool {
Ref<DummyChild> child = *iter;
return child->populate_split(get_context(), splitable_nodes
).safe_then([] {
return seastar::make_ready_future<bool>(false);
return seastar::stop_iteration::no;
});
});
}).safe_then([this] {

View File

@ -14,12 +14,14 @@
struct errorator_test_t : public seastar_test_suite_t {
using ertr = crimson::errorator<crimson::ct_error::invarg>;
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<bool>(false);
return ertr::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::no);
} else {
return ertr::make_ready_future<bool>(true);
return ertr::make_ready_future<seastar::stop_iteration>(
seastar::stop_iteration::yes);
}
});
}