]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_period_puller.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
6 #include "rgw_rest_conn.h"
7 #include "common/ceph_json.h"
8 #include "common/errno.h"
10 #include "services/svc_zone.h"
12 #define dout_subsys ceph_subsys_rgw
15 #define dout_prefix (*_dout << "rgw period puller: ")
17 RGWPeriodPuller::RGWPeriodPuller(RGWSI_Zone
*zone_svc
, RGWSI_SysObj
*sysobj_svc
)
19 cct
= zone_svc
->ctx();
21 svc
.sysobj
= sysobj_svc
;
26 // pull the given period over the connection
27 int pull_period(const DoutPrefixProvider
*dpp
, RGWRESTConn
* conn
, const std::string
& period_id
,
28 const std::string
& realm_id
, RGWPeriod
& period
,
33 req_info
info(conn
->get_ctx(), &env
);
35 info
.request_uri
= "/admin/realm/period";
37 auto& params
= info
.args
.get_params();
38 params
["realm_id"] = realm_id
;
39 params
["period_id"] = period_id
;
42 #define MAX_REST_RESPONSE (128 * 1024)
43 int r
= conn
->forward(dpp
, user
, info
, nullptr, MAX_REST_RESPONSE
, nullptr, &data
, y
);
49 r
= parser
.parse(data
.c_str(), data
.length());
51 ldpp_dout(dpp
, -1) << "request failed: " << cpp_strerror(-r
) << dendl
;
56 decode_json_obj(period
, &parser
);
57 } catch (const JSONDecoder::err
& e
) {
58 ldpp_dout(dpp
, -1) << "failed to decode JSON input: "
65 } // anonymous namespace
67 int RGWPeriodPuller::pull(const DoutPrefixProvider
*dpp
, const std::string
& period_id
, RGWPeriod
& period
,
70 // try to read the period from rados
71 period
.set_id(period_id
);
73 int r
= period
.init(dpp
, cct
, svc
.sysobj
, y
);
75 if (svc
.zone
->is_meta_master()) {
76 // can't pull if we're the master
77 ldpp_dout(dpp
, 1) << "metadata master failed to read period "
78 << period_id
<< " from local storage: " << cpp_strerror(r
) << dendl
;
81 ldpp_dout(dpp
, 14) << "pulling period " << period_id
82 << " from master" << dendl
;
83 // request the period from the master zone
84 r
= pull_period(dpp
, svc
.zone
->get_master_conn(), period_id
,
85 svc
.zone
->get_realm().get_id(), period
, y
);
87 ldpp_dout(dpp
, -1) << "failed to pull period " << period_id
<< dendl
;
90 // write the period to rados
91 r
= period
.store_info(dpp
, true, y
);
95 ldpp_dout(dpp
, -1) << "failed to store period " << period_id
<< dendl
;
98 // update latest epoch
99 r
= period
.update_latest_epoch(dpp
, period
.get_epoch(), y
);
101 // already have this epoch (or a more recent one)
105 ldpp_dout(dpp
, -1) << "failed to update latest_epoch for period "
106 << period_id
<< dendl
;
109 // reflect period objects if this is the latest version
110 if (svc
.zone
->get_realm().get_current_period() == period_id
) {
111 r
= period
.reflect(dpp
, y
);
116 ldpp_dout(dpp
, 14) << "period " << period_id
117 << " pulled and written to local storage" << dendl
;
119 ldpp_dout(dpp
, 14) << "found period " << period_id
120 << " in local storage" << dendl
;