From 55a4f6506cfeec589eb8f520ed7278b5bd0b7b82 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 3 Mar 2021 14:13:05 -0500 Subject: [PATCH] rgw: add set of 'features' to zone and zonegroup Signed-off-by: Casey Bodley --- src/rgw/rgw_json_enc.cc | 4 ++++ src/rgw/rgw_zone.h | 28 ++++++++++++++++++++++++---- src/rgw/rgw_zone_features.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/rgw/rgw_zone_features.h diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index b940eb081c695..8a8c4959c1bab 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -1299,6 +1299,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) @@ -1317,6 +1318,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 @@ -1350,6 +1352,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& zones, JSONObj *o) @@ -1387,6 +1390,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); } diff --git a/src/rgw/rgw_zone.h b/src/rgw/rgw_zone.h index 9e89cbf150a72..ba11464ab0c9f 100644 --- a/src/rgw/rgw_zone.h +++ b/src/rgw/rgw_zone.h @@ -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 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) @@ -902,6 +913,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) {} @@ -919,7 +931,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); @@ -933,11 +945,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); @@ -961,6 +974,9 @@ struct RGWZoneGroup : public RGWSystemMetaObj { if (struct_v >= 5) { decode(sync_policy, bl); } + if (struct_v >= 6) { + decode(enabled_features, bl); + } DECODE_FINISH(bl); } @@ -987,6 +1003,10 @@ struct RGWZoneGroup : public RGWSystemMetaObj { void dump(Formatter *f) const; void decode_json(JSONObj *obj); static void generate_test_instances(std::list& 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 index 0000000000000..3b553046d098b --- /dev/null +++ b/src/rgw/rgw_zone_features.h @@ -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 +#include + +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 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 { + using is_transparent = std::true_type; +}; + +using set = boost::container::flat_set; + +} // namespace rgw::zone_features -- 2.39.5