Skip to content

Commit 1df9dd9

Browse files
committed
crimson/common/interruptible_future: new interruptor function repeat_eagain
Signed-off-by: Xuehan Xu <[email protected]>
1 parent 8b5b1ad commit 1df9dd9

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/crimson/common/interruptible_future.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,27 @@ struct interruptor
13301330
);
13311331
}
13321332
}
1333+
1334+
template <InvokeReturnsInterruptibleFuture AsyncAction>
1335+
[[gnu::always_inline]]
1336+
static auto repeat_eagain(AsyncAction&& action) {
1337+
return seastar::do_with(
1338+
std::forward<AsyncAction>(action),
1339+
[] (auto &f) {
1340+
return repeat([&f] {
1341+
return std::invoke(f
1342+
).si_then([] {
1343+
return seastar::stop_iteration::yes;
1344+
}).handle_error_interruptible(
1345+
[](const crimson::ct_error::eagain &e) {
1346+
return seastar::stop_iteration::no;
1347+
},
1348+
crimson::ct_error::pass_further_all{}
1349+
);
1350+
});
1351+
});
1352+
}
1353+
13331354
template <typename AsyncAction>
13341355
requires (!InvokeReturnsInterruptibleFuture<AsyncAction>)
13351356
[[gnu::always_inline]]

src/test/crimson/test_interruptible_future.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,29 @@ TEST_F(seastar_test_suite_t, DISABLED_nested_interruptors)
282282
});
283283
}
284284

285+
TEST_F(seastar_test_suite_t, interruptible_repeat_eagain)
286+
{
287+
using interruptor =
288+
interruptible::interruptor<TestInterruptCondition>;
289+
run_async([] {
290+
interruptor::with_interruption([] {
291+
return seastar::do_with(
292+
0,
293+
[](auto &i) {
294+
return interruptor::repeat_eagain([&i]() -> base_iertr::future<> {
295+
if (++i < 5) {
296+
return crimson::ct_error::eagain::make();
297+
}
298+
return base_iertr::now();
299+
}).si_then([&i] {
300+
std::cout << i << std::endl;
301+
ceph_assert(i == 5);
302+
});
303+
});
304+
}, [](std::exception_ptr) {}, false).unsafe_get();
305+
});
306+
}
307+
285308
#if 0
286309
// This seems to cause a hang in the gcc-9 linker on bionic
287310
TEST_F(seastar_test_suite_t, handle_error)

0 commit comments

Comments
 (0)