Skip to content

Commit f733a87

Browse files
authored
Merge pull request ceph#62398 from AliMasarweh/wip-alimasa-rgw-standalone-zone
RGW/standalone: refactor rgw_zone.h with configstore Reviewed-by: Casey Bodley <[email protected]> Reviewed-by: Daniel Gryniewicz <[email protected]>
2 parents 9487685 + b229903 commit f733a87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+364
-1972
lines changed

src/rgw/driver/dbstore/config/sqlite.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,14 @@ int SQLiteConfigStore::delete_period(const DoutPrefixProvider* dpp,
872872
return 0;
873873
}
874874

875+
int SQLiteConfigStore::update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
876+
std::string_view period_id, uint32_t epoch)
877+
{
878+
Prefix prefix{*dpp, "dbconfig:sqlite:read_latest_epoch "}; dpp = &prefix;
879+
// TODO: implement it later
880+
return 0;
881+
}
882+
875883
int SQLiteConfigStore::list_period_ids(const DoutPrefixProvider* dpp,
876884
optional_yield y,
877885
const std::string& marker,

src/rgw/driver/dbstore/config/sqlite.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class SQLiteConfigStore : public sal::ConfigStore {
7979
optional_yield y, const std::string& marker,
8080
std::span<std::string> entries,
8181
sal::ListResult<std::string>& result) override;
82+
int update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
83+
std::string_view period_id, uint32_t epoch) override;
8284

8385
int write_default_zonegroup_id(const DoutPrefixProvider* dpp,
8486
optional_yield y, bool exclusive,

src/rgw/driver/immutable_config/store.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ int ImmutableConfigStore::list_period_ids(const DoutPrefixProvider* dpp,
137137
return 0;
138138
}
139139

140+
int ImmutableConfigStore::update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
141+
std::string_view period_id, uint32_t epoch)
142+
{
143+
return -EROFS;
144+
}
145+
140146

141147
// ZoneGroup
142148

src/rgw/driver/immutable_config/store.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class ImmutableConfigStore : public ConfigStore {
7878
optional_yield y, const std::string& marker,
7979
std::span<std::string> entries,
8080
ListResult<std::string>& result) override;
81+
virtual int update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
82+
std::string_view period_id, uint32_t epoch) override;
8183

8284
// ZoneGroup
8385
virtual int write_default_zonegroup_id(const DoutPrefixProvider* dpp,

src/rgw/driver/rados/config/period.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ static int delete_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
7979
return impl->remove(dpp, y, pool, latest_oid, objv);
8080
}
8181

82-
static int update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
83-
ConfigImpl* impl, std::string_view period_id,
84-
uint32_t epoch)
82+
int RadosConfigStore::update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
83+
std::string_view period_id, uint32_t epoch)
8584
{
8685
static constexpr int MAX_RETRIES = 20;
8786

@@ -91,7 +90,7 @@ static int update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
9190
bool exclusive = false;
9291

9392
// read existing epoch
94-
int r = read_latest_epoch(dpp, y, impl, period_id, existing_epoch, &objv);
93+
int r = read_latest_epoch(dpp, y, impl.get(), period_id, existing_epoch, &objv);
9594
if (r == -ENOENT) {
9695
// use an exclusive create to set the epoch atomically
9796
exclusive = true;
@@ -111,7 +110,7 @@ static int update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
111110
<< " -> " << epoch << " on period=" << period_id << dendl;
112111
}
113112

114-
r = write_latest_epoch(dpp, y, impl, exclusive, period_id, epoch, &objv);
113+
r = write_latest_epoch(dpp, y, impl.get(), exclusive, period_id, epoch, &objv);
115114
if (r == -EEXIST) {
116115
continue; // exclusive create raced with another update, retry
117116
} else if (r == -ECANCELED) {
@@ -149,7 +148,8 @@ int RadosConfigStore::create_period(const DoutPrefixProvider* dpp,
149148
return r;
150149
}
151150

152-
(void) update_latest_epoch(dpp, y, impl.get(), info.get_id(), info.get_epoch());
151+
// non const RGWPeriod
152+
(void) this->update_latest_epoch(dpp, y, info.get_id(), info.get_epoch());
153153
return 0;
154154
}
155155

@@ -182,8 +182,7 @@ int RadosConfigStore::delete_period(const DoutPrefixProvider* dpp,
182182
// read the latest_epoch
183183
uint32_t latest_epoch = 0;
184184
RGWObjVersionTracker latest_objv;
185-
int r = read_latest_epoch(dpp, y, impl.get(), period_id,
186-
latest_epoch, &latest_objv);
185+
int r = read_latest_epoch(dpp, y, impl.get(), period_id, latest_epoch, &latest_objv);
187186
if (r < 0 && r != -ENOENT) { // just delete epoch=0 on ENOENT
188187
ldpp_dout(dpp, 0) << "failed to read latest epoch for period "
189188
<< period_id << ": " << cpp_strerror(r) << dendl;

src/rgw/driver/rados/config/store.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class RadosConfigStore : public sal::ConfigStore {
8585
optional_yield y, const std::string& marker,
8686
std::span<std::string> entries,
8787
sal::ListResult<std::string>& result) override;
88+
virtual int update_latest_epoch(const DoutPrefixProvider* dpp, optional_yield y,
89+
std::string_view period_id, uint32_t epoch) override;
8890

8991
// ZoneGroup
9092
virtual int write_default_zonegroup_id(const DoutPrefixProvider* dpp,

src/rgw/driver/rados/rgw_data_sync.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,7 @@ void RGWRemoteDataLog::wakeup(int shard_id, bc::flat_set<rgw_data_notify_entry>&
32323232
data_sync_cr->wakeup(shard_id, entries);
32333233
}
32343234

3235-
int RGWRemoteDataLog::run_sync(const DoutPrefixProvider *dpp, int num_shards)
3235+
int RGWRemoteDataLog::run_sync(const DoutPrefixProvider *dpp, int num_shards, rgw::sal::ConfigStore* cfgstore)
32363236
{
32373237
// construct and start bid manager for data sync fairness
32383238
const auto& control_pool = sc.env->driver->svc()->zone->get_zone_params().control_pool;

src/rgw/driver/rados/rgw_data_sync.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class RGWRemoteDataLog : public RGWCoroutinesManager {
416416
int read_recovering_shards(const DoutPrefixProvider *dpp, const int num_shards, std::set<int>& recovering_shards);
417417
int read_shard_status(const DoutPrefixProvider *dpp, int shard_id, std::set<std::string>& lagging_buckets,std::set<std::string>& recovering_buckets, rgw_data_sync_marker* sync_marker, const int max_entries);
418418
int init_sync_status(const DoutPrefixProvider *dpp, int num_shards);
419-
int run_sync(const DoutPrefixProvider *dpp, int num_shards);
419+
int run_sync(const DoutPrefixProvider *dpp, int num_shards, rgw::sal::ConfigStore* cfgstore);
420420

421421
void wakeup(int shard_id, bc::flat_set<rgw_data_notify_entry>& entries);
422422
};
@@ -483,7 +483,7 @@ class RGWDataSyncStatusManager : public DoutPrefixProvider {
483483
return source_log.read_source_log_shards_next(dpp, shard_markers, result);
484484
}
485485

486-
int run(const DoutPrefixProvider *dpp) { return source_log.run_sync(dpp, num_shards); }
486+
int run(const DoutPrefixProvider *dpp, rgw::sal::ConfigStore* cfgstore) { return source_log.run_sync(dpp, num_shards, cfgstore); }
487487

488488
void wakeup(int shard_id, bc::flat_set<rgw_data_notify_entry>& entries) { return source_log.wakeup(shard_id, entries); }
489489

src/rgw/driver/rados/rgw_period.cc

Lines changed: 2 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// vim: ts=8 sw=2 smarttab ft=cpp
33

44
#include "rgw_sync.h"
5+
#include "rgw_sal.h"
6+
#include "rgw_sal_config.h"
57

68
#include "services/svc_zone.h"
79

@@ -27,115 +29,6 @@ int RGWPeriod::get_zonegroup(RGWZoneGroup& zonegroup,
2729
return -ENOENT;
2830
}
2931

30-
int RGWPeriod::get_latest_epoch(const DoutPrefixProvider *dpp, epoch_t& latest_epoch, optional_yield y)
31-
{
32-
RGWPeriodLatestEpochInfo info;
33-
34-
int ret = read_latest_epoch(dpp, info, y);
35-
if (ret < 0) {
36-
return ret;
37-
}
38-
39-
latest_epoch = info.epoch;
40-
41-
return 0;
42-
}
43-
44-
int RGWPeriod::delete_obj(const DoutPrefixProvider *dpp, optional_yield y)
45-
{
46-
rgw_pool pool(get_pool(cct));
47-
48-
// delete the object for each period epoch
49-
for (epoch_t e = 1; e <= epoch; e++) {
50-
RGWPeriod p{get_id(), e};
51-
rgw_raw_obj oid{pool, p.get_period_oid()};
52-
auto sysobj = sysobj_svc->get_obj(oid);
53-
int ret = sysobj.wop().remove(dpp, y);
54-
if (ret < 0) {
55-
ldpp_dout(dpp, 0) << "WARNING: failed to delete period object " << oid
56-
<< ": " << cpp_strerror(-ret) << dendl;
57-
}
58-
}
59-
60-
// delete the .latest_epoch object
61-
rgw_raw_obj oid{pool, get_period_oid_prefix() + get_latest_epoch_oid()};
62-
auto sysobj = sysobj_svc->get_obj(oid);
63-
int ret = sysobj.wop().remove(dpp, y);
64-
if (ret < 0) {
65-
ldpp_dout(dpp, 0) << "WARNING: failed to delete period object " << oid
66-
<< ": " << cpp_strerror(-ret) << dendl;
67-
}
68-
return ret;
69-
}
70-
71-
int RGWPeriod::update(const DoutPrefixProvider *dpp, optional_yield y)
72-
{
73-
auto zone_svc = sysobj_svc->get_zone_svc();
74-
ldpp_dout(dpp, 20) << __func__ << " realm " << realm_id << " period " << get_id() << dendl;
75-
list<string> zonegroups;
76-
int ret = zone_svc->list_zonegroups(dpp, zonegroups);
77-
if (ret < 0) {
78-
ldpp_dout(dpp, 0) << "ERROR: failed to list zonegroups: " << cpp_strerror(-ret) << dendl;
79-
return ret;
80-
}
81-
82-
// clear zone short ids of removed zones. period_map.update() will add the
83-
// remaining zones back
84-
period_map.short_zone_ids.clear();
85-
86-
for (auto& iter : zonegroups) {
87-
RGWZoneGroup zg(string(), iter);
88-
ret = zg.init(dpp, cct, sysobj_svc, y);
89-
if (ret < 0) {
90-
ldpp_dout(dpp, 0) << "WARNING: zg.init() failed: " << cpp_strerror(-ret) << dendl;
91-
continue;
92-
}
93-
94-
if (zg.realm_id != realm_id) {
95-
ldpp_dout(dpp, 20) << "skipping zonegroup " << zg.get_name() << " zone realm id " << zg.realm_id << ", not on our realm " << realm_id << dendl;
96-
continue;
97-
}
98-
99-
if (zg.master_zone.empty()) {
100-
ldpp_dout(dpp, 0) << "ERROR: zonegroup " << zg.get_name() << " should have a master zone " << dendl;
101-
return -EINVAL;
102-
}
103-
104-
if (zg.zones.find(zg.master_zone) == zg.zones.end()) {
105-
ldpp_dout(dpp, 0) << "ERROR: zonegroup " << zg.get_name()
106-
<< " has a non existent master zone "<< dendl;
107-
return -EINVAL;
108-
}
109-
110-
if (zg.is_master_zonegroup()) {
111-
master_zonegroup = zg.get_id();
112-
master_zone = zg.master_zone;
113-
}
114-
115-
int ret = period_map.update(zg, cct);
116-
if (ret < 0) {
117-
return ret;
118-
}
119-
}
120-
121-
ret = period_config.read(dpp, sysobj_svc, realm_id, y);
122-
if (ret < 0 && ret != -ENOENT) {
123-
ldpp_dout(dpp, 0) << "ERROR: failed to read period config: "
124-
<< cpp_strerror(ret) << dendl;
125-
return ret;
126-
}
127-
return 0;
128-
}
129-
130-
void RGWPeriod::fork()
131-
{
132-
ldout(cct, 20) << __func__ << " realm " << realm_id << " period " << id << dendl;
133-
predecessor_uuid = id;
134-
id = get_staging_id(realm_id);
135-
period_map.reset();
136-
realm_epoch++;
137-
}
138-
13932
static int read_sync_status(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver, rgw_meta_sync_status *sync_status)
14033
{
14134
rgw::sal::RadosStore* rados_store = static_cast<rgw::sal::RadosStore*>(driver);
@@ -201,99 +94,6 @@ int RGWPeriod::update_sync_status(const DoutPrefixProvider *dpp,
20194
return 0;
20295
}
20396

204-
int RGWPeriod::commit(const DoutPrefixProvider *dpp,
205-
rgw::sal::Driver* driver,
206-
RGWRealm& realm, const RGWPeriod& current_period,
207-
std::ostream& error_stream, optional_yield y,
208-
bool force_if_stale)
209-
{
210-
auto zone_svc = sysobj_svc->get_zone_svc();
211-
ldpp_dout(dpp, 20) << __func__ << " realm " << realm.get_id() << " period " << current_period.get_id() << dendl;
212-
// gateway must be in the master zone to commit
213-
if (master_zone != zone_svc->get_zone_params().get_id()) {
214-
error_stream << "Cannot commit period on zone "
215-
<< zone_svc->get_zone_params().get_id() << ", it must be sent to "
216-
"the period's master zone " << master_zone << '.' << std::endl;
217-
return -EINVAL;
218-
}
219-
// period predecessor must match current period
220-
if (predecessor_uuid != current_period.get_id()) {
221-
error_stream << "Period predecessor " << predecessor_uuid
222-
<< " does not match current period " << current_period.get_id()
223-
<< ". Use 'period pull' to get the latest period from the master, "
224-
"reapply your changes, and try again." << std::endl;
225-
return -EINVAL;
226-
}
227-
// realm epoch must be 1 greater than current period
228-
if (realm_epoch != current_period.get_realm_epoch() + 1) {
229-
error_stream << "Period's realm epoch " << realm_epoch
230-
<< " does not come directly after current realm epoch "
231-
<< current_period.get_realm_epoch() << ". Use 'realm pull' to get the "
232-
"latest realm and period from the master zone, reapply your changes, "
233-
"and try again." << std::endl;
234-
return -EINVAL;
235-
}
236-
// did the master zone change?
237-
if (master_zone != current_period.get_master_zone()) {
238-
// store the current metadata sync status in the period
239-
int r = update_sync_status(dpp, driver, current_period, error_stream, force_if_stale);
240-
if (r < 0) {
241-
ldpp_dout(dpp, 0) << "failed to update metadata sync status: "
242-
<< cpp_strerror(-r) << dendl;
243-
return r;
244-
}
245-
// create an object with a new period id
246-
r = create(dpp, y, true);
247-
if (r < 0) {
248-
ldpp_dout(dpp, 0) << "failed to create new period: " << cpp_strerror(-r) << dendl;
249-
return r;
250-
}
251-
// set as current period
252-
r = realm.set_current_period(dpp, *this, y);
253-
if (r < 0) {
254-
ldpp_dout(dpp, 0) << "failed to update realm's current period: "
255-
<< cpp_strerror(-r) << dendl;
256-
return r;
257-
}
258-
ldpp_dout(dpp, 4) << "Promoted to master zone and committed new period "
259-
<< id << dendl;
260-
return 0;
261-
}
262-
// period must be based on current epoch
263-
if (epoch != current_period.get_epoch()) {
264-
error_stream << "Period epoch " << epoch << " does not match "
265-
"predecessor epoch " << current_period.get_epoch()
266-
<< ". Use 'period pull' to get the latest epoch from the master zone, "
267-
"reapply your changes, and try again." << std::endl;
268-
return -EINVAL;
269-
}
270-
// set period as next epoch
271-
set_id(current_period.get_id());
272-
set_epoch(current_period.get_epoch() + 1);
273-
set_predecessor(current_period.get_predecessor());
274-
realm_epoch = current_period.get_realm_epoch();
275-
// write the period to rados
276-
int r = store_info(dpp, false, y);
277-
if (r < 0) {
278-
ldpp_dout(dpp, 0) << "failed to store period: " << cpp_strerror(-r) << dendl;
279-
return r;
280-
}
281-
// set as latest epoch
282-
r = update_latest_epoch(dpp, epoch, y);
283-
if (r < 0) {
284-
ldpp_dout(dpp, 0) << "failed to set latest epoch: " << cpp_strerror(-r) << dendl;
285-
return r;
286-
}
287-
r = reflect(dpp, y);
288-
if (r < 0) {
289-
ldpp_dout(dpp, 0) << "failed to update local objects: " << cpp_strerror(-r) << dendl;
290-
return r;
291-
}
292-
ldpp_dout(dpp, 4) << "Committed new epoch " << epoch
293-
<< " for period " << id << dendl;
294-
return 0;
295-
}
296-
29797
void RGWPeriod::generate_test_instances(list<RGWPeriod*> &o)
29898
{
29999
RGWPeriod *z = new RGWPeriod;

0 commit comments

Comments
 (0)