From: Daniel Gryniewicz Date: Mon, 1 Aug 2022 17:58:04 +0000 (-0400) Subject: RGW - Zipper - Make Zone generic X-Git-Tag: v18.0.0~186^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ff1b565887799b80036bceeef133da4cf0a5ee71;p=ceph.git RGW - Zipper - Make Zone generic - RadosStore had a dummy implementation of Zone that just passed through to the Zone service to get info about the local zone. Implement the Zone API for real, so that we can reference multiple zones. - Convert get_id() to string; it was only ever used as a string anyway. - Add get_zone_by*() to zonegroup and use it apporpriately Signed-off-by: Daniel Gryniewicz --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 637dab47e42..431693ed272 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1887,7 +1887,7 @@ static int commit_period(RGWRealm& realm, RGWPeriod& period, const string& access, const string& secret, bool force) { - auto& master_zone = period.get_master_zone(); + auto& master_zone = period.get_master_zone().id; if (master_zone.empty()) { cerr << "cannot commit period: period does not have a master zone of a master zonegroup" << std::endl; return -EINVAL; @@ -1914,7 +1914,7 @@ static int commit_period(RGWRealm& realm, RGWPeriod& period, if (remote.empty() && url.empty()) { // use the new master zone's connection - remote = master_zone.id; + remote = master_zone; cerr << "Sending period to new master zone " << remote << std::endl; } boost::optional conn; diff --git a/src/rgw/rgw_asio_frontend.cc b/src/rgw/rgw_asio_frontend.cc index 064a6d72ffd..4b4a8175192 100644 --- a/src/rgw/rgw_asio_frontend.cc +++ b/src/rgw/rgw_asio_frontend.cc @@ -681,7 +681,7 @@ public: meta_map["zonegroup"] = zone_svc->get_zonegroup().get_name(); meta_map["zonegroup_id"] = zone_svc->get_zonegroup().get_id(); meta_map["zone"] = zone_svc->get_name(); - meta_map["zone_id"] = zone_svc->get_id().id; + meta_map["zone_id"] = zone_svc->get_id(); } string process_str(const string& in); diff --git a/src/rgw/rgw_period_pusher.cc b/src/rgw/rgw_period_pusher.cc index 3d60c42d838..275f14619d2 100644 --- a/src/rgw/rgw_period_pusher.cc +++ b/src/rgw/rgw_period_pusher.cc @@ -266,7 +266,7 @@ void RGWPeriodPusher::handle_notify(RGWZonesNeedPeriod&& period) // update other zone endpoints for (auto& z : my_zonegroup.zones) { auto& zone = z.second; - if (zone.id == store->get_zone()->get_id().id) + if (zone.id == store->get_zone()->get_id()) continue; if (zone.endpoints.empty()) continue; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 6be3bbb8f29..194de861a9a 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1066,8 +1066,10 @@ struct ReplicationConfiguration { set ids; for (auto& name : zone_names) { - rgw_zone_id id; - if (static_cast(store)->svc()->zone->find_zone_id_by_name(name, &id)) { + std::unique_ptr zone; + int ret = store->get_zone()->get_zonegroup().get_zone_by_name(name, &zone); + if (ret >= 0) { + rgw_zone_id id = zone->get_id(); ids.insert(std::move(id)); } } @@ -1080,9 +1082,10 @@ struct ReplicationConfiguration { vector names; for (auto& id : zone_ids) { - RGWZone *zone; - if ((zone = static_cast(store)->svc()->zone->find_zone(id))) { - names.emplace_back(zone->name); + std::unique_ptr zone; + int ret = store->get_zone()->get_zonegroup().get_zone_by_id(id.id, &zone); + if (ret >= 0) { + names.emplace_back(zone->get_name()); } } diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index 9c74f2d5824..f5634b95386 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -1467,6 +1467,10 @@ public: virtual int get_zone_count() const = 0; /** Get the placement tier associated with the rule */ virtual int get_placement_tier(const rgw_placement_rule& rule, std::unique_ptr* tier) = 0; + /** Get a zone by ID */ + virtual int get_zone_by_id(const std::string& id, std::unique_ptr* zone) = 0; + /** Get a zone by Name */ + virtual int get_zone_by_name(const std::string& name, std::unique_ptr* zone) = 0; /** Clone a copy of this zonegroup. */ virtual std::unique_ptr clone() = 0; }; @@ -1486,7 +1490,7 @@ class Zone { /** Get info about the zonegroup containing this zone */ virtual ZoneGroup& get_zonegroup() = 0; /** Get the ID of this zone */ - virtual const rgw_zone_id& get_id() = 0; + virtual const std::string& get_id() = 0; /** Get the name of this zone */ virtual const std::string& get_name() const = 0; /** True if this zone is writable */ diff --git a/src/rgw/rgw_sal_dbstore.cc b/src/rgw/rgw_sal_dbstore.cc index 78a1a93fc36..2fc9215f94f 100644 --- a/src/rgw/rgw_sal_dbstore.cc +++ b/src/rgw/rgw_sal_dbstore.cc @@ -545,9 +545,9 @@ namespace rgw::sal { return *zone_params; } - const rgw_zone_id& DBZone::get_id() + const std::string& DBZone::get_id() { - return cur_zone_id; + return zone_params->get_id(); } diff --git a/src/rgw/rgw_sal_dbstore.h b/src/rgw/rgw_sal_dbstore.h index c61f86db096..734d3f78aad 100644 --- a/src/rgw/rgw_sal_dbstore.h +++ b/src/rgw/rgw_sal_dbstore.h @@ -289,6 +289,12 @@ protected: std::unique_ptr* tier) { return -1; } + virtual int get_zone_by_id(const std::string& id, std::unique_ptr* zone) override { + return -1; + } + virtual int get_zone_by_name(const std::string& name, std::unique_ptr* zone) override { + return -1; + } virtual std::unique_ptr clone() override { std::unique_ptrzg = std::make_unique(*group.get()); return std::make_unique(store, std::move(zg)); @@ -303,7 +309,6 @@ protected: RGWZone *zone_public_config{nullptr}; /* external zone params, e.g., entrypoints, log flags, etc. */ RGWZoneParams *zone_params{nullptr}; /* internal zone params, e.g., rados pools */ RGWPeriod *current_period{nullptr}; - rgw_zone_id cur_zone_id; public: DBZone(DBStore* _store) : store(_store) { @@ -312,7 +317,6 @@ protected: zone_public_config = new RGWZone(); zone_params = new RGWZoneParams(); current_period = new RGWPeriod(); - cur_zone_id = rgw_zone_id(zone_params->get_id()); // XXX: only default and STANDARD supported for now RGWZonePlacementInfo info; @@ -334,7 +338,7 @@ protected: } virtual ZoneGroup& get_zonegroup() override; const RGWZoneParams& get_rgw_params(); - virtual const rgw_zone_id& get_id() override; + virtual const std::string& get_id() override; virtual const std::string& get_name() const override; virtual bool is_writeable() override; virtual bool get_redirect_endpoint(std::string* endpoint) override; diff --git a/src/rgw/rgw_sal_filter.cc b/src/rgw/rgw_sal_filter.cc index 23354f92cea..ecc7ccdca32 100644 --- a/src/rgw/rgw_sal_filter.cc +++ b/src/rgw/rgw_sal_filter.cc @@ -65,6 +65,30 @@ int FilterZoneGroup::get_placement_tier(const rgw_placement_rule& rule, return 0; } +int FilterZoneGroup::get_zone_by_id(const std::string& id, std::unique_ptr* zone) +{ + std::unique_ptr nz; + int ret = next->get_zone_by_id(id, &nz); + if (ret < 0) + return ret; + Zone *z = new FilterZone(std::move(nz)); + + zone->reset(z); + return 0; +} + +int FilterZoneGroup::get_zone_by_name(const std::string& name, std::unique_ptr* zone) +{ + std::unique_ptr nz; + int ret = next->get_zone_by_name(name, &nz); + if (ret < 0) + return ret; + Zone *z = new FilterZone(std::move(nz)); + + zone->reset(z); + return 0; +} + int FilterStore::initialize(CephContext *cct, const DoutPrefixProvider *dpp) { zone = std::make_unique(next->get_zone()->clone()); diff --git a/src/rgw/rgw_sal_filter.h b/src/rgw/rgw_sal_filter.h index 6b02dd1a41d..384ecf67d67 100644 --- a/src/rgw/rgw_sal_filter.h +++ b/src/rgw/rgw_sal_filter.h @@ -79,6 +79,8 @@ public: virtual int get_zone_count() const override { return next->get_zone_count(); } virtual int get_placement_tier(const rgw_placement_rule& rule, std::unique_ptr* tier) override; + virtual int get_zone_by_id(const std::string& id, std::unique_ptr* zone) override; + virtual int get_zone_by_name(const std::string& name, std::unique_ptr* zone) override; virtual std::unique_ptr clone() override { std::unique_ptr nzg = next->clone(); return std::make_unique(std::move(nzg)); @@ -105,7 +107,7 @@ public: virtual ZoneGroup& get_zonegroup() override { return *group.get(); } - virtual const rgw_zone_id& get_id() override { + virtual const std::string& get_id() override { return next->get_id(); } virtual const std::string& get_name() const override { diff --git a/src/rgw/rgw_sal_motr.cc b/src/rgw/rgw_sal_motr.cc index 28c111d8dd3..8c60b10b16d 100644 --- a/src/rgw/rgw_sal_motr.cc +++ b/src/rgw/rgw_sal_motr.cc @@ -899,9 +899,9 @@ ZoneGroup& MotrZone::get_zonegroup() return zonegroup; } -const rgw_zone_id& MotrZone::get_id() +const std::string& MotrZone::get_id() { - return cur_zone_id; + return zone_params->get_id(); } const std::string& MotrZone::get_name() const diff --git a/src/rgw/rgw_sal_motr.h b/src/rgw/rgw_sal_motr.h index 6ab7b418756..3ba2038583f 100644 --- a/src/rgw/rgw_sal_motr.h +++ b/src/rgw/rgw_sal_motr.h @@ -402,6 +402,12 @@ public: return group.zones.size(); } virtual int get_placement_tier(const rgw_placement_rule& rule, std::unique_ptr* tier); + virtual int get_zone_by_id(const std::string& id, std::unique_ptr* zone) override { + return -1; + } + virtual int get_zone_by_name(const std::string& name, std::unique_ptr* zone) override { + return -1; + } const RGWZoneGroup& get_group() { return group; } virtual std::unique_ptr clone() override { return std::make_unique(store, group); @@ -416,7 +422,6 @@ class MotrZone : public StoreZone { RGWZone *zone_public_config{nullptr}; /* external zone params, e.g., entrypoints, log flags, etc. */ RGWZoneParams *zone_params{nullptr}; /* internal zone params, e.g., rados pools */ RGWPeriod *current_period{nullptr}; - rgw_zone_id cur_zone_id; public: MotrZone(MotrStore* _store) : store(_store), zonegroup(_store) { @@ -424,7 +429,6 @@ class MotrZone : public StoreZone { zone_public_config = new RGWZone(); zone_params = new RGWZoneParams(); current_period = new RGWPeriod(); - cur_zone_id = rgw_zone_id(zone_params->get_id()); // XXX: only default and STANDARD supported for now RGWZonePlacementInfo info; @@ -438,7 +442,6 @@ class MotrZone : public StoreZone { zone_public_config = new RGWZone(); zone_params = new RGWZoneParams(); current_period = new RGWPeriod(); - cur_zone_id = rgw_zone_id(zone_params->get_id()); // XXX: only default and STANDARD supported for now RGWZonePlacementInfo info; @@ -453,7 +456,7 @@ class MotrZone : public StoreZone { return std::make_unique(store); } virtual ZoneGroup& get_zonegroup() override; - virtual const rgw_zone_id& get_id() override; + virtual const std::string& get_id() override; virtual const std::string& get_name() const override; virtual bool is_writeable() override; virtual bool get_redirect_endpoint(std::string* endpoint) override; diff --git a/src/rgw/rgw_sal_rados.cc b/src/rgw/rgw_sal_rados.cc index ea93511d083..ca78de41257 100644 --- a/src/rgw/rgw_sal_rados.cc +++ b/src/rgw/rgw_sal_rados.cc @@ -2960,24 +2960,72 @@ int RadosZoneGroup::get_placement_tier(const rgw_placement_rule& rule, return 0; } -const rgw_zone_id& RadosZone::get_id() +int RadosZoneGroup::get_zone_by_id(const std::string& id, std::unique_ptr* zone) { - return store->svc()->zone->zone_id(); + RGWZone* rz = store->svc()->zone->find_zone(id); + if (!rz) + return -ENOENT; + + Zone* z = new RadosZone(store, clone(), *rz); + zone->reset(z); + return 0; +} + +int RadosZoneGroup::get_zone_by_name(const std::string& name, std::unique_ptr* zone) +{ + rgw_zone_id id; + int ret = store->svc()->zone->find_zone_id_by_name(name, &id); + if (ret < 0) + return ret; + + RGWZone* rz = store->svc()->zone->find_zone(id.id); + if (!rz) + return -ENOENT; + + Zone* z = new RadosZone(store, clone(), *rz); + zone->reset(z); + return 0; +} + +std::unique_ptr RadosZone::clone() +{ + if (local_zone) + return std::make_unique(store, group->clone()); + + return std::make_unique(store, group->clone(), rgw_zone); +} + +const std::string& RadosZone::get_id() +{ + if (local_zone) + return store->svc()->zone->zone_id().id; + + return rgw_zone.id; } const std::string& RadosZone::get_name() const { - return store->svc()->zone->zone_name(); + if (local_zone) + return store->svc()->zone->zone_name(); + + return rgw_zone.name; } bool RadosZone::is_writeable() { - return store->svc()->zone->zone_is_writeable(); + if (local_zone) + return store->svc()->zone->zone_is_writeable(); + + return !rgw_zone.read_only; } bool RadosZone::get_redirect_endpoint(std::string* endpoint) { - return store->svc()->zone->get_redirect_zone_endpoint(endpoint); + if (local_zone) + return store->svc()->zone->get_redirect_zone_endpoint(endpoint); + + endpoint = &rgw_zone.redirect_zone; + return true; } bool RadosZone::has_zonegroup_api(const std::string& api) const @@ -3007,7 +3055,10 @@ const std::string& RadosZone::get_realm_id() const std::string_view RadosZone::get_tier_type() { - return store->svc()->zone->get_zone().tier_type; + if (local_zone) + return store->svc()->zone->get_zone().tier_type; + + return rgw_zone.id; } RadosLuaManager::RadosLuaManager(RadosStore* _s) : diff --git a/src/rgw/rgw_sal_rados.h b/src/rgw/rgw_sal_rados.h index e9413e6f426..6b23f8a153c 100644 --- a/src/rgw/rgw_sal_rados.h +++ b/src/rgw/rgw_sal_rados.h @@ -85,25 +85,28 @@ public: return group.zones.size(); } virtual int get_placement_tier(const rgw_placement_rule& rule, std::unique_ptr* tier); - const RGWZoneGroup& get_group() const { return group; } + virtual int get_zone_by_id(const std::string& id, std::unique_ptr* zone) override; + virtual int get_zone_by_name(const std::string& name, std::unique_ptr* zone) override; virtual std::unique_ptr clone() override { return std::make_unique(store, group); } + const RGWZoneGroup& get_group() const { return group; } }; class RadosZone : public StoreZone { protected: RadosStore* store; std::unique_ptr group; + RGWZone rgw_zone; + bool local_zone{false}; public: - RadosZone(RadosStore* _store, std::unique_ptr _zg) : store(_store), group(std::move(_zg)) {} + RadosZone(RadosStore* _store, std::unique_ptr _zg) : store(_store), group(std::move(_zg)), local_zone(true) {} + RadosZone(RadosStore* _store, std::unique_ptr _zg, RGWZone& z) : store(_store), group(std::move(_zg)), rgw_zone(z) {} ~RadosZone() = default; - virtual std::unique_ptr clone() override { - return std::make_unique(store, group->clone()); - } + virtual std::unique_ptr clone() override; virtual ZoneGroup& get_zonegroup() override { return *(group.get()); } - virtual const rgw_zone_id& get_id() override; + virtual const std::string& get_id() override; virtual const std::string& get_name() const override; virtual bool is_writeable() override; virtual bool get_redirect_endpoint(std::string* endpoint) override;