diff options
author | Abhishek Lekshmanan <abhishek@suse.com> | 2018-09-24 18:21:51 +0200 |
---|---|---|
committer | Abhishek Lekshmanan <abhishek@suse.com> | 2019-01-31 19:39:37 +0100 |
commit | ebabd3f794edd8ff0b4db5930d95cc6e0173b3d1 (patch) | |
tree | d961e5b5263d7fb535f6c8a161d438824cdc8895 /src/rgw/rgw_dmclock_scheduler.h | |
parent | initial impl for processing requests (diff) | |
download | ceph-ebabd3f794edd8ff0b4db5930d95cc6e0173b3d1.tar.xz ceph-ebabd3f794edd8ff0b4db5930d95cc6e0173b3d1.zip |
rgw: scheduler: return a completer for completing async requests
Avoid the need for dmclock scoped completer by completing requests with a
wrapper that holds a const ptr to the scheduler and invokes request complete on
destruction
Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
Diffstat (limited to 'src/rgw/rgw_dmclock_scheduler.h')
-rw-r--r-- | src/rgw/rgw_dmclock_scheduler.h | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/rgw/rgw_dmclock_scheduler.h b/src/rgw/rgw_dmclock_scheduler.h index 65331579541..bbc0af38c3d 100644 --- a/src/rgw/rgw_dmclock_scheduler.h +++ b/src/rgw/rgw_dmclock_scheduler.h @@ -77,6 +77,24 @@ struct SyncRequest : public Request { Request{_id, started, cost}, req_mtx(mtx), req_cv(_cv), req_state(_state), counters(counters) {}; }; + +// A move only completer class that'll provide raii style hanlding on scheduled +// requests, this is needed to throttle reqeusts as we need to decrease throttle +// count on request processing, this can probably be templated with a bool so that +// requisite destructor is only invoked when hasResource is true; +class RequestCompleter { +public: + RequestCompleter(AsyncScheduler *_s) : s(_s) {} + ~RequestCompleter(); + + RequestCompleter(const RequestCompleter&) = delete; + RequestCompleter& operator=(const RequestCompleter&) = delete; + RequestCompleter(RequestCompleter&&) = default; + RequestCompleter& operator=(RequestCompleter&&) = default; +private: + AsyncScheduler* const s; +}; + class SyncScheduler { public: template <typename ...Args> @@ -93,13 +111,17 @@ public: const Time& time, Cost cost, optional_yield_context _y [[maybe_unused]]) { - return add_request(client, params, time, cost); + auto r = add_request(client, params, time, cost); + return std::make_pair(std::move(r), + std::unique_ptr<RequestCompleter>{nullptr}); } void cancel(); void cancel(const client_id& client); + void request_complete() {}; + static void handle_request_cb(const client_id& c, std::unique_ptr<SyncRequest> req, PhaseType phase, Cost cost); private: @@ -148,8 +170,8 @@ class AsyncScheduler : public md_config_obs_t { auto async_request(const client_id& client, const ReqParams& params, const Time& time, Cost cost, CompletionToken&& token); - int schedule_request(const client_id& client, const ReqParams& params, - const Time& time, Cost cost, optional_yield_context yield_ctx); + std::pair<int,std::unique_ptr<RequestCompleter>> schedule_request(const client_id& client, const ReqParams& params, + const Time& time, Cost cost, optional_yield_context yield_ctx); /// returns a throttle unit granted by async_request() void request_complete(); @@ -251,7 +273,6 @@ auto AsyncScheduler::async_request(const client_id& client, return init.result.get(); } - /// array of per-client counters to serve as GetClientCounters class ClientCounters { std::array<PerfCountersRef, static_cast<size_t>(client_id::count)> clients; |