]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add set of 'features' to zone and zonegroup
authorCasey Bodley <cbodley@redhat.com>
Wed, 3 Mar 2021 19:13:05 +0000 (14:13 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Mon, 13 Sep 2021 16:27:51 +0000 (12:27 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_json_enc.cc
src/rgw/rgw_zone.h
src/rgw/rgw_zone_features.h [new file with mode: 0644]

index 8f0dd39ec1d4d6dd2619faa26ebc21d9254564d9..54979729161818b7642998d15f0a917a148db08c 100644 (file)
@@ -1384,6 +1384,7 @@ void RGWZone::dump(Formatter *f) const
   encode_json("sync_from_all", sync_from_all, f);
   encode_json("sync_from", sync_from, f);
   encode_json("redirect_zone", redirect_zone, f);
+  encode_json("supported_features", supported_features, f);
 }
 
 void RGWZone::decode_json(JSONObj *obj)
@@ -1402,6 +1403,7 @@ void RGWZone::decode_json(JSONObj *obj)
   JSONDecoder::decode_json("sync_from_all", sync_from_all, true, obj);
   JSONDecoder::decode_json("sync_from", sync_from, obj);
   JSONDecoder::decode_json("redirect_zone", redirect_zone, obj);
+  JSONDecoder::decode_json("supported_features", supported_features, obj);
 }
 
 void RGWZoneGroupPlacementTarget::dump(Formatter *f) const
@@ -1435,6 +1437,7 @@ void RGWZoneGroup::dump(Formatter *f) const
   encode_json("default_placement", default_placement, f);
   encode_json("realm_id", realm_id, f);
   encode_json("sync_policy", sync_policy, f);
+  encode_json("enabled_features", enabled_features, f);
 }
 
 static void decode_zones(map<rgw_zone_id, RGWZone>& zones, JSONObj *o)
@@ -1472,6 +1475,7 @@ void RGWZoneGroup::decode_json(JSONObj *obj)
   JSONDecoder::decode_json("default_storage_class", default_placement.storage_class, obj);
   JSONDecoder::decode_json("realm_id", realm_id, obj);
   JSONDecoder::decode_json("sync_policy", sync_policy, obj);
+  JSONDecoder::decode_json("enabled_features", enabled_features, obj);
 }
 
 
index 2823d54fc71bb8b6ed83cab8e3069f898928c455..e2b2d30da1bb14493a35309fec538e0b5e55617c 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "rgw_common.h"
 #include "rgw_sync_policy.h"
+#include "rgw_zone_features.h"
 
 namespace rgw_zone_defaults {
 
@@ -596,13 +597,15 @@ struct RGWZone {
   bool sync_from_all;
   std::set<std::string> sync_from; /* list of zones to sync from */
 
+  rgw::zone_features::set supported_features;
+
   RGWZone()
     : log_meta(false), log_data(false), read_only(false),
       bucket_index_max_shards(default_bucket_index_max_shards),
       sync_from_all(true) {}
 
   void encode(bufferlist& bl) const {
-    ENCODE_START(7, 1, bl);
+    ENCODE_START(8, 1, bl);
     encode(name, bl);
     encode(endpoints, bl);
     encode(log_meta, bl);
@@ -614,11 +617,12 @@ struct RGWZone {
     encode(sync_from_all, bl);
     encode(sync_from, bl);
     encode(redirect_zone, bl);
+    encode(supported_features, bl);
     ENCODE_FINISH(bl);
   }
 
   void decode(bufferlist::const_iterator& bl) {
-    DECODE_START(7, bl);
+    DECODE_START(8, bl);
     decode(name, bl);
     if (struct_v < 4) {
       id = name;
@@ -645,6 +649,9 @@ struct RGWZone {
     if (struct_v >= 7) {
       decode(redirect_zone, bl);
     }
+    if (struct_v >= 8) {
+      decode(supported_features, bl);
+    }
     DECODE_FINISH(bl);
   }
   void dump(Formatter *f) const;
@@ -656,6 +663,10 @@ struct RGWZone {
   bool syncs_from(const std::string& zone_name) const {
     return (sync_from_all || sync_from.find(zone_name) != sync_from.end());
   }
+
+  bool supports(std::string_view feature) const {
+    return supported_features.contains(feature);
+  }
 };
 WRITE_CLASS_ENCODER(RGWZone)
 
@@ -754,6 +765,7 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
   std::string realm_id;
 
   rgw_sync_policy_info sync_policy;
+  rgw::zone_features::set enabled_features;
 
   RGWZoneGroup(): is_master(false){}
   RGWZoneGroup(const std::string &id, const std::string &name):RGWSystemMetaObj(id, name) {}
@@ -771,7 +783,7 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
   void post_process_params(const DoutPrefixProvider *dpp, optional_yield y);
 
   void encode(bufferlist& bl) const override {
-    ENCODE_START(5, 1, bl);
+    ENCODE_START(6, 1, bl);
     encode(name, bl);
     encode(api_name, bl);
     encode(is_master, bl);
@@ -785,11 +797,12 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
     RGWSystemMetaObj::encode(bl);
     encode(realm_id, bl);
     encode(sync_policy, bl);
+    encode(enabled_features, bl);
     ENCODE_FINISH(bl);
   }
 
   void decode(bufferlist::const_iterator& bl) override {
-    DECODE_START(5, bl);
+    DECODE_START(6, bl);
     decode(name, bl);
     decode(api_name, bl);
     decode(is_master, bl);
@@ -813,6 +826,9 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
     if (struct_v >= 5) {
       decode(sync_policy, bl);
     }
+    if (struct_v >= 6) {
+      decode(enabled_features, bl);
+    }
     DECODE_FINISH(bl);
   }
 
@@ -839,6 +855,10 @@ struct RGWZoneGroup : public RGWSystemMetaObj {
   void dump(Formatter *f) const;
   void decode_json(JSONObj *obj);
   static void generate_test_instances(std::list<RGWZoneGroup*>& o);
+
+  bool supports(std::string_view feature) const {
+    return enabled_features.contains(feature);
+  }
 };
 WRITE_CLASS_ENCODER(RGWZoneGroup)
 
diff --git a/src/rgw/rgw_zone_features.h b/src/rgw/rgw_zone_features.h
new file mode 100644 (file)
index 0000000..3b55304
--- /dev/null
@@ -0,0 +1,36 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab ft=cpp
+
+#pragma once
+
+#include <string>
+#include <boost/container/flat_set.hpp>
+
+namespace rgw::zone_features {
+
+// zone feature names
+inline constexpr std::string_view resharding = "resharding";
+
+// static list of features supported by this release
+inline constexpr std::initializer_list<std::string_view> supported = {
+  resharding,
+};
+
+inline constexpr bool supports(std::string_view feature) {
+  for (auto i : supported) {
+    if (feature.compare(i) == 0) {
+      return true;
+    }
+  }
+  return false;
+}
+
+
+// enable string_view overloads for find() contains() etc
+struct feature_less : std::less<std::string_view> {
+  using is_transparent = std::true_type;
+};
+
+using set = boost::container::flat_set<std::string, feature_less>;
+
+} // namespace rgw::zone_features