Skip to content

Commit 8ab3694

Browse files
committed
RGW/standalone: refactor RGWRealm with configstore
Signed-off-by: Ali Masarwa <[email protected]>
1 parent de90732 commit 8ab3694

File tree

5 files changed

+72
-146
lines changed

5 files changed

+72
-146
lines changed

src/rgw/driver/rados/rgw_rest_realm.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void RGWOp_Period_Post::execute(optional_yield y)
133133
// period that we haven't restarted with yet. we also don't want to modify
134134
// the objects in use by RGWRados
135135
RGWRealm realm(period.get_realm());
136-
op_ret = realm.init(this, cct, static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj, y);
136+
op_ret = rgw::read_realm(this, y, cfgstore.get(), realm.get_id(), realm.get_name(), realm);
137137
if (op_ret < 0) {
138138
ldpp_dout(this, -1) << "failed to read current realm: "
139139
<< cpp_strerror(-op_ret) << dendl;
@@ -273,7 +273,9 @@ void RGWOp_Period_Post::send_response()
273273
if (notify_realm) {
274274
// trigger realm reload after sending the response, because reload may
275275
// race to close this connection
276-
notify_realm->notify_new_period(this, period, s->yield);
276+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
277+
auto cfgstore = DriverManager::create_config_store(this, config_store_type);
278+
(void) cfgstore->realm_notify_new_period(this, null_yield, period);
277279
}
278280
}
279281

@@ -320,7 +322,9 @@ void RGWOp_Realm_Get::execute(optional_yield y)
320322

321323
// read realm
322324
realm.reset(new RGWRealm(id, name));
323-
op_ret = realm->init(this, g_ceph_context, static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj, y);
325+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
326+
auto cfgstore = DriverManager::create_config_store(this, config_store_type);
327+
op_ret = rgw::read_realm(this, y, cfgstore.get(), realm->get_id(), realm->get_name(), *realm);
324328
if (op_ret < 0)
325329
ldpp_dout(this, -1) << "failed to read realm id=" << id
326330
<< " name=" << name << dendl;
@@ -361,8 +365,8 @@ void RGWOp_Realm_List::execute(optional_yield y)
361365
{
362366
{
363367
// read default realm
364-
RGWRealm realm(driver->ctx(), static_cast<rgw::sal::RadosStore*>(driver)->svc()->sysobj);
365-
[[maybe_unused]] int ret = realm.read_default_id(this, default_id, y);
368+
RGWRealm realm(driver->ctx());
369+
default_id = realm.get_default_oid();
366370
}
367371
op_ret = static_cast<rgw::sal::RadosStore*>(driver)->svc()->zone->list_realms(this, realms);
368372
if (op_ret < 0)

src/rgw/driver/rados/rgw_zone.h

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -525,47 +525,56 @@ WRITE_CLASS_ENCODER(RGWPeriodConfig)
525525
class RGWRealm;
526526
class RGWPeriod;
527527

528-
class RGWRealm : public RGWSystemMetaObj
528+
class RGWRealm
529529
{
530530
public:
531+
std::string id;
532+
std::string name;
533+
534+
CephContext *cct{nullptr};
535+
531536
std::string current_period;
532537
epoch_t epoch{0}; //< realm epoch, incremented for each new period
533538

534-
int create_control(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y);
535-
int delete_control(const DoutPrefixProvider *dpp, optional_yield y);
536539
public:
537540
RGWRealm() {}
538-
RGWRealm(const std::string& _id, const std::string& _name = "") : RGWSystemMetaObj(_id, _name) {}
539-
RGWRealm(CephContext *_cct, RGWSI_SysObj *_sysobj_svc): RGWSystemMetaObj(_cct, _sysobj_svc) {}
540-
RGWRealm(const std::string& _name, CephContext *_cct, RGWSI_SysObj *_sysobj_svc): RGWSystemMetaObj(_name, _cct, _sysobj_svc){}
541-
virtual ~RGWRealm() override;
541+
RGWRealm(const std::string& _id, const std::string& _name = "") : id(_id), name(_name) {}
542+
RGWRealm(CephContext *_cct): cct(_cct) {}
543+
RGWRealm(const std::string& _name, CephContext *_cct, RGWSI_SysObj *_sysobj_svc): name(_name), cct(_cct){}
542544

543-
void encode(bufferlist& bl) const override {
545+
const std::string& get_name() const { return name; }
546+
const std::string& get_id() const { return id; }
547+
548+
void set_name(const std::string& _name) { name = _name;}
549+
void set_id(const std::string& _id) { id = _id;}
550+
void clear_id() { id.clear(); }
551+
552+
virtual ~RGWRealm();
553+
554+
void encode(bufferlist& bl) const {
544555
ENCODE_START(1, 1, bl);
545-
RGWSystemMetaObj::encode(bl);
556+
encode(id, bl);
557+
encode(name, bl);
546558
encode(current_period, bl);
547559
encode(epoch, bl);
548560
ENCODE_FINISH(bl);
549561
}
550562

551-
void decode(bufferlist::const_iterator& bl) override {
563+
void decode(bufferlist::const_iterator& bl) {
552564
DECODE_START(1, bl);
553-
RGWSystemMetaObj::decode(bl);
565+
decode(id, bl);
566+
decode(name, bl);
554567
decode(current_period, bl);
555568
decode(epoch, bl);
556569
DECODE_FINISH(bl);
557570
}
558571

559-
int create(const DoutPrefixProvider *dpp, optional_yield y, bool exclusive = true) override;
560-
int delete_obj(const DoutPrefixProvider *dpp, optional_yield y);
561-
rgw_pool get_pool(CephContext *cct) const override;
562-
const std::string get_default_oid(bool old_format = false) const override;
563-
const std::string& get_names_oid_prefix() const override;
564-
const std::string& get_info_oid_prefix(bool old_format = false) const override;
565-
std::string get_predefined_id(CephContext *cct) const override;
566-
const std::string& get_predefined_name(CephContext *cct) const override;
567-
568-
using RGWSystemMetaObj::read_id; // expose as public for radosgw-admin
572+
rgw_pool get_pool(CephContext *cct) const;
573+
const std::string get_default_oid(bool old_format = false) const;
574+
const std::string& get_names_oid_prefix() const;
575+
const std::string& get_info_oid_prefix(bool old_format = false) const;
576+
std::string get_predefined_id(CephContext *cct) const;
577+
const std::string& get_predefined_name(CephContext *cct) const;
569578

570579
void dump(Formatter *f) const;
571580
void decode_json(JSONObj *obj);
@@ -582,10 +591,6 @@ class RGWRealm : public RGWSystemMetaObj
582591
epoch_t get_epoch() const { return epoch; }
583592

584593
std::string get_control_oid() const;
585-
/// send a notify on the realm control object
586-
int notify_zone(const DoutPrefixProvider *dpp, bufferlist& bl, optional_yield y);
587-
/// notify the zone of a new period
588-
int notify_new_period(const DoutPrefixProvider *dpp, const RGWPeriod& period, optional_yield y);
589594

590595
int find_zone(const DoutPrefixProvider *dpp,
591596
const rgw_zone_id& zid,

src/rgw/rgw_realm.cc

Lines changed: 13 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -48,84 +48,6 @@ const string& RGWRealm::get_predefined_name(CephContext *cct) const {
4848
return cct->_conf->rgw_realm;
4949
}
5050

51-
int RGWRealm::create(const DoutPrefixProvider *dpp, optional_yield y, bool exclusive)
52-
{
53-
int ret = RGWSystemMetaObj::create(dpp, y, exclusive);
54-
if (ret < 0) {
55-
ldpp_dout(dpp, 0) << "ERROR creating new realm object " << name << ": " << cpp_strerror(-ret) << dendl;
56-
return ret;
57-
}
58-
// create the control object for watch/notify
59-
ret = create_control(dpp, exclusive, y);
60-
if (ret < 0) {
61-
ldpp_dout(dpp, 0) << "ERROR creating control for new realm " << name << ": " << cpp_strerror(-ret) << dendl;
62-
return ret;
63-
}
64-
RGWPeriod period;
65-
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
66-
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
67-
if (current_period.empty()) {
68-
/* create new period for the realm */
69-
ret = cfgstore->read_period(dpp, y, period.get_id(), period.get_epoch(), period);
70-
if (ret < 0 ) {
71-
return ret;
72-
}
73-
ret = cfgstore->create_period(dpp, y, true, period);
74-
if (ret < 0) {
75-
ldpp_dout(dpp, 0) << "ERROR: creating new period for realm " << name << ": " << cpp_strerror(-ret) << dendl;
76-
return ret;
77-
}
78-
} else {
79-
period = RGWPeriod(current_period, 0);
80-
ret = cfgstore->read_period(dpp, y, period.get_id(), period.get_epoch(), period);
81-
if (ret < 0) {
82-
ldpp_dout(dpp, 0) << "ERROR: failed to init period " << current_period << dendl;
83-
return ret;
84-
}
85-
}
86-
ret = set_current_period(dpp, period, y);
87-
if (ret < 0) {
88-
ldpp_dout(dpp, 0) << "ERROR: failed set current period " << current_period << dendl;
89-
return ret;
90-
}
91-
// try to set as default. may race with another create, so pass exclusive=true
92-
// so we don't override an existing default
93-
ret = set_as_default(dpp, y, true);
94-
if (ret < 0 && ret != -EEXIST) {
95-
ldpp_dout(dpp, 0) << "WARNING: failed to set realm as default realm, ret=" << ret << dendl;
96-
}
97-
98-
return 0;
99-
}
100-
101-
int RGWRealm::delete_obj(const DoutPrefixProvider *dpp, optional_yield y)
102-
{
103-
int ret = RGWSystemMetaObj::delete_obj(dpp, y);
104-
if (ret < 0) {
105-
return ret;
106-
}
107-
return delete_control(dpp, y);
108-
}
109-
110-
int RGWRealm::create_control(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y)
111-
{
112-
auto pool = rgw_pool{get_pool(cct)};
113-
auto oid = get_control_oid();
114-
bufferlist bl;
115-
auto sysobj = sysobj_svc->get_obj(rgw_raw_obj{pool, oid});
116-
return sysobj.wop()
117-
.set_exclusive(exclusive)
118-
.write(dpp, bl, y);
119-
}
120-
121-
int RGWRealm::delete_control(const DoutPrefixProvider *dpp, optional_yield y)
122-
{
123-
auto pool = rgw_pool{get_pool(cct)};
124-
auto obj = rgw_raw_obj{pool, get_control_oid()};
125-
auto sysobj = sysobj_svc->get_obj(obj);
126-
return sysobj.wop().remove(dpp, y);
127-
}
128-
12951
rgw_pool RGWRealm::get_pool(CephContext *cct) const
13052
{
13153
if (cct->_conf->rgw_realm_root_pool.empty()) {
@@ -170,14 +92,20 @@ int RGWRealm::set_current_period(const DoutPrefixProvider *dpp, RGWPeriod& perio
17092
epoch = period.get_realm_epoch();
17193
current_period = period.get_id();
17294

173-
int ret = update(dpp, y);
95+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
96+
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
97+
std::unique_ptr<rgw::sal::RealmWriter> writer;
98+
int ret = cfgstore->create_realm(dpp, y, false, *this, &writer);
99+
if (ret < 0) {
100+
ldpp_dout(dpp, 0) << "ERROR: realm create: " << cpp_strerror(-ret) << dendl;
101+
return ret;
102+
}
103+
ret = rgw::realm_set_current_period(dpp, y, cfgstore.get(), *writer, *this, period);
174104
if (ret < 0) {
175105
ldpp_dout(dpp, 0) << "ERROR: period update: " << cpp_strerror(-ret) << dendl;
176106
return ret;
177107
}
178108

179-
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
180-
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
181109
ret = rgw::reflect_period(dpp, y, cfgstore.get(), period);
182110
if (ret < 0) {
183111
ldpp_dout(dpp, 0) << "ERROR: period.reflect(): " << cpp_strerror(-ret) << dendl;
@@ -192,30 +120,6 @@ string RGWRealm::get_control_oid() const
192120
return get_info_oid_prefix() + id + ".control";
193121
}
194122

195-
int RGWRealm::notify_zone(const DoutPrefixProvider *dpp, bufferlist& bl, optional_yield y)
196-
{
197-
rgw_pool pool{get_pool(cct)};
198-
auto sysobj = sysobj_svc->get_obj(rgw_raw_obj{pool, get_control_oid()});
199-
int ret = sysobj.wn().notify(dpp, bl, 0, nullptr, y);
200-
if (ret < 0) {
201-
return ret;
202-
}
203-
return 0;
204-
}
205-
206-
int RGWRealm::notify_new_period(const DoutPrefixProvider *dpp, const RGWPeriod& period, optional_yield y)
207-
{
208-
bufferlist bl;
209-
using ceph::encode;
210-
// push the period to dependent zonegroups/zones
211-
encode(RGWRealmNotify::ZonesNeedPeriod, bl);
212-
encode(period, bl);
213-
// reload the gateway with the new period
214-
encode(RGWRealmNotify::Reload, bl);
215-
216-
return notify_zone(dpp, bl, y);
217-
}
218-
219123

220124
int RGWRealm::find_zone(const DoutPrefixProvider *dpp,
221125
const rgw_zone_id& zid,
@@ -256,15 +160,17 @@ void RGWRealm::generate_test_instances(list<RGWRealm*> &o)
256160

257161
void RGWRealm::dump(Formatter *f) const
258162
{
259-
RGWSystemMetaObj::dump(f);
163+
encode_json("id", id , f);
164+
encode_json("name", name , f);
260165
encode_json("current_period", current_period, f);
261166
encode_json("epoch", epoch, f);
262167
}
263168

264169

265170
void RGWRealm::decode_json(JSONObj *obj)
266171
{
267-
RGWSystemMetaObj::decode_json(obj);
172+
JSONDecoder::decode_json("id", id, obj);
173+
JSONDecoder::decode_json("name", name, obj);
268174
JSONDecoder::decode_json("current_period", current_period, obj);
269175
JSONDecoder::decode_json("epoch", epoch, obj);
270176
}

src/rgw/rgw_zone.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "common/errno.h"
77

88
#include "rgw_zone.h"
9+
#include "rgw_sal.h"
910
#include "rgw_sal_config.h"
1011
#include "rgw_sync.h"
1112

@@ -202,7 +203,9 @@ int RGWZoneGroup::read_default_id(const DoutPrefixProvider *dpp, string& default
202203
if (realm_id.empty()) {
203204
/* try using default realm */
204205
RGWRealm realm;
205-
int ret = realm.init(dpp, cct, sysobj_svc, y);
206+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
207+
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
208+
int ret = rgw::read_realm(dpp, y, cfgstore.get(), realm.get_id(), realm.get_name(), realm);
206209
// no default realm exist
207210
if (ret < 0) {
208211
return read_id(dpp, default_zonegroup_name, default_id, y);
@@ -386,7 +389,9 @@ int RGWZoneParams::read_default_id(const DoutPrefixProvider *dpp, string& defaul
386389
if (realm_id.empty()) {
387390
/* try using default realm */
388391
RGWRealm realm;
389-
int ret = realm.init(dpp, cct, sysobj_svc, y);
392+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
393+
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
394+
int ret = rgw::read_realm(dpp, y, cfgstore.get(), realm.get_id(), realm.get_name(), realm);
390395
//no default realm exist
391396
if (ret < 0) {
392397
return read_id(dpp, default_zone_name, default_id, y);
@@ -403,7 +408,9 @@ int RGWZoneParams::set_as_default(const DoutPrefixProvider *dpp, optional_yield
403408
if (realm_id.empty()) {
404409
/* try using default realm */
405410
RGWRealm realm;
406-
int ret = realm.init(dpp, cct, sysobj_svc, y);
411+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
412+
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
413+
int ret = rgw::read_realm(dpp, y, cfgstore.get(), realm.get_id(), realm.get_name(), realm);
407414
if (ret < 0) {
408415
ldpp_dout(dpp, 10) << "could not read realm id: " << cpp_strerror(-ret) << dendl;
409416
return -EINVAL;
@@ -1204,7 +1211,9 @@ int RGWZoneGroup::set_as_default(const DoutPrefixProvider *dpp, optional_yield y
12041211
if (realm_id.empty()) {
12051212
/* try using default realm */
12061213
RGWRealm realm;
1207-
int ret = realm.init(dpp, cct, sysobj_svc, y);
1214+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
1215+
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
1216+
int ret = rgw::read_realm(dpp, y, cfgstore.get(), realm.get_id(), realm.get_name(), realm);
12081217
if (ret < 0) {
12091218
ldpp_dout(dpp, 10) << "could not read realm id: " << cpp_strerror(-ret) << dendl;
12101219
return -EINVAL;

src/rgw/services/svc_zone.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ int RGWSI_Zone::search_realm_with_zone(const DoutPrefixProvider *dpp,
104104
for (auto& realm_name : realms) {
105105
string realm_id;
106106
RGWRealm realm(realm_id, realm_name);
107-
r = realm.init(dpp, cct, sysobj_svc, y);
107+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
108+
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
109+
r = rgw::read_realm(dpp, y, cfgstore.get(), realm_id, realm_name, realm);
108110
if (r < 0) {
109111
ldpp_dout(dpp, 0) << "WARNING: can't open realm " << realm_name << ": " << cpp_strerror(-r) << " ... skipping" << dendl;
110112
continue;
@@ -136,14 +138,14 @@ int RGWSI_Zone::do_start(optional_yield y, const DoutPrefixProvider *dpp)
136138

137139
assert(sysobj_svc->is_started()); /* if not then there's ordering issue */
138140

139-
ret = realm->init(dpp, cct, sysobj_svc, y);
141+
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
142+
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
143+
ret = rgw::read_realm(dpp, y, cfgstore.get(), realm->get_id(), realm->get_name(), *realm);
140144
if (ret < 0 && ret != -ENOENT) {
141145
ldpp_dout(dpp, 0) << "failed reading realm info: ret "<< ret << " " << cpp_strerror(-ret) << dendl;
142146
return ret;
143147
}
144148

145-
auto config_store_type = g_conf().get_val<std::string>("rgw_config_store");
146-
auto cfgstore = DriverManager::create_config_store(dpp, config_store_type);
147149
ldpp_dout(dpp, 20) << "realm " << realm->get_name() << " " << realm->get_id() << dendl;
148150
current_period->set_realm_id(realm->get_id());
149151
ret = cfgstore->read_period(dpp, y, current_period->get_id(), current_period->epoch, *current_period);
@@ -425,7 +427,7 @@ int RGWSI_Zone::list_zones(const DoutPrefixProvider *dpp, list<string>& zones)
425427

426428
int RGWSI_Zone::list_realms(const DoutPrefixProvider *dpp, list<string>& realms)
427429
{
428-
RGWRealm realm(cct, sysobj_svc);
430+
RGWRealm realm(cct);
429431
RGWSI_SysObj::Pool syspool = sysobj_svc->get_pool(realm.get_pool(cct));
430432

431433
return syspool.list_prefixed_objs(dpp, realm_names_oid_prefix, &realms);

0 commit comments

Comments
 (0)