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_realm_reloader.h"
16 #include "rgw_auth_registry.h"
17 #include "rgw_sal_rados.h"
19 #define dout_context g_ceph_context
21 namespace rgw::dmclock
{
27 class RGWFrontendConfig
{
29 std::multimap
<std::string
, std::string
> config_map
;
30 std::string framework
;
32 int parse_config(const std::string
& config
,
33 std::multimap
<std::string
, std::string
>& config_map
);
36 explicit RGWFrontendConfig(const std::string
& config
)
41 const int ret
= parse_config(config
, config_map
);
42 return ret
< 0 ? ret
: 0;
45 void set_default_config(RGWFrontendConfig
& def_conf
);
47 std::optional
<std::string
> get_val(const std::string
& key
);
49 bool get_val(const std::string
& key
,
50 const std::string
& def_val
,
52 bool get_val(const std::string
& key
, int def_val
, int *out
);
54 std::string
get_val(const std::string
& key
,
55 const std::string
& def_val
) {
57 get_val(key
, def_val
, &out
);
61 const std::string
& get_config() {
65 std::multimap
<std::string
, std::string
>& get_config_map() {
69 std::string
get_framework() const {
76 virtual ~RGWFrontend() {}
78 virtual int init() = 0;
80 virtual int run() = 0;
81 virtual void stop() = 0;
82 virtual void join() = 0;
84 virtual void pause_for_new_config() = 0;
85 virtual void unpause_with_new_config(rgw::sal::Store
* store
,
86 rgw_auth_registry_ptr_t auth_registry
) = 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(rgw::sal::Store
* const store
,
125 rgw_auth_registry_ptr_t auth_registry
) override
{
127 env
.auth_registry
= auth_registry
;
128 pprocess
->unpause_with_new_config(store
, std::move(auth_registry
));
130 }; /* RGWProcessFrontend */
132 class RGWLoadGenFrontend
: public RGWProcessFrontend
, public DoutPrefixProvider
{
134 RGWLoadGenFrontend(RGWProcessEnv
& pe
, RGWFrontendConfig
*_conf
)
135 : RGWProcessFrontend(pe
, _conf
) {}
137 CephContext
*get_cct() const {
138 return env
.store
->ctx();
141 unsigned get_subsys() const
143 return ceph_subsys_rgw
;
146 std::ostream
& gen_prefix(std::ostream
& out
) const
148 return out
<< "rgw loadgen frontend: ";
151 int init() override
{
153 conf
->get_val("num_threads", g_conf()->rgw_thread_pool_size
, &num_threads
);
154 RGWLoadGenProcess
*pp
= new RGWLoadGenProcess(g_ceph_context
, &env
,
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
.store
->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::list
<RGWFrontend
*> &frontends
;
192 RGWRealmReloader::Pauser
* pauser
;
193 rgw::auth::ImplicitTenants
& implicit_tenants
;
196 RGWFrontendPauser(std::list
<RGWFrontend
*> &frontends
,
197 rgw::auth::ImplicitTenants
& implicit_tenants
,
198 RGWRealmReloader::Pauser
* pauser
= nullptr)
199 : frontends(frontends
),
201 implicit_tenants(implicit_tenants
) {
204 void pause() override
{
205 for (auto frontend
: frontends
)
206 frontend
->pause_for_new_config();
210 void resume(rgw::sal::Store
* store
) override
{
211 /* Initialize the registry of auth strategies which will coordinate
212 * the dynamic reconfiguration. */
213 auto auth_registry
= \
214 rgw::auth::StrategyRegistry::create(g_ceph_context
, implicit_tenants
, store
);
216 for (auto frontend
: frontends
)
217 frontend
->unpause_with_new_config(store
, auth_registry
);
219 pauser
->resume(store
);
223 #endif /* RGW_FRONTEND_H */