From 8eb3c26b087b83d84b294f98c30c5d6bd5e3e249 Mon Sep 17 00:00:00 2001 From: Ali Masarwa Date: Thu, 3 Apr 2025 23:32:23 +0300 Subject: [PATCH] RGW/standalone: refactor RGWZoneParams with configstore Signed-off-by: Ali Masarwa --- src/rgw/driver/rados/rgw_zone.cc | 16 --- src/rgw/driver/rados/rgw_zone.h | 63 +++++----- src/rgw/rgw_zone.cc | 190 +------------------------------ src/rgw/services/svc_zone.cc | 5 +- 4 files changed, 41 insertions(+), 233 deletions(-) diff --git a/src/rgw/driver/rados/rgw_zone.cc b/src/rgw/driver/rados/rgw_zone.cc index a3ffcc6189a1c..e569aaada7e9e 100644 --- a/src/rgw/driver/rados/rgw_zone.cc +++ b/src/rgw/driver/rados/rgw_zone.cc @@ -106,22 +106,6 @@ int RGWSystemMetaObj::read(const DoutPrefixProvider *dpp, optional_yield y) return read_info(dpp, id, y); } -int RGWZoneParams::create_default(const DoutPrefixProvider *dpp, optional_yield y, bool old_format) -{ - name = default_zone_name; - - int r = create(dpp, y); - if (r < 0) { - return r; - } - - if (old_format) { - name = id; - } - - return r; -} - const string& RGWZoneParams::get_compression_type(const rgw_placement_rule& placement_rule) const { static const std::string NONE{"none"}; diff --git a/src/rgw/driver/rados/rgw_zone.h b/src/rgw/driver/rados/rgw_zone.h index c48dbf3a6046b..6e4336e851aa5 100644 --- a/src/rgw/driver/rados/rgw_zone.h +++ b/src/rgw/driver/rados/rgw_zone.h @@ -97,7 +97,9 @@ public: }; WRITE_CLASS_ENCODER(RGWSystemMetaObj) -struct RGWZoneParams : RGWSystemMetaObj { +struct RGWZoneParams { + std::string id; + std::string name; rgw_pool domain_root; rgw_pool control_pool; rgw_pool gc_pool; @@ -126,33 +128,24 @@ struct RGWZoneParams : RGWSystemMetaObj { JSONFormattable tier_config; - RGWZoneParams() : RGWSystemMetaObj() {} - explicit RGWZoneParams(const std::string& name) : RGWSystemMetaObj(name){} - RGWZoneParams(const rgw_zone_id& id, const std::string& name) : RGWSystemMetaObj(id.id, name) {} - RGWZoneParams(const rgw_zone_id& id, const std::string& name, const std::string& _realm_id) - : RGWSystemMetaObj(id.id, name), realm_id(_realm_id) {} - virtual ~RGWZoneParams(); - - rgw_pool get_pool(CephContext *cct) const override; - const std::string get_default_oid(bool old_format = false) const override; - const std::string& get_names_oid_prefix() const override; - const std::string& get_info_oid_prefix(bool old_format = false) const override; - std::string get_predefined_id(CephContext *cct) const override; - const std::string& get_predefined_name(CephContext *cct) const override; - - int init(const DoutPrefixProvider *dpp, - CephContext *_cct, RGWSI_SysObj *_sysobj_svc, optional_yield y, - bool setup_obj = true, bool old_format = false); - using RGWSystemMetaObj::init; - int read_default_id(const DoutPrefixProvider *dpp, std::string& default_id, optional_yield y, bool old_format = false) override; - int set_as_default(const DoutPrefixProvider *dpp, optional_yield y, bool exclusive = false) override; - int create_default(const DoutPrefixProvider *dpp, optional_yield y, bool old_format = false); - int create(const DoutPrefixProvider *dpp, optional_yield y, bool exclusive = true) override; - int fix_pool_names(const DoutPrefixProvider *dpp, optional_yield y); + RGWZoneParams() {} + explicit RGWZoneParams(const std::string& _name) : name(_name){} + RGWZoneParams(const rgw_zone_id& _id, const std::string& _name) : id(_id.id), name(_name) {} + RGWZoneParams(const rgw_zone_id& _id, const std::string& _name, const std::string& _realm_id) + : id(_id.id), name(_name), realm_id(_realm_id) {} + + const std::string& get_name() const { return name; } + const std::string& get_id() const { return id; } + + void set_name(const std::string& _name) { name = _name;} + void set_id(const std::string& _id) { id = _id;} + void clear_id() { id.clear(); } + + rgw_pool get_pool(CephContext *cct) const; const std::string& get_compression_type(const rgw_placement_rule& placement_rule) const; - void encode(bufferlist& bl) const override { + void encode(bufferlist& bl) const { ENCODE_START(15, 1, bl); encode(domain_root, bl); encode(control_pool, bl); @@ -164,7 +157,14 @@ struct RGWZoneParams : RGWSystemMetaObj { encode(user_email_pool, bl); encode(user_swift_pool, bl); encode(user_uid_pool, bl); - RGWSystemMetaObj::encode(bl); + { + // these used to be wrapped by RGWSystemMetaObj::encode(), + // so the extra ENCODE_START/ENCODE_FINISH are preserved + ENCODE_START(1, 1, bl); + encode(id, bl); + encode(name, bl); + ENCODE_FINISH(bl); + } encode(system_key, bl); encode(placement_pools, bl); rgw_pool unused_metadata_heap; @@ -185,7 +185,7 @@ struct RGWZoneParams : RGWSystemMetaObj { ENCODE_FINISH(bl); } - void decode(bufferlist::const_iterator& bl) override { + void decode(bufferlist::const_iterator& bl) { DECODE_START(15, bl); decode(domain_root, bl); decode(control_pool, bl); @@ -198,7 +198,14 @@ struct RGWZoneParams : RGWSystemMetaObj { decode(user_swift_pool, bl); decode(user_uid_pool, bl); if (struct_v >= 6) { - RGWSystemMetaObj::decode(bl); + { + // these used to be wrapped by RGWSystemMetaObj::decode(), + // so the extra DECODE_START/DECODE_FINISH are preserved + DECODE_START(1, bl); + decode(id, bl); + decode(name, bl); + DECODE_FINISH(bl); + } } else if (struct_v >= 2) { decode(name, bl); id = name; diff --git a/src/rgw/rgw_zone.cc b/src/rgw/rgw_zone.cc index 4b33ffc1e36a8..1dd8c227fd128 100644 --- a/src/rgw/rgw_zone.cc +++ b/src/rgw/rgw_zone.cc @@ -220,11 +220,10 @@ void RGWZoneGroup::decode_json(JSONObj *obj) JSONDecoder::decode_json("enabled_features", enabled_features, obj); } -RGWZoneParams::~RGWZoneParams() {} - void RGWZoneParams::decode_json(JSONObj *obj) { - RGWSystemMetaObj::decode_json(obj); + JSONDecoder::decode_json("id", id, obj); + JSONDecoder::decode_json("name", name, obj); JSONDecoder::decode_json("domain_root", domain_root, obj); JSONDecoder::decode_json("control_pool", control_pool, obj); JSONDecoder::decode_json("gc_pool", gc_pool, obj); @@ -251,7 +250,8 @@ void RGWZoneParams::decode_json(JSONObj *obj) void RGWZoneParams::dump(Formatter *f) const { - RGWSystemMetaObj::dump(f); + encode_json("id", id, f); + encode_json("name", name, f); encode_json("domain_root", domain_root, f); encode_json("control_pool", control_pool, f); encode_json("gc_pool", gc_pool, f); @@ -276,17 +276,6 @@ void RGWZoneParams::dump(Formatter *f) const encode_json("realm_id", realm_id, f); } -int RGWZoneParams::init(const DoutPrefixProvider *dpp, - CephContext *cct, RGWSI_SysObj *sysobj_svc, - optional_yield y, bool setup_obj, bool old_format) -{ - if (name.empty()) { - name = cct->_conf->rgw_zone; - } - - return RGWSystemMetaObj::init(dpp, cct, sysobj_svc, y, setup_obj, old_format); -} - rgw_pool RGWZoneParams::get_pool(CephContext *cct) const { if (cct->_conf->rgw_zone_root_pool.empty()) { @@ -296,101 +285,6 @@ rgw_pool RGWZoneParams::get_pool(CephContext *cct) const return rgw_pool(cct->_conf->rgw_zone_root_pool); } -const string RGWZoneParams::get_default_oid(bool old_format) const -{ - if (old_format) { - return cct->_conf->rgw_default_zone_info_oid; - } - - return cct->_conf->rgw_default_zone_info_oid + "." + realm_id; -} - -const string& RGWZoneParams::get_names_oid_prefix() const -{ - return zone_names_oid_prefix; -} - -const string& RGWZoneParams::get_info_oid_prefix(bool old_format) const -{ - return zone_info_oid_prefix; -} - -string RGWZoneParams::get_predefined_id(CephContext *cct) const { - return cct->_conf.get_val("rgw_zone_id"); -} - -const string& RGWZoneParams::get_predefined_name(CephContext *cct) const { - return cct->_conf->rgw_zone; -} - -int RGWZoneParams::read_default_id(const DoutPrefixProvider *dpp, string& default_id, optional_yield y, - bool old_format) -{ - if (realm_id.empty()) { - /* try using default realm */ - RGWRealm realm; - auto config_store_type = g_conf().get_val("rgw_config_store"); - auto cfgstore = DriverManager::create_config_store(dpp, config_store_type); - int ret = rgw::read_realm(dpp, y, cfgstore.get(), realm.get_id(), realm.get_name(), realm); - //no default realm exist - if (ret < 0) { - return read_id(dpp, default_zone_name, default_id, y); - } - realm_id = realm.get_id(); - } - - return RGWSystemMetaObj::read_default_id(dpp, default_id, y, old_format); -} - - -int RGWZoneParams::set_as_default(const DoutPrefixProvider *dpp, optional_yield y, bool exclusive) -{ - if (realm_id.empty()) { - /* try using default realm */ - RGWRealm realm; - auto config_store_type = g_conf().get_val("rgw_config_store"); - auto cfgstore = DriverManager::create_config_store(dpp, config_store_type); - int ret = rgw::read_realm(dpp, y, cfgstore.get(), realm.get_id(), realm.get_name(), realm); - if (ret < 0) { - ldpp_dout(dpp, 10) << "could not read realm id: " << cpp_strerror(-ret) << dendl; - return -EINVAL; - } - realm_id = realm.get_id(); - } - - return RGWSystemMetaObj::set_as_default(dpp, y, exclusive); -} - -int RGWZoneParams::create(const DoutPrefixProvider *dpp, optional_yield y, bool exclusive) -{ - RGWZonePlacementInfo default_placement; - default_placement.index_pool = name + "." + default_bucket_index_pool_suffix; - rgw_pool pool = name + "." + default_storage_pool_suffix; - default_placement.storage_classes.set_storage_class(RGW_STORAGE_CLASS_STANDARD, &pool, nullptr); - default_placement.data_extra_pool = name + "." + default_storage_extra_pool_suffix; - placement_pools["default-placement"] = default_placement; - - int r = fix_pool_names(dpp, y); - if (r < 0) { - ldpp_dout(dpp, 0) << "ERROR: fix_pool_names returned r=" << r << dendl; - return r; - } - - r = RGWSystemMetaObj::create(dpp, y, exclusive); - if (r < 0) { - return r; - } - - // try to set as default. may race with another create, so pass exclusive=true - // so we don't override an existing default - r = set_as_default(dpp, y, true); - if (r < 0 && r != -EEXIST) { - ldpp_dout(dpp, 10) << "WARNING: failed to set zone as default, r=" << r << dendl; - } - - return 0; -} - rgw_pool fix_zone_pool_dup(const set& pools, const string& default_prefix, const string& default_suffix, @@ -484,82 +378,6 @@ int get_zones_pool_set(const DoutPrefixProvider *dpp, } -static int get_zones_pool_set(const DoutPrefixProvider *dpp, - CephContext* cct, - RGWSI_SysObj* sysobj_svc, - const list& zone_names, - const string& my_zone_id, - set& pool_names, - optional_yield y) -{ - for (const auto& name : zone_names) { - RGWZoneParams zone(name); - int r = zone.init(dpp, cct, sysobj_svc, y); - if (r < 0) { - ldpp_dout(dpp, 0) << "Error: failed to load zone " << name - << " with " << cpp_strerror(-r) << dendl; - return r; - } - if (zone.get_id() != my_zone_id) { - add_zone_pools(zone, pool_names); - } - } - return 0; -} - -int RGWZoneParams::fix_pool_names(const DoutPrefixProvider *dpp, optional_yield y) -{ - - list zones; - int r = zone_svc->list_zones(dpp, zones); - if (r < 0) { - ldpp_dout(dpp, 10) << "WARNING: driver->list_zones() returned r=" << r << dendl; - } - - set pools; - r = get_zones_pool_set(dpp, cct, sysobj_svc, zones, id, pools, y); - if (r < 0) { - ldpp_dout(dpp, 0) << "Error: get_zones_pool_names" << r << dendl; - return r; - } - - domain_root = fix_zone_pool_dup(pools, name, ".rgw.meta:root", domain_root); - control_pool = fix_zone_pool_dup(pools, name, ".rgw.control", control_pool); - gc_pool = fix_zone_pool_dup(pools, name ,".rgw.log:gc", gc_pool); - lc_pool = fix_zone_pool_dup(pools, name ,".rgw.log:lc", lc_pool); - log_pool = fix_zone_pool_dup(pools, name, ".rgw.log", log_pool); - intent_log_pool = fix_zone_pool_dup(pools, name, ".rgw.log:intent", intent_log_pool); - usage_log_pool = fix_zone_pool_dup(pools, name, ".rgw.log:usage", usage_log_pool); - user_keys_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:users.keys", user_keys_pool); - user_email_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:users.email", user_email_pool); - user_swift_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:users.swift", user_swift_pool); - user_uid_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:users.uid", user_uid_pool); - roles_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:roles", roles_pool); - reshard_pool = fix_zone_pool_dup(pools, name, ".rgw.log:reshard", reshard_pool); - otp_pool = fix_zone_pool_dup(pools, name, ".rgw.otp", otp_pool); - oidc_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:oidc", oidc_pool); - notif_pool = fix_zone_pool_dup(pools, name ,".rgw.log:notif", notif_pool); - topics_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:topics", topics_pool); - account_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:accounts", account_pool); - group_pool = fix_zone_pool_dup(pools, name, ".rgw.meta:groups", group_pool); - - for(auto& iter : placement_pools) { - iter.second.index_pool = fix_zone_pool_dup(pools, name, "." + default_bucket_index_pool_suffix, - iter.second.index_pool); - for (auto& pi : iter.second.storage_classes.get_all()) { - if (pi.second.data_pool) { - rgw_pool& pool = pi.second.data_pool.get(); - pool = fix_zone_pool_dup(pools, name, "." + default_storage_pool_suffix, - pool); - } - } - iter.second.data_extra_pool= fix_zone_pool_dup(pools, name, "." + default_storage_extra_pool_suffix, - iter.second.data_extra_pool); - } - - return 0; -} - void RGWPeriodConfig::decode_json(JSONObj *obj) { JSONDecoder::decode_json("bucket_quota", quota.bucket_quota, obj); diff --git a/src/rgw/services/svc_zone.cc b/src/rgw/services/svc_zone.cc index 99edbee5cf470..099a127acae52 100644 --- a/src/rgw/services/svc_zone.cc +++ b/src/rgw/services/svc_zone.cc @@ -151,7 +151,7 @@ int RGWSI_Zone::do_start(optional_yield y, const DoutPrefixProvider *dpp) return ret; } - ret = zone_params->init(dpp, cct, sysobj_svc, y); + ret = cfgstore->read_default_zone(dpp, y, realm->get_id(), *zone_params, nullptr); bool found_zone = (ret == 0); if (ret < 0 && ret != -ENOENT) { lderr(cct) << "failed reading zone info: ret "<< ret << " " << cpp_strerror(-ret) << dendl; @@ -581,8 +581,7 @@ int RGWSI_Zone::create_default_zg(const DoutPrefixProvider *dpp, optional_yield int RGWSI_Zone::init_default_zone(const DoutPrefixProvider *dpp, optional_yield y) { ldpp_dout(dpp, 10) << " Using default name "<< default_zone_name << dendl; - zone_params->set_name(default_zone_name); - int ret = zone_params->init(dpp, cct, sysobj_svc, y); + int ret = cfgstore->read_zone_by_name(dpp, y, default_zone_name, *zone_params, nullptr); if (ret < 0 && ret != -ENOENT) { ldpp_dout(dpp, 0) << "failed reading zone params info: " << " " << cpp_strerror(-ret) << dendl; return ret; -- 2.39.5