1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 #include "rgw_rest_conn.h"
6 #include "common/ceph_json.h"
7 #include "common/errno.h"
9 #define dout_subsys ceph_subsys_rgw
12 #define dout_prefix (*_dout << "rgw period puller: ")
16 // pull the given period over the connection
17 int pull_period(RGWRESTConn* conn, const std::string& period_id,
18 const std::string& realm_id, RGWPeriod& period)
22 req_info info(conn->get_ctx(), &env);
24 info.request_uri = "/admin/realm/period";
26 auto& params = info.args.get_params();
27 params["realm_id"] = realm_id;
28 params["period_id"] = period_id;
31 #define MAX_REST_RESPONSE (128 * 1024)
32 int r = conn->forward(user, info, nullptr, MAX_REST_RESPONSE, nullptr, &data);
38 r = parser.parse(data.c_str(), data.length());
40 lderr(conn->get_ctx()) << "request failed: " << cpp_strerror(-r) << dendl;
45 decode_json_obj(period, &parser);
46 } catch (JSONDecoder::err& e) {
47 lderr(conn->get_ctx()) << "failed to decode JSON input: "
48 << e.message << dendl;
54 } // anonymous namespace
56 int RGWPeriodPuller::pull(const std::string& period_id, RGWPeriod& period)
58 // try to read the period from rados
59 period.set_id(period_id);
61 int r = period.init(store->ctx(), store);
63 if (store->is_meta_master()) {
64 // can't pull if we're the master
65 ldout(store->ctx(), 1) << "metadata master failed to read period "
66 << period_id << " from local storage: " << cpp_strerror(r) << dendl;
69 ldout(store->ctx(), 14) << "pulling period " << period_id
70 << " from master" << dendl;
71 // request the period from the master zone
72 r = pull_period(store->rest_master_conn, period_id,
73 store->realm.get_id(), period);
75 lderr(store->ctx()) << "failed to pull period " << period_id << dendl;
78 // write the period to rados
79 r = period.store_info(true);
83 lderr(store->ctx()) << "failed to store period " << period_id << dendl;
86 // update latest epoch
87 r = period.update_latest_epoch(period.get_epoch());
89 // already have this epoch (or a more recent one)
93 lderr(store->ctx()) << "failed to update latest_epoch for period "
94 << period_id << dendl;
97 // reflect period objects if this is the latest version
102 ldout(store->ctx(), 14) << "period " << period_id
103 << " pulled and written to local storage" << dendl;
105 ldout(store->ctx(), 14) << "found period " << period_id
106 << " in local storage" << dendl;