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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user