summaryrefslogtreecommitdiffstats
path: root/src/rgw/services/svc_mdlog.cc
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@redhat.com>2019-03-16 00:31:20 +0100
committerCasey Bodley <cbodley@redhat.com>2019-07-29 21:20:46 +0200
commitee2370253247edd6ac7e713f65a970764240bd16 (patch)
tree0b44d5b2a47fb968d3e87b655f460b8a595430c9 /src/rgw/services/svc_mdlog.cc
parentrgw: initial meta manager refactoring (diff)
downloadceph-ee2370253247edd6ac7e713f65a970764240bd16.tar.xz
ceph-ee2370253247edd6ac7e713f65a970764240bd16.zip
rgw: more progress with meta restructure
Getting closer, but not there yet Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
Diffstat (limited to 'src/rgw/services/svc_mdlog.cc')
-rw-r--r--src/rgw/services/svc_mdlog.cc160
1 files changed, 90 insertions, 70 deletions
diff --git a/src/rgw/services/svc_mdlog.cc b/src/rgw/services/svc_mdlog.cc
index 98b88a98f5e..0a227967935 100644
--- a/src/rgw/services/svc_mdlog.cc
+++ b/src/rgw/services/svc_mdlog.cc
@@ -1,15 +1,54 @@
#include "svc_mdlog.h"
#include "svc_zone.h"
+#include "svc_sys_obj.h"
#include "rgw/rgw_tools.h"
#include "rgw/rgw_mdlog.h"
#include "rgw/rgw_coroutine.h"
+#include "rgw/rgw_cr_rados.h"
+#include "rgw/rgw_zone.h"
-int RGWSI_MDLog::read_history(RGWRados *store, RGWMetadataLogHistory *state,
- RGWObjVersionTracker *objv_tracker)
+#include "common/errno.h"
+
+#include <boost/asio/yield.hpp>
+
+#define dout_subsys ceph_subsys_rgw
+
+using Svc = RGWSI_MDLog::Svc;
+using Cursor = RGWPeriodHistory::Cursor;
+
+RGWSI_MDLog::RGWSI_MDLog(CephContext *cct) : RGWServiceInstance(cct) {
+}
+
+RGWSI_MDLog::~RGWSI_MDLog() {
+}
+
+int RGWSI_MDLog::init(RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc)
+{
+ svc.zone = zone_svc;
+ svc.sysobj = sysobj_svc;
+ svc.mdlog = this;
+
+ return 0;
+}
+
+int RGWSI_MDLog::do_start()
+{
+ auto& current_period = svc.zone->get_current_period();
+
+ current_log = get_log(current_period.get_id());
+
+ period_puller.reset(new RGWPeriodPuller(svc.zone, svc.sysobj));
+ period_history.reset(new RGWPeriodHistory(cct, period_puller.get(),
+ current_period.get_id()));
+ return 0;
+}
+
+int RGWSI_MDLog::read_history(RGWMetadataLogHistory *state,
+ RGWObjVersionTracker *objv_tracker) const
{
- auto obj_ctx = sysobj_svc->init_obj_ctx();
- auto& pool = zone_svc->get_zone_params().log_pool;
+ auto obj_ctx = svc.sysobj->init_obj_ctx();
+ auto& pool = svc.zone->get_zone_params().log_pool;
const auto& oid = RGWMetadataLogHistory::oid;
bufferlist bl;
int ret = rgw_get_system_obj(obj_ctx, pool, oid, bl, objv_tracker, nullptr, null_yield);
@@ -45,30 +84,28 @@ int RGWSI_MDLog::write_history(const RGWMetadataLogHistory& state,
bufferlist bl;
state.encode(bl);
- auto& pool = zone_svc->get_zone_params().log_pool;
+ auto& pool = svc.zone->get_zone_params().log_pool;
const auto& oid = RGWMetadataLogHistory::oid;
- return rgw_put_system_obj(sysobj_svc, pool, oid, bl,
+ auto obj_ctx = svc.sysobj->init_obj_ctx();
+ return rgw_put_system_obj(obj_ctx, pool, oid, bl,
exclusive, objv_tracker, real_time{});
}
-namespace {
+namespace mdlog {
using Cursor = RGWPeriodHistory::Cursor;
/// read the mdlog history and use it to initialize the given cursor
class ReadHistoryCR : public RGWCoroutine {
- RGWSI_Zone *zone_svc;
- RGWSI_SysObj *sysobj_svc;
+ Svc svc;
Cursor *cursor;
RGWObjVersionTracker *objv_tracker;
RGWMetadataLogHistory state;
public:
- ReadHistoryCR(RGWSI_Zone *zone_svc,
- RGWSI_SysObj *sysobj_svc,
+ ReadHistoryCR(const Svc& svc,
Cursor *cursor,
RGWObjVersionTracker *objv_tracker)
- : RGWCoroutine(zone_svc->ctx()), zone_svc(zone_svc),
- sysobj_svc(sysobj_svc),
+ : RGWCoroutine(svc.zone->ctx()), svc(svc),
cursor(cursor),
objv_tracker(objv_tracker)
{}
@@ -76,12 +113,12 @@ class ReadHistoryCR : public RGWCoroutine {
int operate() {
reenter(this) {
yield {
- rgw_raw_obj obj{zone_svc->get_zone_params().log_pool,
+ rgw_raw_obj obj{svc.zone->get_zone_params().log_pool,
RGWMetadataLogHistory::oid};
constexpr bool empty_on_enoent = false;
using ReadCR = RGWSimpleRadosReadCR<RGWMetadataLogHistory>;
- call(new ReadCR(store->get_async_rados(), sysobj_svc, obj,
+ call(new ReadCR(store->get_async_rados(), svc.sysobj, obj,
&state, empty_on_enoent, objv_tracker));
}
if (retcode < 0) {
@@ -89,7 +126,7 @@ class ReadHistoryCR : public RGWCoroutine {
<< cpp_strerror(retcode) << dendl;
return set_cr_error(retcode);
}
- *cursor = store->period_history->lookup(state.oldest_realm_epoch);
+ *cursor = svc.mdlog->period_history->lookup(state.oldest_realm_epoch);
if (!*cursor) {
return set_cr_error(cursor->get_error());
}
@@ -105,16 +142,16 @@ class ReadHistoryCR : public RGWCoroutine {
/// write the given cursor to the mdlog history
class WriteHistoryCR : public RGWCoroutine {
- RGWSI_Zone *zone_svc;
- RGWSI_SysObj *sysobj_svc;
+ Svc svc;
Cursor cursor;
RGWObjVersionTracker *objv;
RGWMetadataLogHistory state;
public:
- WriteHistoryCR(RGWSI_Zone *zone_svc, RGWSI_SysObj *sysobj_svc,
+ WriteHistoryCR(Svc& svc,
const Cursor& cursor,
RGWObjVersionTracker *objv)
- : RGWCoroutine(zone_svc->ctx()), zone_svc(zone_svc), cursor(cursor), objv(objv)
+ : RGWCoroutine(svc.zone->ctx()), svc(svc),
+ cursor(cursor), objv(objv)
{}
int operate() {
@@ -123,11 +160,11 @@ class WriteHistoryCR : public RGWCoroutine {
state.oldest_realm_epoch = cursor.get_epoch();
yield {
- rgw_raw_obj obj{zone_svc->get_zone_params().log_pool,
+ rgw_raw_obj obj{svc.zone->get_zone_params().log_pool,
RGWMetadataLogHistory::oid};
using WriteCR = RGWSimpleRadosWriteCR<RGWMetadataLogHistory>;
- call(new WriteCR(store->get_async_rados(), sysobj_svc, obj, state, objv));
+ call(new WriteCR(store->get_async_rados(), svc.sysobj, obj, state, objv));
}
if (retcode < 0) {
ldout(cct, 1) << "failed to write mdlog history: "
@@ -146,24 +183,23 @@ class WriteHistoryCR : public RGWCoroutine {
/// update the mdlog history to reflect trimmed logs
class TrimHistoryCR : public RGWCoroutine {
- RGWRados *store;
+ Svc svc;
const Cursor cursor; //< cursor to trimmed period
RGWObjVersionTracker *objv; //< to prevent racing updates
Cursor next; //< target cursor for oldest log period
Cursor existing; //< existing cursor read from disk
public:
- TrimHistoryCR(RGWRados *store, Cursor cursor, RGWObjVersionTracker *objv)
- : RGWCoroutine(store->ctx()),
- store(store), cursor(cursor), objv(objv), next(cursor)
- {
+ TrimHistoryCR(const Svc& svc, Cursor cursor, RGWObjVersionTracker *objv)
+ : RGWCoroutine(svc.zone->ctx()), svc(svc),
+ cursor(cursor), objv(objv), next(cursor) {
next.next(); // advance past cursor
}
int operate() {
reenter(this) {
// read an existing history, and write the new history if it's newer
- yield call(new ReadHistoryCR(store, &existing, objv));
+ yield call(new ReadHistoryCR(svc, &existing, objv));
if (retcode < 0) {
return set_cr_error(retcode);
}
@@ -174,7 +210,7 @@ class TrimHistoryCR : public RGWCoroutine {
return set_cr_error(-ECANCELED);
}
// overwrite with updated history
- yield call(new WriteHistoryCR(store, next, objv));
+ yield call(new WriteHistoryCR(svc, next, objv));
if (retcode < 0) {
return set_cr_error(retcode);
}
@@ -184,12 +220,13 @@ class TrimHistoryCR : public RGWCoroutine {
}
};
+} // mdlog namespace
+
// traverse all the way back to the beginning of the period history, and
// return a cursor to the first period in a fully attached history
-Cursor find_oldest_period(RGWRados *store)
+Cursor RGWSI_MDLog::find_oldest_period()
{
- auto cct = store->ctx();
- auto cursor = store->period_history->get_current();
+ auto cursor = period_history->get_current();
while (cursor) {
// advance to the period's predecessor
@@ -203,11 +240,11 @@ Cursor find_oldest_period(RGWRados *store)
}
// pull the predecessor and add it to our history
RGWPeriod period;
- int r = store->period_puller->pull(predecessor, period);
+ int r = period_puller->pull(predecessor, period);
if (r < 0) {
return Cursor{r};
}
- auto prev = store->period_history->insert(std::move(period));
+ auto prev = period_history->insert(std::move(period));
if (!prev) {
return prev;
}
@@ -221,19 +258,17 @@ Cursor find_oldest_period(RGWRados *store)
return cursor;
}
-} // anonymous namespace
-
-Cursor RGWMetadataManager::init_oldest_log_period()
+Cursor RGWSI_MDLog::init_oldest_log_period()
{
// read the mdlog history
RGWMetadataLogHistory state;
RGWObjVersionTracker objv;
- int ret = read_history(store, &state, &objv);
+ int ret = read_history(&state, &objv);
if (ret == -ENOENT) {
// initialize the mdlog history and write it
ldout(cct, 10) << "initializing mdlog history" << dendl;
- auto cursor = find_oldest_period(store);
+ auto cursor = find_oldest_period();
if (!cursor) {
return cursor;
}
@@ -243,7 +278,7 @@ Cursor RGWMetadataManager::init_oldest_log_period()
state.oldest_period_id = cursor.get_period().get_id();
constexpr bool exclusive = true; // don't overwrite
- int ret = write_history(store, state, &objv, exclusive);
+ int ret = write_history(state, &objv, exclusive);
if (ret < 0 && ret != -EEXIST) {
ldout(cct, 1) << "failed to write mdlog history: "
<< cpp_strerror(ret) << dendl;
@@ -257,13 +292,13 @@ Cursor RGWMetadataManager::init_oldest_log_period()
}
// if it's already in the history, return it
- auto cursor = store->period_history->lookup(state.oldest_realm_epoch);
+ auto cursor = period_history->lookup(state.oldest_realm_epoch);
if (cursor) {
return cursor;
}
// pull the oldest period by id
RGWPeriod period;
- ret = store->period_puller->pull(state.oldest_period_id, period);
+ ret = period_puller->pull(state.oldest_period_id, period);
if (ret < 0) {
ldout(cct, 1) << "failed to read period id=" << state.oldest_period_id
<< " for mdlog history: " << cpp_strerror(ret) << dendl;
@@ -277,39 +312,39 @@ Cursor RGWMetadataManager::init_oldest_log_period()
return Cursor{-EINVAL};
}
// attach the period to our history
- return store->period_history->attach(std::move(period));
+ return period_history->attach(std::move(period));
}
-Cursor RGWMetadataManager::read_oldest_log_period() const
+Cursor RGWSI_MDLog::read_oldest_log_period() const
{
RGWMetadataLogHistory state;
- int ret = read_history(store, &state, nullptr);
+ int ret = read_history(&state, nullptr);
if (ret < 0) {
- ldout(store->ctx(), 1) << "failed to read mdlog history: "
+ ldout(cct, 1) << "failed to read mdlog history: "
<< cpp_strerror(ret) << dendl;
return Cursor{ret};
}
- ldout(store->ctx(), 10) << "read mdlog history with oldest period id="
+ ldout(cct, 10) << "read mdlog history with oldest period id="
<< state.oldest_period_id << " realm_epoch="
<< state.oldest_realm_epoch << dendl;
- return store->period_history->lookup(state.oldest_realm_epoch);
+ return period_history->lookup(state.oldest_realm_epoch);
}
-RGWCoroutine* RGWMetadataManager::read_oldest_log_period_cr(Cursor *period,
+RGWCoroutine* RGWSI_MDLog::read_oldest_log_period_cr(Cursor *period,
RGWObjVersionTracker *objv) const
{
- return new ReadHistoryCR(store, period, objv);
+ return new mdlog::ReadHistoryCR(svc, period, objv);
}
-RGWCoroutine* RGWMetadataManager::trim_log_period_cr(Cursor period,
+RGWCoroutine* RGWSI_MDLog::trim_log_period_cr(Cursor period,
RGWObjVersionTracker *objv) const
{
- return new TrimHistoryCR(store, period, objv);
+ return new mdlog::TrimHistoryCR(svc, period, objv);
}
-RGWMetadataLog* RGWMetadataManager::get_log(const std::string& period)
+RGWMetadataLog* RGWSI_MDLog::get_log(const std::string& period)
{
// construct the period's log in place if it doesn't exist
auto insert = md_logs.emplace(std::piecewise_construct,
@@ -318,23 +353,8 @@ RGWMetadataLog* RGWMetadataManager::get_log(const std::string& period)
return &insert.first->second;
}
-int init(RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc,
- const std::string& current_period)
-{
- zone_svc = _zone_svc;
- sysobj_svc = _sysobj_svc;
- current_log = get_log(current_period);
-
- period_puller.reset(new RGWPeriodPuller(this));
- period_history.reset(new RGWPeriodHistory(cct, period_puller.get(),
- zone_svc->get_current_period()));
-
- return 0;
-}
-}
-
-int RGWSI_MDLog::add_entry(RGWSI_MetaBacked::Module *module, const string& section, const string& key, bufferlist& bl)
+int RGWSI_MDLog::add_entry(RGWSI_MetaBackend::Module *module, const string& section, const string& key, bufferlist& bl)
{
ceph_assert(current_log); // must have called init()
- return current_log->add_entry(module, section, key, logbl);
+ return current_log->add_entry(module, section, key, bl);
}