1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp
#pragma once
#include <map>
#include <string>
#include <vector>
#include "common/RWLock.h"
#include "rgw_request.h"
#include "rgw_process.h"
#include "rgw_process_env.h"
#include "rgw_realm_reloader.h"
#include "rgw_auth_registry.h"
#include "rgw_sal_rados.h"
#define dout_context g_ceph_context
namespace rgw::dmclock {
class SyncScheduler;
class ClientConfig;
class SchedulerCtx;
}
class RGWFrontendConfig {
std::string config;
std::multimap<std::string, std::string> config_map;
std::string framework;
int parse_config(const std::string& config,
std::multimap<std::string, std::string>& config_map);
public:
explicit RGWFrontendConfig(const std::string& config)
: config(config) {
}
int init() {
const int ret = parse_config(config, config_map);
return ret < 0 ? ret : 0;
}
void set_default_config(RGWFrontendConfig& def_conf);
std::optional<std::string> get_val(const std::string& key);
bool get_val(const std::string& key,
const std::string& def_val,
std::string* out);
bool get_val(const std::string& key, int def_val, int *out);
std::string get_val(const std::string& key,
const std::string& def_val) {
std::string out;
get_val(key, def_val, &out);
return out;
}
const std::string& get_config() {
return config;
}
std::multimap<std::string, std::string>& get_config_map() {
return config_map;
}
std::string get_framework() const {
return framework;
}
};
class RGWFrontend {
public:
virtual ~RGWFrontend() {}
virtual int init() = 0;
virtual int run() = 0;
virtual void stop() = 0;
virtual void join() = 0;
virtual void pause_for_new_config() = 0;
virtual void unpause_with_new_config() = 0;
};
class RGWProcessFrontend : public RGWFrontend {
protected:
RGWFrontendConfig* conf;
RGWProcess* pprocess;
RGWProcessEnv& env;
RGWProcessControlThread* thread;
public:
RGWProcessFrontend(RGWProcessEnv& pe, RGWFrontendConfig* _conf)
: conf(_conf), pprocess(nullptr), env(pe), thread(nullptr) {
}
~RGWProcessFrontend() override {
delete thread;
delete pprocess;
}
int run() override {
ceph_assert(pprocess); /* should have initialized by init() */
thread = new RGWProcessControlThread(pprocess);
thread->create("rgw_frontend");
return 0;
}
void stop() override;
void join() override {
thread->join();
}
void pause_for_new_config() override {
pprocess->pause();
}
void unpause_with_new_config() override {
pprocess->unpause_with_new_config();
}
}; /* RGWProcessFrontend */
class RGWLoadGenFrontend : public RGWProcessFrontend, public DoutPrefixProvider {
public:
RGWLoadGenFrontend(RGWProcessEnv& pe, RGWFrontendConfig *_conf)
: RGWProcessFrontend(pe, _conf) {}
CephContext *get_cct() const {
return env.driver->ctx();
}
unsigned get_subsys() const
{
return ceph_subsys_rgw;
}
std::ostream& gen_prefix(std::ostream& out) const
{
return out << "rgw loadgen frontend: ";
}
int init() override {
int num_threads;
conf->get_val("num_threads", g_conf()->rgw_thread_pool_size, &num_threads);
std::string uri_prefix;
conf->get_val("prefix", "", &uri_prefix);
RGWLoadGenProcess *pp = new RGWLoadGenProcess(
g_ceph_context, env, num_threads, std::move(uri_prefix), conf);
pprocess = pp;
std::string uid_str;
conf->get_val("uid", "", &uid_str);
if (uid_str.empty()) {
derr << "ERROR: uid param must be specified for loadgen frontend"
<< dendl;
return -EINVAL;
}
rgw_user uid(uid_str);
std::unique_ptr<rgw::sal::User> user = env.driver->get_user(uid);
int ret = user->load_user(this, null_yield);
if (ret < 0) {
derr << "ERROR: failed reading user info: uid=" << uid << " ret="
<< ret << dendl;
return ret;
}
auto aiter = user->get_info().access_keys.begin();
if (aiter == user->get_info().access_keys.end()) {
derr << "ERROR: user has no S3 access keys set" << dendl;
return -EINVAL;
}
pp->set_access_key(aiter->second);
return 0;
}
}; /* RGWLoadGenFrontend */
// FrontendPauser implementation for RGWRealmReloader
class RGWFrontendPauser : public RGWRealmReloader::Pauser {
std::vector<RGWFrontend*> &frontends;
RGWRealmReloader::Pauser* pauser;
public:
RGWFrontendPauser(std::vector<RGWFrontend*> &frontends,
RGWRealmReloader::Pauser* pauser = nullptr)
: frontends(frontends), pauser(pauser) {}
void pause() override {
for (auto frontend : frontends)
frontend->pause_for_new_config();
if (pauser)
pauser->pause();
}
void resume(rgw::sal::Driver* driver) override {
for (auto frontend : frontends)
frontend->unpause_with_new_config();
if (pauser)
pauser->resume(driver);
}
};
|