Skip to content

Commit

Permalink
RGW - Zipper - Make Zone generic
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
dang committed Aug 16, 2022
1 parent 5a6fb22 commit ff1b565
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_asio_frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ class ExpandMetaVar {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_period_pusher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions src/rgw/rgw_rest_s3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand All @@ -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());
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/rgw/rgw_sal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,10 @@ class ZoneGroup {
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;
};
Expand All @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions src/rgw/rgw_sal_dbstore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
10 changes: 7 additions & 3 deletions src/rgw/rgw_sal_dbstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ class DBNotification : public StoreNotification {
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));
Expand All @@ -303,7 +309,6 @@ class DBNotification : public StoreNotification {
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) {
Expand All @@ -312,7 +317,6 @@ class DBNotification : public StoreNotification {
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;
Expand All @@ -334,7 +338,7 @@ class DBNotification : public StoreNotification {
}
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;
Expand Down
24 changes: 24 additions & 0 deletions src/rgw/rgw_sal_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/rgw/rgw_sal_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class FilterZoneGroup : public ZoneGroup {
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));
Expand All @@ -105,7 +107,7 @@ class FilterZone : public Zone {
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/rgw/rgw_sal_motr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions src/rgw/rgw_sal_motr.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ class MotrZoneGroup : public StoreZoneGroup {
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);
Expand All @@ -416,15 +422,13 @@ 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) {
realm = new RGWRealm();
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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
63 changes: 57 additions & 6 deletions src/rgw/rgw_sal_rados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) :
Expand Down
15 changes: 9 additions & 6 deletions src/rgw/rgw_sal_rados.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,28 @@ class RadosZoneGroup : public StoreZoneGroup {
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;
Expand Down

0 comments on commit ff1b565

Please sign in to comment.