]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
RGW - Zipper - Make Zone generic
authorDaniel Gryniewicz <dang@redhat.com>
Mon, 1 Aug 2022 17:58:04 +0000 (13:58 -0400)
committerDaniel Gryniewicz <dang@redhat.com>
Tue, 16 Aug 2022 16:31:27 +0000 (12:31 -0400)
- 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 <dang@redhat.com>
13 files changed:
src/rgw/rgw_admin.cc
src/rgw/rgw_asio_frontend.cc
src/rgw/rgw_period_pusher.cc
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_sal.h
src/rgw/rgw_sal_dbstore.cc
src/rgw/rgw_sal_dbstore.h
src/rgw/rgw_sal_filter.cc
src/rgw/rgw_sal_filter.h
src/rgw/rgw_sal_motr.cc
src/rgw/rgw_sal_motr.h
src/rgw/rgw_sal_rados.cc
src/rgw/rgw_sal_rados.h

index 637dab47e42efa9ce2ef5c1869bd3d4dbcfd2324..431693ed2722b42b202e7015e7c86e341fd9df1b 100644 (file)
@@ -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<RGWRESTConn> conn;
index 064a6d72ffd3de36d0b7bb8a73a22ffbab1f2459..4b4a8175192fbb9c2fdcc8d54f1866bd61dae2bd 100644 (file)
@@ -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);
index 3d60c42d838befe0e7ddfac2072a40474d5e1f0c..275f14619d264df7d1ebe5aa3293a7407f3da6df 100644 (file)
@@ -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;
index 6be3bbb8f29f9fc41dfbb2b5245e4cce92c4a97d..194de861a9a263d34195a8d32df27de652a462d7 100644 (file)
@@ -1066,8 +1066,10 @@ struct ReplicationConfiguration {
       set<rgw_zone_id> ids;
 
       for (auto& name : zone_names) {
-       rgw_zone_id id;
-       if (static_cast<rgw::sal::RadosStore*>(store)->svc()->zone->find_zone_id_by_name(name, &id)) {
+       std::unique_ptr<rgw::sal::Zone> 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<string> names;
 
       for (auto& id : zone_ids) {
-       RGWZone *zone;
-       if ((zone = static_cast<rgw::sal::RadosStore*>(store)->svc()->zone->find_zone(id))) {
-         names.emplace_back(zone->name);
+       std::unique_ptr<rgw::sal::Zone> zone;
+       int ret = store->get_zone()->get_zonegroup().get_zone_by_id(id.id, &zone);
+       if (ret >= 0) {
+         names.emplace_back(zone->get_name());
        }
       }
 
index 9c74f2d5824f42da008a9b73564828a413ca41e5..f5634b95386c050ab845a3d3b62349b6cec74e91 100644 (file)
@@ -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<PlacementTier>* tier) = 0;
+  /** Get a zone by ID */
+  virtual int get_zone_by_id(const std::string& id, std::unique_ptr<Zone>* zone) = 0;
+  /** Get a zone by Name */
+  virtual int get_zone_by_name(const std::string& name, std::unique_ptr<Zone>* zone) = 0;
   /** Clone a copy of this zonegroup. */
   virtual std::unique_ptr<ZoneGroup> 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 */
index 78a1a93fc3649f5c29e891ab474e609dcf9bb413..2fc9215f94f0d4f08126cf2a5c78957a63066dc4 100644 (file)
@@ -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();
   }
 
 
index c61f86db0963e1a5cb828fd93bd9e4df2a7cfc87..734d3f78aad922856c3d21c09225f040af1ef2d3 100644 (file)
@@ -289,6 +289,12 @@ protected:
                                   std::unique_ptr<PlacementTier>* tier) {
       return -1;
     }
+    virtual int get_zone_by_id(const std::string& id, std::unique_ptr<Zone>* zone) override {
+      return -1;
+    }
+    virtual int get_zone_by_name(const std::string& name, std::unique_ptr<Zone>* zone) override {
+      return -1;
+    }
     virtual std::unique_ptr<ZoneGroup> clone() override {
       std::unique_ptr<RGWZoneGroup>zg = std::make_unique<RGWZoneGroup>(*group.get());
       return std::make_unique<DBZoneGroup>(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;
index 23354f92ceae752eb74abc09474f99d0ed5d69d7..ecc7ccdca32f02969fc69ab6dc1202140b43ab85 100644 (file)
@@ -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>* zone)
+{
+  std::unique_ptr<Zone> 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>* zone)
+{
+  std::unique_ptr<Zone> 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<FilterZone>(next->get_zone()->clone());
index 6b02dd1a41dc374da17ee7baaa8a67b89fa93021..384ecf67d679bfc5bcb06df3743ec134c6310942 100644 (file)
@@ -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<PlacementTier>* tier) override;
+  virtual int get_zone_by_id(const std::string& id, std::unique_ptr<Zone>* zone) override;
+  virtual int get_zone_by_name(const std::string& name, std::unique_ptr<Zone>* zone) override;
   virtual std::unique_ptr<ZoneGroup> clone() override {
     std::unique_ptr<ZoneGroup> nzg = next->clone();
     return std::make_unique<FilterZoneGroup>(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 {
index 28c111d8dd3b684d43a6c8bcf144ff44f2a1ed01..8c60b10b16dd6a60972d8d74c02f03703316abd3 100644 (file)
@@ -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
index 6ab7b4187561ea1ff5b2e2c9d8b5a481f64b2739..3ba2038583fd344e1b0fd382cd19274e4a4f539f 100644 (file)
@@ -402,6 +402,12 @@ public:
     return group.zones.size();
   }
   virtual int get_placement_tier(const rgw_placement_rule& rule, std::unique_ptr<PlacementTier>* tier);
+  virtual int get_zone_by_id(const std::string& id, std::unique_ptr<Zone>* zone) override {
+    return -1;
+  }
+  virtual int get_zone_by_name(const std::string& name, std::unique_ptr<Zone>* zone) override {
+    return -1;
+  }
   const RGWZoneGroup& get_group() { return group; }
   virtual std::unique_ptr<ZoneGroup> clone() override {
     return std::make_unique<MotrZoneGroup>(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<MotrZone>(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;
index ea93511d0839cff36afa2bb0abd1ac584c407eb6..ca78de41257407f3ba9de919ec74799ae2594dc6 100644 (file)
@@ -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>* 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>* 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<Zone> RadosZone::clone()
+{
+  if (local_zone)
+    return std::make_unique<RadosZone>(store, group->clone());
+
+  return std::make_unique<RadosZone>(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) : 
index e9413e6f4269c9a83c47cb6b746968157ba2e8d2..6b23f8a153c25f40a667373830f68d7a08b692dd 100644 (file)
@@ -85,25 +85,28 @@ public:
     return group.zones.size();
   }
   virtual int get_placement_tier(const rgw_placement_rule& rule, std::unique_ptr<PlacementTier>* tier);
-  const RGWZoneGroup& get_group() const { return group; }
+  virtual int get_zone_by_id(const std::string& id, std::unique_ptr<Zone>* zone) override;
+  virtual int get_zone_by_name(const std::string& name, std::unique_ptr<Zone>* zone) override;
   virtual std::unique_ptr<ZoneGroup> clone() override {
     return std::make_unique<RadosZoneGroup>(store, group);
   }
+  const RGWZoneGroup& get_group() const { return group; }
 };
 
 class RadosZone : public StoreZone {
   protected:
     RadosStore* store;
     std::unique_ptr<ZoneGroup> group;
+    RGWZone rgw_zone;
+    bool local_zone{false};
   public:
-    RadosZone(RadosStore* _store, std::unique_ptr<ZoneGroup> _zg) : store(_store), group(std::move(_zg)) {}
+    RadosZone(RadosStore* _store, std::unique_ptr<ZoneGroup> _zg) : store(_store), group(std::move(_zg)), local_zone(true) {}
+    RadosZone(RadosStore* _store, std::unique_ptr<ZoneGroup> _zg, RGWZone& z) : store(_store), group(std::move(_zg)), rgw_zone(z) {}
     ~RadosZone() = default;
 
-    virtual std::unique_ptr<Zone> clone() override {
-      return std::make_unique<RadosZone>(store, group->clone());
-    }
+    virtual std::unique_ptr<Zone> 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;