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-
13932static 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-
29797void RGWPeriod::generate_test_instances (list<RGWPeriod*> &o)
29898{
29999 RGWPeriod *z = new RGWPeriod;
0 commit comments