feed_writers: optimize error path

Eliminate one try/catch block around call to wr.close()
by using coroutine::as_future.

Mark error paths as `[[unlikely]]`.

Use `coroutine::return_exception_ptr` to avoid rethrowing
the final exception.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>

Closes scylladb/scylladb#22831
This commit is contained in:
Benny Halevy
2025-02-13 08:38:29 +02:00
committed by Avi Kivity
parent 138645f744
commit 7a4c563e40

View File

@@ -8,6 +8,8 @@
#pragma once
#include <seastar/coroutine/as_future.hh>
#include "readers/queue.hh"
namespace mutation_writer {
@@ -63,14 +65,15 @@ future<> feed_writer(mutation_reader&& rd_ref, Writer wr) {
}
}
try {
co_await wr.close();
} catch (...) {
auto f = co_await coroutine::as_future(wr.close());
if (f.failed()) [[unlikely]] {
// Need to consume the failed future exception even if not used
auto close_ex = f.get_exception();
if (!ex) {
ex = std::current_exception();
ex = std::move(close_ex);
}
}
if (ex) {
if (ex) [[unlikely]] {
std::rethrow_exception(ex);
}
}