Skip to content

Commit 4bb08c9

Browse files
committed
RGW/standalone: refactor RGWZoneGroup with configstore
Signed-off-by: Ali Masarwa <[email protected]>
1 parent 09383ab commit 4bb08c9

File tree

4 files changed

+52
-363
lines changed

4 files changed

+52
-363
lines changed

src/rgw/driver/rados/rgw_zone.cc

Lines changed: 0 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -43,77 +43,6 @@ void RGWDefaultZoneGroupInfo::decode_json(JSONObj *obj) {
4343
}
4444
}
4545

46-
int RGWZoneGroup::create_default(const DoutPrefixProvider *dpp, optional_yield y, bool old_format)
47-
{
48-
name = default_zonegroup_name;
49-
api_name = default_zonegroup_name;
50-
is_master = true;
51-
52-
RGWZoneGroupPlacementTarget placement_target;
53-
placement_target.name = "default-placement";
54-
placement_targets[placement_target.name] = placement_target;
55-
default_placement.name = "default-placement";
56-
57-
RGWZoneParams zone_params(default_zone_name);
58-
59-
int r = zone_params.init(dpp, cct, sysobj_svc, y, false);
60-
if (r < 0) {
61-
ldpp_dout(dpp, 0) << "create_default: error initializing zone params: " << cpp_strerror(-r) << dendl;
62-
return r;
63-
}
64-
65-
r = zone_params.create_default(dpp, y);
66-
if (r < 0 && r != -EEXIST) {
67-
ldpp_dout(dpp, 0) << "create_default: error in create_default zone params: " << cpp_strerror(-r) << dendl;
68-
return r;
69-
} else if (r == -EEXIST) {
70-
ldpp_dout(dpp, 10) << "zone_params::create_default() returned -EEXIST, we raced with another default zone_params creation" << dendl;
71-
zone_params.clear_id();
72-
r = zone_params.init(dpp, cct, sysobj_svc, y);
73-
if (r < 0) {
74-
ldpp_dout(dpp, 0) << "create_default: error in init existing zone params: " << cpp_strerror(-r) << dendl;
75-
return r;
76-
}
77-
ldpp_dout(dpp, 20) << "zone_params::create_default() " << zone_params.get_name() << " id " << zone_params.get_id()
78-
<< dendl;
79-
}
80-
81-
RGWZone& default_zone = zones[zone_params.get_id()];
82-
default_zone.name = zone_params.get_name();
83-
default_zone.id = zone_params.get_id();
84-
master_zone = default_zone.id;
85-
86-
// initialize supported zone features
87-
default_zone.supported_features.insert(rgw::zone_features::supported.begin(),
88-
rgw::zone_features::supported.end());
89-
// enable default zonegroup features
90-
enabled_features.insert(rgw::zone_features::enabled.begin(),
91-
rgw::zone_features::enabled.end());
92-
93-
r = create(dpp, y);
94-
if (r < 0 && r != -EEXIST) {
95-
ldpp_dout(dpp, 0) << "error storing zone group info: " << cpp_strerror(-r) << dendl;
96-
return r;
97-
}
98-
99-
if (r == -EEXIST) {
100-
ldpp_dout(dpp, 10) << "create_default() returned -EEXIST, we raced with another zonegroup creation" << dendl;
101-
id.clear();
102-
r = init(dpp, cct, sysobj_svc, y);
103-
if (r < 0) {
104-
return r;
105-
}
106-
}
107-
108-
if (old_format) {
109-
name = id;
110-
}
111-
112-
post_process_params(dpp, y);
113-
114-
return 0;
115-
}
116-
11746
int RGWZoneGroup::equals(const string& other_zonegroup) const
11847
{
11948
if (is_master && other_zonegroup.empty())
@@ -122,168 +51,6 @@ int RGWZoneGroup::equals(const string& other_zonegroup) const
12251
return (id == other_zonegroup);
12352
}
12453

125-
int RGWZoneGroup::add_zone(const DoutPrefixProvider *dpp,
126-
const RGWZoneParams& zone_params, bool *is_master, bool *read_only,
127-
const list<string>& endpoints, const string *ptier_type,
128-
bool *psync_from_all, list<string>& sync_from, list<string>& sync_from_rm,
129-
string *predirect_zone, std::optional<int> bucket_index_max_shards,
130-
RGWSyncModulesManager *sync_mgr,
131-
const rgw::zone_features::set& enable_features,
132-
const rgw::zone_features::set& disable_features,
133-
optional_yield y)
134-
{
135-
auto& zone_id = zone_params.get_id();
136-
auto& zone_name = zone_params.get_name();
137-
138-
// check for duplicate zone name on insert
139-
if (!zones.count(zone_id)) {
140-
for (const auto& zone : zones) {
141-
if (zone.second.name == zone_name) {
142-
ldpp_dout(dpp, 0) << "ERROR: found existing zone name " << zone_name
143-
<< " (" << zone.first << ") in zonegroup " << get_name() << dendl;
144-
return -EEXIST;
145-
}
146-
}
147-
}
148-
149-
if (is_master) {
150-
if (*is_master) {
151-
if (!master_zone.empty() && master_zone != zone_id) {
152-
ldpp_dout(dpp, 0) << "NOTICE: overriding master zone: " << master_zone << dendl;
153-
}
154-
master_zone = zone_id;
155-
} else if (master_zone == zone_id) {
156-
master_zone.clear();
157-
}
158-
}
159-
160-
RGWZone& zone = zones[zone_id];
161-
zone.name = zone_name;
162-
zone.id = zone_id;
163-
if (!endpoints.empty()) {
164-
zone.endpoints = endpoints;
165-
}
166-
if (read_only) {
167-
zone.read_only = *read_only;
168-
}
169-
if (ptier_type) {
170-
zone.tier_type = *ptier_type;
171-
if (!sync_mgr->get_module(*ptier_type, nullptr)) {
172-
ldpp_dout(dpp, 0) << "ERROR: could not found sync module: " << *ptier_type
173-
<< ", valid sync modules: "
174-
<< sync_mgr->get_registered_module_names()
175-
<< dendl;
176-
return -ENOENT;
177-
}
178-
}
179-
180-
if (psync_from_all) {
181-
zone.sync_from_all = *psync_from_all;
182-
}
183-
184-
if (predirect_zone) {
185-
zone.redirect_zone = *predirect_zone;
186-
}
187-
188-
if (bucket_index_max_shards) {
189-
zone.bucket_index_max_shards = *bucket_index_max_shards;
190-
}
191-
192-
for (auto add : sync_from) {
193-
zone.sync_from.insert(add);
194-
}
195-
196-
for (auto rm : sync_from_rm) {
197-
zone.sync_from.erase(rm);
198-
}
199-
200-
zone.supported_features.insert(enable_features.begin(),
201-
enable_features.end());
202-
203-
for (const auto& feature : disable_features) {
204-
if (enabled_features.contains(feature)) {
205-
lderr(cct) << "ERROR: Cannot disable zone feature \"" << feature
206-
<< "\" until it's been disabled in zonegroup " << name << dendl;
207-
return -EINVAL;
208-
}
209-
auto i = zone.supported_features.find(feature);
210-
if (i == zone.supported_features.end()) {
211-
ldout(cct, 1) << "WARNING: zone feature \"" << feature
212-
<< "\" was not enabled in zone " << zone.name << dendl;
213-
continue;
214-
}
215-
zone.supported_features.erase(i);
216-
}
217-
218-
post_process_params(dpp, y);
219-
220-
return update(dpp,y);
221-
}
222-
223-
224-
int RGWZoneGroup::rename_zone(const DoutPrefixProvider *dpp,
225-
const RGWZoneParams& zone_params,
226-
optional_yield y)
227-
{
228-
RGWZone& zone = zones[zone_params.get_id()];
229-
zone.name = zone_params.get_name();
230-
231-
return update(dpp, y);
232-
}
233-
234-
void RGWZoneGroup::post_process_params(const DoutPrefixProvider *dpp, optional_yield y)
235-
{
236-
bool log_data = zones.size() > 1;
237-
238-
if (master_zone.empty()) {
239-
auto iter = zones.begin();
240-
if (iter != zones.end()) {
241-
master_zone = iter->first;
242-
}
243-
}
244-
245-
for (auto& item : zones) {
246-
RGWZone& zone = item.second;
247-
zone.log_data = log_data;
248-
249-
RGWZoneParams zone_params(zone.id, zone.name);
250-
int ret = zone_params.init(dpp, cct, sysobj_svc, y);
251-
if (ret < 0) {
252-
ldpp_dout(dpp, 0) << "WARNING: could not read zone params for zone id=" << zone.id << " name=" << zone.name << dendl;
253-
continue;
254-
}
255-
256-
for (auto& pitem : zone_params.placement_pools) {
257-
const string& placement_name = pitem.first;
258-
if (placement_targets.find(placement_name) == placement_targets.end()) {
259-
RGWZoneGroupPlacementTarget placement_target;
260-
placement_target.name = placement_name;
261-
placement_targets[placement_name] = placement_target;
262-
}
263-
}
264-
}
265-
266-
if (default_placement.empty() && !placement_targets.empty()) {
267-
default_placement.init(placement_targets.begin()->first, RGW_STORAGE_CLASS_STANDARD);
268-
}
269-
}
270-
271-
int RGWZoneGroup::remove_zone(const DoutPrefixProvider *dpp, const std::string& zone_id, optional_yield y)
272-
{
273-
auto iter = zones.find(zone_id);
274-
if (iter == zones.end()) {
275-
ldpp_dout(dpp, 0) << "zone id " << zone_id << " is not a part of zonegroup "
276-
<< name << dendl;
277-
return -ENOENT;
278-
}
279-
280-
zones.erase(iter);
281-
282-
post_process_params(dpp, y);
283-
284-
return update(dpp, y);
285-
}
286-
28754
void RGWDefaultSystemMetaObjInfo::dump(Formatter *f) const {
28855
encode_json("default_id", default_id, f);
28956
}

src/rgw/driver/rados/rgw_zone.h

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ struct RGWZoneParams : RGWSystemMetaObj {
317317
};
318318
WRITE_CLASS_ENCODER(RGWZoneParams)
319319

320-
struct RGWZoneGroup : public RGWSystemMetaObj {
320+
struct RGWZoneGroup {
321+
std::string id;
322+
std::string name;
321323
std::string api_name;
322324
std::list<std::string> endpoints;
323325
bool is_master = false;
@@ -351,24 +353,25 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
351353

352354
rgw_sync_policy_info sync_policy;
353355
rgw::zone_features::set enabled_features;
356+
CephContext *cct{nullptr};
354357

355358
RGWZoneGroup(): is_master(false){}
356-
RGWZoneGroup(const std::string &id, const std::string &name):RGWSystemMetaObj(id, name) {}
357-
explicit RGWZoneGroup(const std::string &_name):RGWSystemMetaObj(_name) {}
358-
RGWZoneGroup(const std::string &_name, bool _is_master, CephContext *cct, RGWSI_SysObj* sysobj_svc,
359-
const std::string& _realm_id, const std::list<std::string>& _endpoints)
360-
: RGWSystemMetaObj(_name, cct , sysobj_svc), endpoints(_endpoints), is_master(_is_master),
361-
realm_id(_realm_id) {}
362-
virtual ~RGWZoneGroup();
359+
RGWZoneGroup(const std::string &_id, const std::string &_name):id(_id), name(_name) {}
360+
explicit RGWZoneGroup(const std::string &_name):name(_name) {}
361+
RGWZoneGroup(const std::string &_name, bool _is_master, const std::string& _realm_id,
362+
const std::list<std::string>& _endpoints)
363+
: name(_name), endpoints(_endpoints), is_master(_is_master), realm_id(_realm_id) {}
364+
365+
const std::string& get_name() const { return name; }
366+
const std::string& get_id() const { return id; }
367+
368+
void set_name(const std::string& _name) { name = _name;}
369+
void set_id(const std::string& _id) { id = _id;}
370+
void clear_id() { id.clear(); }
363371

364372
bool is_master_zonegroup() const { return is_master;}
365-
void update_master(const DoutPrefixProvider *dpp, bool _is_master, optional_yield y) {
366-
is_master = _is_master;
367-
post_process_params(dpp, y);
368-
}
369-
void post_process_params(const DoutPrefixProvider *dpp, optional_yield y);
370373

371-
void encode(bufferlist& bl) const override {
374+
void encode(bufferlist& bl) const {
372375
ENCODE_START(6, 1, bl);
373376
encode(name, bl);
374377
encode(api_name, bl);
@@ -380,14 +383,21 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
380383
encode(default_placement, bl);
381384
encode(hostnames, bl);
382385
encode(hostnames_s3website, bl);
383-
RGWSystemMetaObj::encode(bl);
386+
{
387+
// these used to be wrapped by RGWSystemMetaObj::encode(),
388+
// so the extra ENCODE_START/ENCODE_FINISH are preserved
389+
ENCODE_START(1, 1, bl);
390+
encode(id, bl);
391+
encode(name, bl);
392+
ENCODE_FINISH(bl);
393+
}
384394
encode(realm_id, bl);
385395
encode(sync_policy, bl);
386396
encode(enabled_features, bl);
387397
ENCODE_FINISH(bl);
388398
}
389399

390-
void decode(bufferlist::const_iterator& bl) override {
400+
void decode(bufferlist::const_iterator& bl) {
391401
DECODE_START(6, bl);
392402
decode(name, bl);
393403
decode(api_name, bl);
@@ -404,7 +414,14 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
404414
decode(hostnames_s3website, bl);
405415
}
406416
if (struct_v >= 4) {
407-
RGWSystemMetaObj::decode(bl);
417+
{
418+
// these used to be wrapped by RGWSystemMetaObj::decode(),
419+
// so the extra DECODE_START/DECODE_FINISH are preserved
420+
DECODE_START(1, bl);
421+
decode(id, bl);
422+
decode(name, bl);
423+
DECODE_FINISH(bl);
424+
}
408425
decode(realm_id, bl);
409426
} else {
410427
id = name;
@@ -418,27 +435,8 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
418435
DECODE_FINISH(bl);
419436
}
420437

421-
int read_default_id(const DoutPrefixProvider *dpp, std::string& default_id, optional_yield y, bool old_format = false) override;
422-
int set_as_default(const DoutPrefixProvider *dpp, optional_yield y, bool exclusive = false) override;
423-
int create_default(const DoutPrefixProvider *dpp, optional_yield y, bool old_format = false);
424438
int equals(const std::string& other_zonegroup) const;
425-
int add_zone(const DoutPrefixProvider *dpp,
426-
const RGWZoneParams& zone_params, bool *is_master, bool *read_only,
427-
const std::list<std::string>& endpoints, const std::string *ptier_type,
428-
bool *psync_from_all, std::list<std::string>& sync_from,
429-
std::list<std::string>& sync_from_rm, std::string *predirect_zone,
430-
std::optional<int> bucket_index_max_shards, RGWSyncModulesManager *sync_mgr,
431-
const rgw::zone_features::set& enable_features,
432-
const rgw::zone_features::set& disable_features,
433-
optional_yield y);
434-
int remove_zone(const DoutPrefixProvider *dpp, const std::string& zone_id, optional_yield y);
435-
int rename_zone(const DoutPrefixProvider *dpp, const RGWZoneParams& zone_params, optional_yield y);
436-
rgw_pool get_pool(CephContext *cct) const override;
437-
const std::string get_default_oid(bool old_region_format = false) const override;
438-
const std::string& get_info_oid_prefix(bool old_region_format = false) const override;
439-
const std::string& get_names_oid_prefix() const override;
440-
std::string get_predefined_id(CephContext *cct) const override;
441-
const std::string& get_predefined_name(CephContext *cct) const override;
439+
rgw_pool get_pool(CephContext *cct) const;
442440

443441
void dump(Formatter *f) const;
444442
void decode_json(JSONObj *obj);

0 commit comments

Comments
 (0)