diff --git a/src/rgw/rgw_rest_config.cc b/src/rgw/rgw_rest_config.cc index db8eab4cc72..dec8655c00a 100644 --- a/src/rgw/rgw_rest_config.cc +++ b/src/rgw/rgw_rest_config.cc @@ -32,34 +32,6 @@ using namespace std; -void RGWOp_ZoneGroupMap_Get::execute(optional_yield y) { - op_ret = zonegroup_map.read(this, g_ceph_context, static_cast(store)->svc()->sysobj, y); - if (op_ret < 0) { - ldpp_dout(this, 5) << "failed to read zone_group map" << dendl; - } -} - -void RGWOp_ZoneGroupMap_Get::send_response() { - set_req_state_err(s, op_ret); - dump_errno(s); - end_header(s); - - if (op_ret < 0) - return; - - if (old_format) { - RGWRegionMap region_map; - region_map.regions = zonegroup_map.zonegroups; - region_map.master_region = zonegroup_map.master_zonegroup; - region_map.quota.bucket_quota = zonegroup_map.quota.bucket_quota; - region_map.quota.user_quota = zonegroup_map.quota.user_quota; - encode_json("region-map", region_map, s->formatter); - } else { - encode_json("zonegroup-map", zonegroup_map, s->formatter); - } - flusher.flush(); -} - void RGWOp_ZoneConfig_Get::send_response() { const RGWZoneParams& zone_params = static_cast(store)->svc()->zone->get_zone_params(); @@ -78,11 +50,8 @@ RGWOp* RGWHandler_Config::op_get() { bool exists; string type = s->info.args.get("type", &exists); - if (type.compare("zonegroup-map") == 0) { - return new RGWOp_ZoneGroupMap_Get(false); - } else if (type.compare("zone") == 0) { + if (type.compare("zone") == 0) { return new RGWOp_ZoneConfig_Get(); - } else { - return new RGWOp_ZoneGroupMap_Get(true); } + return nullptr; } diff --git a/src/rgw/rgw_rest_config.h b/src/rgw/rgw_rest_config.h index ac1cde433d1..81717cc0d80 100644 --- a/src/rgw/rgw_rest_config.h +++ b/src/rgw/rgw_rest_config.h @@ -19,30 +19,6 @@ #include "rgw_rest.h" #include "rgw_zone.h" -class RGWOp_ZoneGroupMap_Get : public RGWRESTOp { - RGWZoneGroupMap zonegroup_map; - bool old_format; -public: - explicit RGWOp_ZoneGroupMap_Get(bool _old_format):old_format(_old_format) {} - ~RGWOp_ZoneGroupMap_Get() override {} - - int check_caps(const RGWUserCaps& caps) override { - return caps.check_cap("zone", RGW_CAP_READ); - } - int verify_permission(optional_yield) override { - return check_caps(s->user->get_caps()); - } - void execute(optional_yield y) override; - void send_response() override; - const char* name() const override { - if (old_format) { - return "get_region_map"; - } else { - return "get_zonegroup_map"; - } - } -}; - class RGWOp_ZoneConfig_Get : public RGWRESTOp { RGWZoneParams zone_params; public: diff --git a/src/rgw/rgw_zone.cc b/src/rgw/rgw_zone.cc index 9554349e81e..38ac0eb085d 100644 --- a/src/rgw/rgw_zone.cc +++ b/src/rgw/rgw_zone.cc @@ -2060,75 +2060,6 @@ bool RGWPeriodMap::find_zone_by_name(const string& zone_name, return false; } -int RGWZoneGroupMap::read(const DoutPrefixProvider *dpp, CephContext *cct, RGWSI_SysObj *sysobj_svc, optional_yield y) -{ - - RGWPeriod period; - int ret = period.init(dpp, cct, sysobj_svc, y); - if (ret < 0) { - cerr << "failed to read current period info: " << cpp_strerror(ret); - return ret; - } - - quota.bucket_quota = period.get_config().quota.bucket_quota; - quota.user_quota = period.get_config().quota.user_quota; - zonegroups = period.get_map().zonegroups; - zonegroups_by_api = period.get_map().zonegroups_by_api; - master_zonegroup = period.get_map().master_zonegroup; - - return 0; -} - -void RGWRegionMap::encode(bufferlist& bl) const { - ENCODE_START( 3, 1, bl); - encode(regions, bl); - encode(master_region, bl); - encode(quota.bucket_quota, bl); - encode(quota.user_quota, bl); - ENCODE_FINISH(bl); -} - -void RGWRegionMap::decode(bufferlist::const_iterator& bl) { - DECODE_START(3, bl); - decode(regions, bl); - decode(master_region, bl); - if (struct_v >= 2) - decode(quota.bucket_quota, bl); - if (struct_v >= 3) - decode(quota.user_quota, bl); - DECODE_FINISH(bl); -} - -void RGWZoneGroupMap::encode(bufferlist& bl) const { - ENCODE_START( 3, 1, bl); - encode(zonegroups, bl); - encode(master_zonegroup, bl); - encode(quota.bucket_quota, bl); - encode(quota.user_quota, bl); - ENCODE_FINISH(bl); -} - -void RGWZoneGroupMap::decode(bufferlist::const_iterator& bl) { - DECODE_START(3, bl); - decode(zonegroups, bl); - decode(master_zonegroup, bl); - if (struct_v >= 2) - decode(quota.bucket_quota, bl); - if (struct_v >= 3) - decode(quota.user_quota, bl); - DECODE_FINISH(bl); - - zonegroups_by_api.clear(); - for (map::iterator iter = zonegroups.begin(); - iter != zonegroups.end(); ++iter) { - RGWZoneGroup& zonegroup = iter->second; - zonegroups_by_api[zonegroup.api_name] = zonegroup; - if (zonegroup.is_master_zonegroup()) { - master_zonegroup = zonegroup.get_name(); - } - } -} - static inline int conf_to_uint64(const JSONFormattable& config, const string& key, uint64_t *pval) { string sval; @@ -2777,45 +2708,3 @@ void RGWPeriodConfig::decode_json(JSONObj *obj) JSONDecoder::decode_json("bucket_ratelimit", bucket_ratelimit, obj); JSONDecoder::decode_json("anonymous_ratelimit", anon_ratelimit, obj); } - -void RGWRegionMap::dump(Formatter *f) const -{ - encode_json("regions", regions, f); - encode_json("master_region", master_region, f); - encode_json("bucket_quota", quota.bucket_quota, f); - encode_json("user_quota", quota.user_quota, f); -} - -void RGWRegionMap::decode_json(JSONObj *obj) -{ - JSONDecoder::decode_json("regions", regions, obj); - JSONDecoder::decode_json("master_region", master_region, obj); - JSONDecoder::decode_json("bucket_quota", quota.bucket_quota, obj); - JSONDecoder::decode_json("user_quota", quota.user_quota, obj); -} - -void RGWZoneGroupMap::dump(Formatter *f) const -{ - encode_json("zonegroups", zonegroups, f); - encode_json("master_zonegroup", master_zonegroup, f); - encode_json("bucket_quota", quota.bucket_quota, f); - encode_json("user_quota", quota.user_quota, f); -} - -void RGWZoneGroupMap::decode_json(JSONObj *obj) -{ - JSONDecoder::decode_json("zonegroups", zonegroups, obj); - /* backward compatability with region */ - if (zonegroups.empty()) { - JSONDecoder::decode_json("regions", zonegroups, obj); - } - JSONDecoder::decode_json("master_zonegroup", master_zonegroup, obj); - /* backward compatability with region */ - if (master_zonegroup.empty()) { - JSONDecoder::decode_json("master_region", master_zonegroup, obj); - } - - JSONDecoder::decode_json("bucket_quota", quota.bucket_quota, obj); - JSONDecoder::decode_json("user_quota", quota.user_quota, obj); -} - diff --git a/src/rgw/rgw_zone.h b/src/rgw/rgw_zone.h index e63b8b1eca3..b48750e759a 100644 --- a/src/rgw/rgw_zone.h +++ b/src/rgw/rgw_zone.h @@ -1090,43 +1090,6 @@ struct RGWPeriodConfig }; WRITE_CLASS_ENCODER(RGWPeriodConfig) -/* for backward comaptability */ -struct RGWRegionMap { - - std::map regions; - - std::string master_region; - - RGWQuota quota; - - void encode(bufferlist& bl) const; - void decode(bufferlist::const_iterator& bl); - - void dump(Formatter *f) const; - void decode_json(JSONObj *obj); -}; -WRITE_CLASS_ENCODER(RGWRegionMap) - -struct RGWZoneGroupMap { - - std::map zonegroups; - std::map zonegroups_by_api; - - std::string master_zonegroup; - - RGWQuota quota; - - /* construct the map */ - int read(const DoutPrefixProvider *dpp, CephContext *cct, RGWSI_SysObj *sysobj_svc, optional_yield y); - - void encode(bufferlist& bl) const; - void decode(bufferlist::const_iterator& bl); - - void dump(Formatter *f) const; - void decode_json(JSONObj *obj); -}; -WRITE_CLASS_ENCODER(RGWZoneGroupMap) - class RGWRealm; class RGWPeriod; diff --git a/src/rgw/services/svc_zone.cc b/src/rgw/services/svc_zone.cc index dc0b8c24a51..e11b3b6eff1 100644 --- a/src/rgw/services/svc_zone.cc +++ b/src/rgw/services/svc_zone.cc @@ -241,18 +241,6 @@ int RGWSI_Zone::do_start(optional_yield y, const DoutPrefixProvider *dpp) /* we have zone now */ - ret = replace_region_with_zonegroup(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, -1) << "failed converting region to zonegroup : ret "<< ret << " " << cpp_strerror(-ret) << dendl; - return ret; - } - - ret = convert_regionmap(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, -1) << "failed converting regionmap: " << cpp_strerror(-ret) << dendl; - return ret; - } - auto zone_iter = zonegroup->zones.find(zone_params->get_id()); if (zone_iter == zonegroup->zones.end()) { /* shouldn't happen if relying on period config */ @@ -469,264 +457,6 @@ int RGWSI_Zone::list_periods(const DoutPrefixProvider *dpp, const string& curren return ret; } -/** - * Replace all region configuration with zonegroup for - * backward compatability - * Returns 0 on success, -ERR# on failure. - */ -int RGWSI_Zone::replace_region_with_zonegroup(const DoutPrefixProvider *dpp, optional_yield y) -{ - /* copy default region */ - /* convert default region to default zonegroup */ - string default_oid = cct->_conf->rgw_default_region_info_oid; - if (default_oid.empty()) { - default_oid = default_region_info_oid; - } - - RGWZoneGroup default_zonegroup; - rgw_pool pool{default_zonegroup.get_pool(cct)}; - string oid = "converted"; - bufferlist bl; - - RGWSysObj sysobj = sysobj_svc->get_obj(rgw_raw_obj(pool, oid)); - - int ret = sysobj.rop().read(dpp, &bl, y); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << " failed to read converted: ret "<< ret << " " << cpp_strerror(-ret) - << dendl; - return ret; - } else if (ret != -ENOENT) { - ldpp_dout(dpp, 20) << "System already converted " << dendl; - return 0; - } - - string default_region; - ret = default_zonegroup.init(dpp, cct, sysobj_svc, y, false, true); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed init default region: ret "<< ret << " " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = default_zonegroup.read_default_id(dpp, default_region, y, true); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << " failed reading old default region: ret "<< ret << " " << cpp_strerror(-ret) << dendl; - return ret; - } - - /* convert regions to zonegroups */ - list regions; - ret = list_regions(dpp, regions); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << " failed to list regions: ret "<< ret << " " << cpp_strerror(-ret) << dendl; - return ret; - } else if (ret == -ENOENT || regions.empty()) { - RGWZoneParams zoneparams(default_zone_name); - int ret = zoneparams.init(dpp, cct, sysobj_svc, y); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << ": error initializing default zone params: " << cpp_strerror(-ret) << dendl; - return ret; - } - /* update master zone */ - RGWZoneGroup default_zg(default_zonegroup_name); - ret = default_zg.init(dpp, cct, sysobj_svc, y); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << ": error in initializing default zonegroup: " << cpp_strerror(-ret) << dendl; - return ret; - } - if (ret != -ENOENT && default_zg.master_zone.empty()) { - default_zg.master_zone = zoneparams.get_id(); - return default_zg.update(dpp, y); - } - return 0; - } - - string master_region; - rgw_zone_id master_zone; - for (list::iterator iter = regions.begin(); iter != regions.end(); ++iter) { - if (*iter != default_zonegroup_name){ - RGWZoneGroup region(*iter); - int ret = region.init(dpp, cct, sysobj_svc, y, true, true); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed init region "<< *iter << ": " << cpp_strerror(-ret) << dendl; - return ret; - } - if (region.is_master_zonegroup()) { - master_region = region.get_id(); - master_zone = region.master_zone; - } - } - } - - /* create realm if there is none. - The realm name will be the region and zone concatenated - realm id will be mds of its name */ - if (realm->get_id().empty() && !master_region.empty() && !master_zone.empty()) { - string new_realm_name = master_region + "." + master_zone.id; - unsigned char md5[CEPH_CRYPTO_MD5_DIGESTSIZE]; - char md5_str[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; - MD5 hash; - // Allow use of MD5 digest in FIPS mode for non-cryptographic purposes - hash.SetFlags(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); - hash.Update((const unsigned char *)new_realm_name.c_str(), new_realm_name.length()); - hash.Final(md5); - buf_to_hex(md5, CEPH_CRYPTO_MD5_DIGESTSIZE, md5_str); - string new_realm_id(md5_str); - RGWRealm new_realm(new_realm_id,new_realm_name); - ret = new_realm.init(dpp, cct, sysobj_svc, y, false); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " Error initing new realm: " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = new_realm.create(dpp, y); - if (ret < 0 && ret != -EEXIST) { - ldpp_dout(dpp, 0) << __func__ << " Error creating new realm: " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = new_realm.set_as_default(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " Error setting realm as default: " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = realm->init(dpp, cct, sysobj_svc, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " Error initing realm: " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = current_period->init(dpp, cct, sysobj_svc, realm->get_id(), y, - realm->get_name()); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " Error initing current period: " << cpp_strerror(-ret) << dendl; - return ret; - } - } - - list::iterator iter; - /* create zonegroups */ - for (iter = regions.begin(); iter != regions.end(); ++iter) - { - ldpp_dout(dpp, 0) << __func__ << " Converting " << *iter << dendl; - /* check to see if we don't have already a zonegroup with this name */ - RGWZoneGroup new_zonegroup(*iter); - ret = new_zonegroup.init(dpp, cct , sysobj_svc, y); - if (ret == 0 && new_zonegroup.get_id() != *iter) { - ldpp_dout(dpp, 0) << __func__ << " zonegroup "<< *iter << " already exists id " << new_zonegroup.get_id () << - " skipping conversion " << dendl; - continue; - } - RGWZoneGroup zonegroup(*iter); - zonegroup.set_id(*iter); - int ret = zonegroup.init(dpp, cct, sysobj_svc, y, true, true); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed init zonegroup: ret "<< ret << " " << cpp_strerror(-ret) << dendl; - return ret; - } - zonegroup.realm_id = realm->get_id(); - /* fix default region master zone */ - if (*iter == default_zonegroup_name && zonegroup.master_zone.empty()) { - ldpp_dout(dpp, 0) << __func__ << " Setting default zone as master for default region" << dendl; - zonegroup.master_zone = default_zone_name; - } - ret = zonegroup.update(dpp, y); - if (ret < 0 && ret != -EEXIST) { - ldpp_dout(dpp, 0) << __func__ << " failed to update zonegroup " << *iter << ": ret "<< ret << " " << cpp_strerror(-ret) - << dendl; - return ret; - } - ret = zonegroup.update_name(dpp, y); - if (ret < 0 && ret != -EEXIST) { - ldpp_dout(dpp, 0) << __func__ << " failed to update_name for zonegroup " << *iter << ": ret "<< ret << " " << cpp_strerror(-ret) - << dendl; - return ret; - } - if (zonegroup.get_name() == default_region) { - ret = zonegroup.set_as_default(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed to set_as_default " << *iter << ": ret "<< ret << " " << cpp_strerror(-ret) - << dendl; - return ret; - } - } - for (auto iter = zonegroup.zones.begin(); iter != zonegroup.zones.end(); - ++iter) { - ldpp_dout(dpp, 0) << __func__ << " Converting zone" << iter->first << dendl; - RGWZoneParams zoneparams(iter->first, iter->second.name); - zoneparams.set_id(iter->first.id); - zoneparams.realm_id = realm->get_id(); - ret = zoneparams.init(dpp, cct, sysobj_svc, y); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << " failed to init zoneparams " << iter->first << ": " << cpp_strerror(-ret) << dendl; - return ret; - } else if (ret == -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << " zone is part of another cluster " << iter->first << " skipping " << dendl; - continue; - } - zonegroup.realm_id = realm->get_id(); - ret = zoneparams.update(dpp, y); - if (ret < 0 && ret != -EEXIST) { - ldpp_dout(dpp, 0) << __func__ << " failed to update zoneparams " << iter->first << ": " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = zoneparams.update_name(dpp, y); - if (ret < 0 && ret != -EEXIST) { - ldpp_dout(dpp, 0) << __func__ << " failed to init zoneparams " << iter->first << ": " << cpp_strerror(-ret) << dendl; - return ret; - } - } - - if (!current_period->get_id().empty()) { - ret = current_period->add_zonegroup(dpp, zonegroup, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed to add zonegroup to current_period: " << cpp_strerror(-ret) << dendl; - return ret; - } - } - } - - if (!current_period->get_id().empty()) { - ret = current_period->update(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed to update new period: " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = current_period->store_info(dpp, false, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed to store new period: " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = current_period->reflect(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed to update local objects: " << cpp_strerror(-ret) << dendl; - return ret; - } - } - - for (auto const& iter : regions) { - RGWZoneGroup zonegroup(iter); - int ret = zonegroup.init(dpp, cct, sysobj_svc, y, true, true); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed init zonegroup" << iter << ": ret "<< ret << " " << cpp_strerror(-ret) << dendl; - return ret; - } - ret = zonegroup.delete_obj(dpp, y, true); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << __func__ << " failed to delete region " << iter << ": ret "<< ret << " " << cpp_strerror(-ret) - << dendl; - return ret; - } - } - - /* mark as converted */ - ret = sysobj.wop() - .set_exclusive(true) - .write(dpp, bl, y); - if (ret < 0 ) { - ldpp_dout(dpp, 0) << __func__ << " failed to mark cluster as converted: ret "<< ret << " " << cpp_strerror(-ret) - << dendl; - return ret; - } - - return 0; -} - /** * Add new connection to connections map * @param zonegroup_conn_map map which new connection will be added to @@ -877,69 +607,6 @@ int RGWSI_Zone::init_zg_from_local(const DoutPrefixProvider *dpp, optional_yield return 0; } -int RGWSI_Zone::convert_regionmap(const DoutPrefixProvider *dpp, optional_yield y) -{ - RGWZoneGroupMap zonegroupmap; - - string pool_name = cct->_conf->rgw_zone_root_pool; - if (pool_name.empty()) { - pool_name = RGW_DEFAULT_ZONE_ROOT_POOL; - } - string oid = region_map_oid; - - rgw_pool pool(pool_name); - bufferlist bl; - - RGWSysObj sysobj = sysobj_svc->get_obj(rgw_raw_obj(pool, oid)); - - int ret = sysobj.rop().read(dpp, &bl, y); - if (ret < 0 && ret != -ENOENT) { - return ret; - } else if (ret == -ENOENT) { - return 0; - } - - try { - auto iter = bl.cbegin(); - decode(zonegroupmap, iter); - } catch (buffer::error& err) { - ldpp_dout(dpp, 0) << "error decoding regionmap from " << pool << ":" << oid << dendl; - return -EIO; - } - - for (map::iterator iter = zonegroupmap.zonegroups.begin(); - iter != zonegroupmap.zonegroups.end(); ++iter) { - RGWZoneGroup& zonegroup = iter->second; - ret = zonegroup.init(dpp, cct, sysobj_svc, y, false); - ret = zonegroup.update(dpp, y); - if (ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << "Error could not update zonegroup " << zonegroup.get_name() << ": " << - cpp_strerror(-ret) << dendl; - return ret; - } else if (ret == -ENOENT) { - ret = zonegroup.create(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << "Error could not create " << zonegroup.get_name() << ": " << - cpp_strerror(-ret) << dendl; - return ret; - } - } - } - - current_period->set_user_quota(zonegroupmap.quota.user_quota); - current_period->set_bucket_quota(zonegroupmap.quota.bucket_quota); - - // remove the region_map so we don't try to convert again - ret = sysobj.wop().remove(dpp, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << "Error could not remove " << sysobj.get_obj() - << " after upgrading to zonegroup map: " << cpp_strerror(ret) << dendl; - return ret; - } - - return 0; -} - const RGWZoneParams& RGWSI_Zone::get_zone_params() const { return *zone_params; diff --git a/src/rgw/services/svc_zone.h b/src/rgw/services/svc_zone.h index 3e7e91e4d3a..a03cdc48b0f 100644 --- a/src/rgw/services/svc_zone.h +++ b/src/rgw/services/svc_zone.h @@ -64,10 +64,8 @@ class RGWSI_Zone : public RGWServiceInstance int do_start(optional_yield y, const DoutPrefixProvider *dpp) override; void shutdown() override; - int replace_region_with_zonegroup(const DoutPrefixProvider *dpp, optional_yield y); int init_zg_from_period(const DoutPrefixProvider *dpp, optional_yield y); int init_zg_from_local(const DoutPrefixProvider *dpp, optional_yield y); - int convert_regionmap(const DoutPrefixProvider *dpp, optional_yield y); int update_placement_map(const DoutPrefixProvider *dpp, optional_yield y);