diff --git a/mutation_reader.cc b/mutation_reader.cc index e628a23983..1d2499939c 100644 --- a/mutation_reader.cc +++ b/mutation_reader.cc @@ -1094,11 +1094,7 @@ void evictable_reader::maybe_pause(flat_mutation_reader reader) { } flat_mutation_reader_opt evictable_reader::try_resume() { - auto ir_ptr = _permit.semaphore().unregister_inactive_read(std::move(_irh)); - if (!ir_ptr) { - return {}; - } - return std::move(*ir_ptr); + return _permit.semaphore().unregister_inactive_read(std::move(_irh)); } void evictable_reader::update_next_position(flat_mutation_reader& reader) { @@ -1932,11 +1928,7 @@ reader_lifecycle_policy::pause(reader_concurrency_semaphore& sem, flat_mutation_ flat_mutation_reader_opt reader_lifecycle_policy::try_resume(reader_concurrency_semaphore& sem, reader_concurrency_semaphore::inactive_read_handle irh) { - auto ir_ptr = sem.unregister_inactive_read(std::move(irh)); - if (!ir_ptr) { - return {}; - } - return std::move(*ir_ptr); + return sem.unregister_inactive_read(std::move(irh)); } reader_concurrency_semaphore::inactive_read_handle diff --git a/querier.cc b/querier.cc index 593ac66f8c..57a4c67234 100644 --- a/querier.cc +++ b/querier.cc @@ -304,11 +304,11 @@ static std::optional lookup_querier( throw std::runtime_error("lookup_querier(): found querier is not of the expected type"); } auto& q = *q_ptr; - auto read_ptr = q.permit().semaphore().unregister_inactive_read(querier_utils::get_inactive_read_handle(q)); - if (!read_ptr) { + auto reader_opt = q.permit().semaphore().unregister_inactive_read(querier_utils::get_inactive_read_handle(q)); + if (!reader_opt) { throw std::runtime_error("lookup_querier(): found querier that is evicted"); } - querier_utils::set_reader(q, std::move(*read_ptr.get())); + querier_utils::set_reader(q, std::move(*reader_opt)); --stats.population; const auto can_be_used = can_be_used_for_page(q, s, ranges.front(), slice); diff --git a/reader_concurrency_semaphore.cc b/reader_concurrency_semaphore.cc index acf25cd8a8..ff9636288c 100644 --- a/reader_concurrency_semaphore.cc +++ b/reader_concurrency_semaphore.cc @@ -339,10 +339,6 @@ void reader_concurrency_semaphore::expiry_handler::operator()(entry& e) noexcept maybe_dump_reader_permit_diagnostics(_semaphore, *_semaphore._permit_list, "timed out"); } -reader_concurrency_semaphore::inactive_read::inactive_read(flat_mutation_reader reader) - : reader(std::make_unique(std::move(reader))) { -} - reader_concurrency_semaphore::inactive_read::~inactive_read() { } @@ -413,7 +409,7 @@ reader_concurrency_semaphore::inactive_read_handle reader_concurrency_semaphore: return inactive_read_handle(); } -std::unique_ptr reader_concurrency_semaphore::unregister_inactive_read(inactive_read_handle irh) { +flat_mutation_reader_opt reader_concurrency_semaphore::unregister_inactive_read(inactive_read_handle irh) { if (irh && irh._sem != this) { throw std::runtime_error(fmt::format( "reader_concurrency_semaphore::unregister_inactive_read(): " diff --git a/reader_concurrency_semaphore.hh b/reader_concurrency_semaphore.hh index 403ce12a09..f2104dbca6 100644 --- a/reader_concurrency_semaphore.hh +++ b/reader_concurrency_semaphore.hh @@ -24,11 +24,10 @@ #include #include #include "reader_permit.hh" +#include "flat_mutation_reader.hh" using namespace seastar; -class flat_mutation_reader; - /// Specific semaphore for controlling reader concurrency /// /// Use `make_permit()` to create a permit to track the resource consumption @@ -122,11 +121,13 @@ private: }; struct inactive_read { - std::unique_ptr reader; + flat_mutation_reader reader; eviction_notify_handler notify_handler; std::optional> ttl_timer; - explicit inactive_read(flat_mutation_reader); + explicit inactive_read(flat_mutation_reader reader_) noexcept + : reader(std::move(reader_)) + { } inactive_read(inactive_read&&) = default; ~inactive_read(); }; @@ -203,7 +204,7 @@ public: /// /// If the read was not evicted, the inactive read object, passed in to the /// register call, will be returned. Otherwise a nullptr is returned. - std::unique_ptr unregister_inactive_read(inactive_read_handle irh); + flat_mutation_reader_opt unregister_inactive_read(inactive_read_handle irh); /// Try to evict an inactive read. ///