1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
7 #include "rgw_common.h"
9 #include "rgw_auth_registry.h"
14 #include "include/ceph_assert.h"
16 #include "common/WorkQueue.h"
17 #include "common/Throttle.h"
21 #if !defined(dout_subsys)
22 #define dout_subsys ceph_subsys_rgw
23 #define def_dout_subsys
26 #define dout_context g_ceph_context
28 extern void signal_shutdown();
30 namespace rgw::dmclock
{
34 struct RGWProcessEnv
{
35 rgw::sal::RGWRadosStore
*store
;
39 std::string uri_prefix
;
40 std::shared_ptr
<rgw::auth::StrategyRegistry
> auth_registry
;
43 class RGWFrontendConfig
;
47 deque
<RGWRequest
*> m_req_queue
;
50 rgw::sal::RGWRadosStore
* store
;
51 rgw_auth_registry_ptr_t auth_registry
;
54 Throttle req_throttle
;
56 RGWFrontendConfig
* conf
;
58 std::string uri_prefix
;
60 struct RGWWQ
: public DoutPrefixProvider
, public ThreadPool::WorkQueue
<RGWRequest
> {
62 RGWWQ(RGWProcess
* p
, ceph::timespan timeout
, ceph::timespan suicide_timeout
,
64 : ThreadPool::WorkQueue
<RGWRequest
>("RGWWQ", timeout
, suicide_timeout
,
67 bool _enqueue(RGWRequest
* req
) override
;
69 void _dequeue(RGWRequest
* req
) override
{
73 bool _empty() override
{
74 return process
->m_req_queue
.empty();
77 RGWRequest
* _dequeue() override
;
79 using ThreadPool::WorkQueue
<RGWRequest
>::_process
;
81 void _process(RGWRequest
*req
, ThreadPool::TPHandle
&) override
;
85 void _clear() override
{
86 ceph_assert(process
->m_req_queue
.empty());
89 CephContext
*get_cct() const override
{ return process
->cct
; }
90 unsigned get_subsys() const { return ceph_subsys_rgw
; }
91 std::ostream
& gen_prefix(std::ostream
& out
) const { return out
<< "rgw request work queue: ";}
96 RGWProcess(CephContext
* const cct
,
97 RGWProcessEnv
* const pe
,
98 const int num_threads
,
99 RGWFrontendConfig
* const conf
)
102 auth_registry(pe
->auth_registry
),
104 m_tp(cct
, "RGWProcess::m_tp", "tp_rgw_process", num_threads
),
105 req_throttle(cct
, "rgw_ops", num_threads
* 2),
109 uri_prefix(pe
->uri_prefix
),
111 ceph::make_timespan(g_conf()->rgw_op_thread_timeout
),
112 ceph::make_timespan(g_conf()->rgw_op_thread_suicide_timeout
),
116 virtual ~RGWProcess() = default;
118 virtual void run() = 0;
119 virtual void handle_request(const DoutPrefixProvider
*dpp
, RGWRequest
*req
) = 0;
125 void unpause_with_new_config(rgw::sal::RGWRadosStore
* const store
,
126 rgw_auth_registry_ptr_t auth_registry
) {
128 this->auth_registry
= std::move(auth_registry
);
140 class RGWFCGXProcess
: public RGWProcess
{
144 /* have a bit more connections than threads so that requests are
145 * still accepted even if we're still processing older requests */
146 RGWFCGXProcess(CephContext
* const cct
,
147 RGWProcessEnv
* const pe
,
148 const int num_threads
,
149 RGWFrontendConfig
* const conf
)
150 : RGWProcess(cct
, pe
, num_threads
, conf
),
151 max_connections(num_threads
+ (num_threads
>> 3)) {
155 void handle_request(const DoutPrefixProvider
*dpp
, RGWRequest
* req
) override
;
158 class RGWProcessControlThread
: public Thread
{
159 RGWProcess
*pprocess
;
161 explicit RGWProcessControlThread(RGWProcess
*_pprocess
) : pprocess(_pprocess
) {}
163 void *entry() override
{
169 class RGWLoadGenProcess
: public RGWProcess
{
170 RGWAccessKey access_key
;
172 RGWLoadGenProcess(CephContext
* cct
, RGWProcessEnv
* pe
, int num_threads
,
173 RGWFrontendConfig
* _conf
) :
174 RGWProcess(cct
, pe
, num_threads
, _conf
) {}
177 void handle_request(const DoutPrefixProvider
*dpp
, RGWRequest
* req
) override
;
178 void gen_request(const string
& method
, const string
& resource
,
179 int content_length
, std::atomic
<bool>* fail_flag
);
181 void set_access_key(RGWAccessKey
& key
) { access_key
= key
; }
183 /* process stream request */
184 extern int process_request(rgw::sal::RGWRadosStore
* store
,
187 const std::string
& frontend_prefix
,
188 const rgw_auth_registry_t
& auth_registry
,
189 RGWRestfulIO
* client_io
,
192 rgw::dmclock::Scheduler
*scheduler
,
194 ceph::coarse_real_clock::duration
* latency
,
195 int* http_ret
= nullptr);
197 extern int rgw_process_authenticated(RGWHandler_REST
* handler
,
202 bool skip_retarget
= false);
204 #if defined(def_dout_subsys)
205 #undef def_dout_subsys
210 #endif /* RGW_PROCESS_H */