]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_frontend.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
10 #include "common/RWLock.h"
12 #include "rgw_request.h"
13 #include "rgw_process.h"
14 #include "rgw_process_env.h"
15 #include "rgw_realm_reloader.h"
17 #include "rgw_auth_registry.h"
18 #include "rgw_sal_rados.h"
20 #define dout_context g_ceph_context
22 namespace rgw::dmclock
{
28 class RGWFrontendConfig
{
30 std::multimap
<std::string
, std::string
> config_map
;
31 std::string framework
;
33 int parse_config(const std::string
& config
,
34 std::multimap
<std::string
, std::string
>& config_map
);
37 explicit RGWFrontendConfig(const std::string
& config
)
42 const int ret
= parse_config(config
, config_map
);
43 return ret
< 0 ? ret
: 0;
46 void set_default_config(RGWFrontendConfig
& def_conf
);
48 std::optional
<std::string
> get_val(const std::string
& key
);
50 bool get_val(const std::string
& key
,
51 const std::string
& def_val
,
53 bool get_val(const std::string
& key
, int def_val
, int *out
);
55 std::string
get_val(const std::string
& key
,
56 const std::string
& def_val
) {
58 get_val(key
, def_val
, &out
);
62 const std::string
& get_config() {
66 std::multimap
<std::string
, std::string
>& get_config_map() {
70 std::string
get_framework() const {
77 virtual ~RGWFrontend() {}
79 virtual int init() = 0;
81 virtual int run() = 0;
82 virtual void stop() = 0;
83 virtual void join() = 0;
85 virtual void pause_for_new_config() = 0;
86 virtual void unpause_with_new_config() = 0;
90 class RGWProcessFrontend
: public RGWFrontend
{
92 RGWFrontendConfig
* conf
;
95 RGWProcessControlThread
* thread
;
98 RGWProcessFrontend(RGWProcessEnv
& pe
, RGWFrontendConfig
* _conf
)
99 : conf(_conf
), pprocess(nullptr), env(pe
), thread(nullptr) {
102 ~RGWProcessFrontend() override
{
108 ceph_assert(pprocess
); /* should have initialized by init() */
109 thread
= new RGWProcessControlThread(pprocess
);
110 thread
->create("rgw_frontend");
114 void stop() override
;
116 void join() override
{
120 void pause_for_new_config() override
{
124 void unpause_with_new_config() override
{
125 pprocess
->unpause_with_new_config();
127 }; /* RGWProcessFrontend */
129 class RGWLoadGenFrontend
: public RGWProcessFrontend
, public DoutPrefixProvider
{
131 RGWLoadGenFrontend(RGWProcessEnv
& pe
, RGWFrontendConfig
*_conf
)
132 : RGWProcessFrontend(pe
, _conf
) {}
134 CephContext
*get_cct() const {
135 return env
.driver
->ctx();
138 unsigned get_subsys() const
140 return ceph_subsys_rgw
;
143 std::ostream
& gen_prefix(std::ostream
& out
) const
145 return out
<< "rgw loadgen frontend: ";
148 int init() override
{
150 conf
->get_val("num_threads", g_conf()->rgw_thread_pool_size
, &num_threads
);
151 std::string uri_prefix
;
152 conf
->get_val("prefix", "", &uri_prefix
);
154 RGWLoadGenProcess
*pp
= new RGWLoadGenProcess(
155 g_ceph_context
, env
, num_threads
, std::move(uri_prefix
), conf
);
160 conf
->get_val("uid", "", &uid_str
);
161 if (uid_str
.empty()) {
162 derr
<< "ERROR: uid param must be specified for loadgen frontend"
167 rgw_user
uid(uid_str
);
168 std::unique_ptr
<rgw::sal::User
> user
= env
.driver
->get_user(uid
);
170 int ret
= user
->load_user(this, null_yield
);
172 derr
<< "ERROR: failed reading user info: uid=" << uid
<< " ret="
177 auto aiter
= user
->get_info().access_keys
.begin();
178 if (aiter
== user
->get_info().access_keys
.end()) {
179 derr
<< "ERROR: user has no S3 access keys set" << dendl
;
183 pp
->set_access_key(aiter
->second
);
187 }; /* RGWLoadGenFrontend */
189 // FrontendPauser implementation for RGWRealmReloader
190 class RGWFrontendPauser
: public RGWRealmReloader::Pauser
{
191 std::vector
<RGWFrontend
*> &frontends
;
192 RGWRealmReloader::Pauser
* pauser
;
195 RGWFrontendPauser(std::vector
<RGWFrontend
*> &frontends
,
196 RGWRealmReloader::Pauser
* pauser
= nullptr)
197 : frontends(frontends
), pauser(pauser
) {}
199 void pause() override
{
200 for (auto frontend
: frontends
)
201 frontend
->pause_for_new_config();
205 void resume(rgw::sal::Driver
* driver
) override
{
206 for (auto frontend
: frontends
)
207 frontend
->unpause_with_new_config();
209 pauser
->resume(driver
);