From af5eb09aa7db31b12182638a873e433c6fb7f680 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 11 Sep 2018 07:46:30 -0700 Subject: [PATCH] rgw: svc: remove SystemObject impl Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 6 +- src/rgw/rgw_bucket.cc | 53 ++-- src/rgw/rgw_cache.h | 17 ++ src/rgw/rgw_common.h | 6 +- src/rgw/rgw_cr_rados.cc | 46 +++- src/rgw/rgw_cr_rados.h | 63 ++--- src/rgw/rgw_data_sync.cc | 32 +-- src/rgw/rgw_lc.cc | 4 +- src/rgw/rgw_metadata.cc | 25 +- src/rgw/rgw_object_expirer_core.cc | 4 +- src/rgw/rgw_op.cc | 34 ++- src/rgw/rgw_op.h | 9 +- src/rgw/rgw_orphan.cc | 4 +- src/rgw/rgw_process.cc | 3 + src/rgw/rgw_quota.cc | 8 +- src/rgw/rgw_rados.cc | 391 ++------------------------- src/rgw/rgw_rados.h | 216 +-------------- src/rgw/rgw_reshard.cc | 3 +- src/rgw/rgw_rest_bucket.cc | 4 +- src/rgw/rgw_rest_log.cc | 20 +- src/rgw/rgw_rest_s3.cc | 6 +- src/rgw/rgw_rest_swift.cc | 2 +- src/rgw/rgw_role.cc | 7 +- src/rgw/rgw_swift_auth.cc | 2 +- src/rgw/rgw_sync.cc | 22 +- src/rgw/rgw_sync_log_trim.cc | 4 +- src/rgw/rgw_sync_module_aws.cc | 4 +- src/rgw/rgw_tools.cc | 54 ++-- src/rgw/rgw_tools.h | 6 +- src/rgw/rgw_user.cc | 41 +-- src/rgw/services/svc_sys_obj.cc | 13 +- src/rgw/services/svc_sys_obj.h | 20 +- src/rgw/services/svc_sys_obj_cache.h | 59 ++++ 33 files changed, 421 insertions(+), 767 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 9e1b9fbdb48..792fdf2e180 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1093,7 +1093,7 @@ static int init_bucket(const string& tenant_name, const string& bucket_name, con RGWBucketInfo& bucket_info, rgw_bucket& bucket, map *pattrs = nullptr) { if (!bucket_name.empty()) { - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r; if (bucket_id.empty()) { r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, nullptr, pattrs); @@ -1282,7 +1282,7 @@ int set_bucket_quota(RGWRados *store, int opt_cmd, { RGWBucketInfo bucket_info; map attrs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL, &attrs); if (r < 0) { cerr << "could not get bucket info for bucket=" << bucket_name << ": " << cpp_strerror(-r) << std::endl; @@ -1549,7 +1549,7 @@ int set_bucket_sync_enabled(RGWRados *store, int opt_cmd, const string& tenant_n { RGWBucketInfo bucket_info; map attrs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL, &attrs); if (r < 0) { diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 277f2f9f66f..7d97db93a23 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -24,6 +24,7 @@ #include "rgw_multi.h" #include "services/svc_zone.h" +#include "services/svc_sys_obj.h" #include "include/rados/librados.hpp" // until everything is moved from rgw_common @@ -165,7 +166,7 @@ int rgw_bucket_sync_user_stats(RGWRados *store, const rgw_user& user_id, const R int rgw_bucket_sync_user_stats(RGWRados *store, const string& tenant_name, const string& bucket_name) { RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL); if (ret < 0) { ldout(store->ctx(), 0) << "ERROR: could not fetch bucket info: ret=" << ret << dendl; @@ -204,7 +205,7 @@ int rgw_link_bucket(RGWRados* const store, new_bucket.creation_time = creation_time; map attrs; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); if (update_entrypoint) { ret = store->get_bucket_entrypoint_info(obj_ctx, tenant_name, bucket_name, ep, &ot, NULL, &attrs); @@ -267,7 +268,7 @@ int rgw_unlink_bucket(RGWRados *store, const rgw_user& user_id, const string& te RGWBucketEntryPoint ep; RGWObjVersionTracker ot; map attrs; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); ret = store->get_bucket_entrypoint_info(obj_ctx, tenant_name, bucket_name, ep, &ot, NULL, &attrs); if (ret == -ENOENT) return 0; @@ -410,7 +411,7 @@ int rgw_bucket_set_attrs(RGWRados *store, RGWBucketInfo& bucket_info, if (!bucket_info.has_instance_obj) { /* an old bucket object, need to convert it */ - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = store->convert_old_bucket_info(obj_ctx, bucket.tenant, bucket.name); if (ret < 0) { ldout(store->ctx(), 0) << "ERROR: failed converting old bucket info: " << ret << dendl; @@ -467,7 +468,7 @@ void check_bad_user_bucket_mapping(RGWRados *store, const rgw_user& user_id, RGWBucketInfo bucket_info; real_time mtime; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_info(obj_ctx, user_id.tenant, bucket.name, bucket_info, &mtime); if (r < 0) { ldout(store->ctx(), 0) << "could not get bucket info for bucket=" << bucket << dendl; @@ -521,7 +522,7 @@ int rgw_remove_bucket(RGWRados *store, rgw_bucket& bucket, bool delete_children) std::vector objs; map common_prefixes; RGWBucketInfo info; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); string bucket_ver, master_ver; @@ -621,11 +622,12 @@ int rgw_remove_bucket_bypass_gc(RGWRados *store, rgw_bucket& bucket, map common_prefixes; RGWBucketInfo info; RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx sysobj_ctx = store->svc.sysobj->init_obj_ctx(); CephContext *cct = store->ctx(); string bucket_ver, master_ver; - ret = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL); + ret = store->get_bucket_info(sysobj_ctx, bucket.tenant, bucket.name, info, NULL); if (ret < 0) return ret; @@ -778,7 +780,7 @@ int RGWBucket::init(RGWRados *storage, RGWBucketAdminOpState& op_state) tenant = user_id.tenant; bucket_name = op_state.get_bucket_name(); RGWUserBuckets user_buckets; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); if (bucket_name.empty() && user_id.empty()) return -EINVAL; @@ -830,7 +832,7 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state, std::string *err_msg) map attrs; RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_instance_info(obj_ctx, bucket, bucket_info, NULL, &attrs); if (r < 0) { return r; @@ -873,7 +875,10 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state, std::string *err_msg) aclbl.clear(); policy.encode(aclbl); - r = store->system_obj_set_attr(NULL, obj, RGW_ATTR_ACL, aclbl, &objv_tracker); + auto sysobj = obj_ctx.get_obj(obj); + r = sysobj.wop() + .set_objv_tracker(&objv_tracker) + .write_attr(RGW_ATTR_ACL, aclbl); if (r < 0) { return r; } @@ -885,7 +890,10 @@ int RGWBucket::link(RGWBucketAdminOpState& op_state, std::string *err_msg) rgw_raw_obj obj_bucket_instance; store->get_bucket_instance_obj(bucket, obj_bucket_instance); - r = store->system_obj_set_attr(NULL, obj_bucket_instance, RGW_ATTR_ACL, aclbl, &objv_tracker); + auto inst_sysobj = obj_ctx.get_obj(obj_bucket_instance); + r = inst_sysobj.wop() + .set_objv_tracker(&objv_tracker) + .write_attr(RGW_ATTR_ACL, aclbl); if (r < 0) { return r; } @@ -922,7 +930,7 @@ int RGWBucket::set_quota(RGWBucketAdminOpState& op_state, std::string *err_msg) rgw_bucket bucket = op_state.get_bucket(); RGWBucketInfo bucket_info; map attrs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, bucket_info, NULL, &attrs); if (r < 0) { set_err_msg(err_msg, "could not get bucket info for bucket=" + bucket.name + ": " + cpp_strerror(-r)); @@ -1032,7 +1040,7 @@ int RGWBucket::check_bad_index_multipart(RGWBucketAdminOpState& op_state, map all_objs; RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_instance_info(obj_ctx, bucket, bucket_info, nullptr, nullptr); if (r < 0) { ldout(store->ctx(), 0) << "ERROR: " << __func__ << "(): get_bucket_instance_info(bucket=" << bucket << ") returned r=" << r << dendl; @@ -1225,11 +1233,12 @@ int RGWBucket::get_policy(RGWBucketAdminOpState& op_state, RGWAccessControlPolic { std::string object_name = op_state.get_object_name(); rgw_bucket bucket = op_state.get_bucket(); + auto sysobj_ctx = store->svc.sysobj->init_obj_ctx(); RGWObjectCtx obj_ctx(store); RGWBucketInfo bucket_info; map attrs; - int ret = store->get_bucket_info(obj_ctx, bucket.tenant, bucket.name, bucket_info, NULL, &attrs); + int ret = store->get_bucket_info(sysobj_ctx, bucket.tenant, bucket.name, bucket_info, NULL, &attrs); if (ret < 0) { return ret; } @@ -1404,7 +1413,7 @@ static int bucket_stats(RGWRados *store, const std::string& tenant_name, std::st map stats; real_time mtime; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, &mtime); if (r < 0) return r; @@ -1490,7 +1499,7 @@ int RGWBucketAdminOp::limit_check(RGWRados *store, /* need info for num_shards */ RGWBucketInfo info; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); marker = bucket.name; /* Casey's location for marker update, * as we may now not reach the end of @@ -2103,7 +2112,7 @@ public: real_time mtime; map attrs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); string tenant_name, bucket_name; parse_bucket(entry, &tenant_name, &bucket_name); @@ -2131,7 +2140,7 @@ public: map attrs; RGWObjVersionTracker old_ot; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); string tenant_name, bucket_name; parse_bucket(entry, &tenant_name, &bucket_name); @@ -2170,7 +2179,7 @@ public: int remove(RGWRados *store, string& entry, RGWObjVersionTracker& objv_tracker) override { RGWBucketEntryPoint be; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); string tenant_name, bucket_name; parse_bucket(entry, &tenant_name, &bucket_name); @@ -2270,7 +2279,7 @@ public: RGWBucketCompleteInfo bci; real_time mtime; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = store->get_bucket_instance_info(obj_ctx, oid, bci.info, &mtime, &bci.attrs); if (ret < 0) @@ -2293,7 +2302,7 @@ public: } real_time orig_mtime; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = store->get_bucket_instance_info(obj_ctx, entry, old_bci.info, &orig_mtime, &old_bci.attrs); @@ -2385,7 +2394,7 @@ public: int remove(RGWRados *store, string& entry, RGWObjVersionTracker& objv_tracker) override { RGWBucketInfo info; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = store->get_bucket_instance_info(obj_ctx, entry, info, NULL, NULL); if (ret < 0 && ret != -ENOENT) diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index 498c86c2326..3a1c3495edc 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -126,6 +126,23 @@ struct RGWCacheNotifyInfo { }; WRITE_CLASS_ENCODER(RGWCacheNotifyInfo) +class RGWChainedCache { +public: + virtual ~RGWChainedCache() {} + virtual void chain_cb(const string& key, void *data) = 0; + virtual void invalidate(const string& key) = 0; + virtual void invalidate_all() = 0; + + struct Entry { + RGWChainedCache *cache; + const string& key; + void *data; + + Entry(RGWChainedCache *_c, const string& _k, void *_d) : cache(_c), key(_k), data(_d) {} + }; +}; + + struct ObjectCacheEntry { ObjectCacheInfo info; std::list::iterator lru_iter; diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 0fcdca142c9..e1e1e411b05 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1795,6 +1795,9 @@ struct req_init_state { #include "rgw_auth.h" +class RGWObjectCtx; +class RGWSysObjectCtx; + /** Store all the state necessary to complete and respond to an HTTP request*/ struct req_state : DoutPrefixProvider { CephContext *cct; @@ -1913,7 +1916,8 @@ struct req_state : DoutPrefixProvider { Clock::duration time_elapsed() const { return Clock::now() - time; } - void *obj_ctx{nullptr}; + RGWObjectCtx *obj_ctx{nullptr}; + RGWSysObjectCtx *sysobj_ctx{nullptr}; string dialect; string req_id; string trans_id; diff --git a/src/rgw/rgw_cr_rados.cc b/src/rgw/rgw_cr_rados.cc index 1a2654f991f..8d3e452da98 100644 --- a/src/rgw/rgw_cr_rados.cc +++ b/src/rgw/rgw_cr_rados.cc @@ -5,6 +5,7 @@ #include "services/svc_zone.h" #include "services/svc_zone_utils.h" +#include "services/svc_sys_obj.h" #include "cls/lock/cls_lock_client.h" #include "cls/rgw/cls_rgw_client.h" @@ -93,15 +94,18 @@ int RGWAsyncGetSystemObj::_send_request() { map *pattrs = want_attrs ? &attrs : nullptr; - return store->get_system_obj(obj_ctx, read_state, &objv_tracker, - obj, bl, ofs, end, pattrs, nullptr); + auto sysobj = obj_ctx.get_obj(obj); + return sysobj.rop() + .set_objv_tracker(&objv_tracker) + .set_attrs(pattrs) + .read(&bl); } -RGWAsyncGetSystemObj::RGWAsyncGetSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, +RGWAsyncGetSystemObj::RGWAsyncGetSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWSI_SysObj *_svc, RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, - off_t _ofs, off_t _end, bool want_attrs) - : RGWAsyncRadosRequest(caller, cn), store(_store), obj_ctx(_store), - obj(_obj), ofs(_ofs), end(_end), want_attrs(want_attrs) + bool want_attrs) + : RGWAsyncRadosRequest(caller, cn), obj_ctx(_svc), + obj(_obj), want_attrs(want_attrs) { if (_objv_tracker) { objv_tracker = *_objv_tracker; @@ -111,7 +115,7 @@ RGWAsyncGetSystemObj::RGWAsyncGetSystemObj(RGWCoroutine *caller, RGWAioCompletio int RGWSimpleRadosReadAttrsCR::send_request() { req = new RGWAsyncGetSystemObj(this, stack->create_completion_notifier(), - store, nullptr, obj, 0, -1, true); + svc, nullptr, obj, true); async_rados->queue(req); return 0; } @@ -126,10 +130,16 @@ int RGWSimpleRadosReadAttrsCR::request_complete() int RGWAsyncPutSystemObj::_send_request() { - return store->put_system_obj_data(NULL, obj, bl, -1, exclusive, &objv_tracker); + auto obj_ctx = svc->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + return sysobj.wop() + .set_objv_tracker(&objv_tracker) + .set_exclusive(exclusive) + .write_data(bl); } -RGWAsyncPutSystemObj::RGWAsyncPutSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, +RGWAsyncPutSystemObj::RGWAsyncPutSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, + RGWSI_SysObj *_svc, RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, bool _exclusive, bufferlist _bl) : RGWAsyncRadosRequest(caller, cn), store(_store), @@ -142,15 +152,25 @@ RGWAsyncPutSystemObj::RGWAsyncPutSystemObj(RGWCoroutine *caller, RGWAioCompletio int RGWAsyncPutSystemObjAttrs::_send_request() { - return store->system_obj_set_attrs(nullptr, obj, attrs, nullptr, &objv_tracker); + auto obj_ctx = svc->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + return sysobj.wop() + .set_objv_tracker(&objv_tracker) + .set_exclusive(false) + .set_attrs(attrs) + .write_attrs(); } -RGWAsyncPutSystemObjAttrs::RGWAsyncPutSystemObjAttrs(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, +RGWAsyncPutSystemObjAttrs::RGWAsyncPutSystemObjAttrs(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, + RGWSI_SysObj *_svc, RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, map _attrs) - : RGWAsyncRadosRequest(caller, cn), store(_store), + : RGWAsyncRadosRequest(caller, cn), svc(_svc), obj(_obj), attrs(std::move(_attrs)) { + if (_objv_tracker) { + objv_tracker = *_objv_tracker; + } } @@ -502,7 +522,7 @@ bool RGWOmapAppend::finish() { int RGWAsyncGetBucketInstanceInfo::_send_request() { - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_instance_from_oid(obj_ctx, oid, bucket_info, NULL, NULL); if (r < 0) { ldout(store->ctx(), 0) << "ERROR: failed to get bucket instance info for " diff --git a/src/rgw/rgw_cr_rados.h b/src/rgw/rgw_cr_rados.h index ef019347d11..3cb0b99991d 100644 --- a/src/rgw/rgw_cr_rados.h +++ b/src/rgw/rgw_cr_rados.h @@ -10,6 +10,8 @@ #include +#include "services/svc_sys_obj.h" + class RGWAsyncRadosRequest : public RefCountedObject { RGWCoroutine *caller; RGWAioCompletionNotifier *notifier; @@ -101,27 +103,23 @@ public: class RGWAsyncGetSystemObj : public RGWAsyncRadosRequest { - RGWRados *store; - RGWObjectCtx obj_ctx; - RGWRados::SystemObject::Read::GetObjState read_state; + RGWSysObjectCtx obj_ctx; RGWObjVersionTracker objv_tracker; rgw_raw_obj obj; - off_t ofs; - off_t end; const bool want_attrs; protected: int _send_request() override; public: - RGWAsyncGetSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, + RGWAsyncGetSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWSI_SysObj *_svc, RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, - off_t _ofs, off_t _end, bool want_attrs); + bool want_attrs); bufferlist bl; map attrs; }; class RGWAsyncPutSystemObj : public RGWAsyncRadosRequest { - RGWRados *store; + RGWSI_SysObj *svc; rgw_raw_obj obj; bool exclusive; bufferlist bl; @@ -129,7 +127,7 @@ class RGWAsyncPutSystemObj : public RGWAsyncRadosRequest { protected: int _send_request() override; public: - RGWAsyncPutSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, + RGWAsyncPutSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWSI_SysObj *_svc, RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, bool _exclusive, bufferlist _bl); @@ -137,14 +135,14 @@ public: }; class RGWAsyncPutSystemObjAttrs : public RGWAsyncRadosRequest { - RGWRados *store; + RGWSI_SysObj *svc; rgw_raw_obj obj; map attrs; protected: int _send_request() override; public: - RGWAsyncPutSystemObjAttrs(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWRados *_store, + RGWAsyncPutSystemObjAttrs(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWSI_SysObj *_svc, RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj, map _attrs); @@ -183,7 +181,8 @@ public: template class RGWSimpleRadosReadCR : public RGWSimpleCoroutine { RGWAsyncRadosProcessor *async_rados; - RGWRados *store; + RGWSI_SysObj *svc; + rgw_raw_obj obj; T *result; /// on ENOENT, call handle_data() with an empty object instead of failing @@ -192,11 +191,11 @@ class RGWSimpleRadosReadCR : public RGWSimpleCoroutine { RGWAsyncGetSystemObj *req{nullptr}; public: - RGWSimpleRadosReadCR(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, + RGWSimpleRadosReadCR(RGWAsyncRadosProcessor *_async_rados, RGWSI_SysObj *_svc, const rgw_raw_obj& _obj, T *_result, bool empty_on_enoent = true, RGWObjVersionTracker *objv_tracker = nullptr) - : RGWSimpleCoroutine(_store->ctx()), async_rados(_async_rados), store(_store), + : RGWSimpleCoroutine(_svc->ctx()), async_rados(_async_rados), svc(_svc), obj(_obj), result(_result), empty_on_enoent(empty_on_enoent), objv_tracker(objv_tracker) {} ~RGWSimpleRadosReadCR() override { @@ -221,8 +220,8 @@ public: template int RGWSimpleRadosReadCR::send_request() { - req = new RGWAsyncGetSystemObj(this, stack->create_completion_notifier(), - store, objv_tracker, obj, 0, -1, false); + req = new RGWAsyncGetSystemObj(this, stack->create_completion_notifier(), svc, + objv_tracker, obj, false); async_rados->queue(req); return 0; } @@ -259,19 +258,20 @@ int RGWSimpleRadosReadCR::request_complete() class RGWSimpleRadosReadAttrsCR : public RGWSimpleCoroutine { RGWAsyncRadosProcessor *async_rados; - RGWRados *store; + RGWSI_SysObj *svc; + rgw_raw_obj obj; map *pattrs; RGWAsyncGetSystemObj *req; public: - RGWSimpleRadosReadAttrsCR(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, + RGWSimpleRadosReadAttrsCR(RGWAsyncRadosProcessor *_async_rados, RGWSI_SysObj *_svc, const rgw_raw_obj& _obj, - map *_pattrs) : RGWSimpleCoroutine(_store->ctx()), - async_rados(_async_rados), store(_store), + map *_pattrs) : RGWSimpleCoroutine(_svc->ctx()), + async_rados(_async_rados), svc(_svc), obj(_obj), pattrs(_pattrs), - req(NULL) { } + req(NULL) {} ~RGWSimpleRadosReadAttrsCR() override { request_cleanup(); } @@ -290,18 +290,18 @@ public: template class RGWSimpleRadosWriteCR : public RGWSimpleCoroutine { RGWAsyncRadosProcessor *async_rados; - RGWRados *store; + RGWSI_SysObj *svc; bufferlist bl; rgw_raw_obj obj; RGWObjVersionTracker *objv_tracker; RGWAsyncPutSystemObj *req{nullptr}; public: - RGWSimpleRadosWriteCR(RGWAsyncRadosProcessor *_async_rados, RGWRados *_store, + RGWSimpleRadosWriteCR(RGWAsyncRadosProcessor *_async_rados, RGWSI_SysObj *_svc, const rgw_raw_obj& _obj, const T& _data, RGWObjVersionTracker *objv_tracker = nullptr) - : RGWSimpleCoroutine(_store->ctx()), async_rados(_async_rados), - store(_store), obj(_obj), objv_tracker(objv_tracker) { + : RGWSimpleCoroutine(_svc->ctx()), async_rados(_async_rados), + svc(_svc), obj(_obj), objv_tracker(objv_tracker) { encode(_data, bl); } @@ -318,7 +318,7 @@ public: int send_request() override { req = new RGWAsyncPutSystemObj(this, stack->create_completion_notifier(), - store, objv_tracker, obj, false, std::move(bl)); + svc, objv_tracker, obj, false, std::move(bl)); async_rados->queue(req); return 0; } @@ -333,19 +333,20 @@ public: class RGWSimpleRadosWriteAttrsCR : public RGWSimpleCoroutine { RGWAsyncRadosProcessor *async_rados; - RGWRados *store; + RGWSI_SysObj *svc; RGWObjVersionTracker *objv_tracker; + rgw_raw_obj obj; map attrs; RGWAsyncPutSystemObjAttrs *req = nullptr; public: RGWSimpleRadosWriteAttrsCR(RGWAsyncRadosProcessor *_async_rados, - RGWRados *_store, const rgw_raw_obj& _obj, + RGWSI_SysObj *_svc, const rgw_raw_obj& _obj, map _attrs, RGWObjVersionTracker *objv_tracker = nullptr) - : RGWSimpleCoroutine(_store->ctx()), async_rados(_async_rados), - store(_store), objv_tracker(objv_tracker), obj(_obj), + : RGWSimpleCoroutine(_svc->ctx()), async_rados(_async_rados), + svc(_svc), objv_tracker(objv_tracker), obj(_obj), attrs(std::move(_attrs)) { } ~RGWSimpleRadosWriteAttrsCR() override { @@ -361,7 +362,7 @@ public: int send_request() override { req = new RGWAsyncPutSystemObjAttrs(this, stack->create_completion_notifier(), - store, objv_tracker, obj, std::move(attrs)); + svc, objv_tracker, obj, std::move(attrs)); async_rados->queue(req); return 0; } diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index ad8aa1b8774..0f5417ff4d1 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -86,7 +86,7 @@ bool RGWReadDataSyncStatusMarkersCR::spawn_next() return false; } using CR = RGWSimpleRadosReadCR; - spawn(new CR(env->async_rados, env->store, + spawn(new CR(env->async_rados, env->store->svc.sysobj, rgw_raw_obj(env->store->svc.zone->get_zone_params().log_pool, RGWDataSyncStatusManager::shard_obj_name(env->source_zone, shard_id)), &markers[shard_id]), false); @@ -149,7 +149,7 @@ int RGWReadDataSyncStatusCoroutine::operate() using ReadInfoCR = RGWSimpleRadosReadCR; yield { bool empty_on_enoent = false; // fail on ENOENT - call(new ReadInfoCR(sync_env->async_rados, sync_env->store, + call(new ReadInfoCR(sync_env->async_rados, sync_env->store->svc.sysobj, rgw_raw_obj(sync_env->store->svc.zone->get_zone_params().log_pool, RGWDataSyncStatusManager::sync_status_oid(sync_env->source_zone)), &sync_status->sync_info, empty_on_enoent)); } @@ -487,7 +487,7 @@ public: return set_cr_error(retcode); } using WriteInfoCR = RGWSimpleRadosWriteCR; - yield call(new WriteInfoCR(sync_env->async_rados, store, + yield call(new WriteInfoCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj{pool, sync_status_oid}, status->sync_info)); if (retcode < 0) { @@ -532,7 +532,7 @@ public: marker.timestamp = info.last_update; const auto& oid = RGWDataSyncStatusManager::shard_obj_name(sync_env->source_zone, i); using WriteMarkerCR = RGWSimpleRadosWriteCR; - spawn(new WriteMarkerCR(sync_env->async_rados, store, + spawn(new WriteMarkerCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj{pool, oid}, marker), true); } } @@ -545,7 +545,7 @@ public: } status->sync_info.state = rgw_data_sync_info::StateBuildingFullSyncMaps; - yield call(new WriteInfoCR(sync_env->async_rados, store, + yield call(new WriteInfoCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj{pool, sync_status_oid}, status->sync_info)); if (retcode < 0) { @@ -799,7 +799,7 @@ public: int shard_id = (int)iter->first; rgw_data_sync_marker& marker = iter->second; marker.total_entries = entries_index->get_total_entries(shard_id); - spawn(new RGWSimpleRadosWriteCR(sync_env->async_rados, store, + spawn(new RGWSimpleRadosWriteCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, RGWDataSyncStatusManager::shard_obj_name(sync_env->source_zone, shard_id)), marker), true); } @@ -865,7 +865,7 @@ public: tn->log(20, SSTR("updating marker marker_oid=" << marker_oid << " marker=" << new_marker)); RGWRados *store = sync_env->store; - return new RGWSimpleRadosWriteCR(sync_env->async_rados, store, + return new RGWSimpleRadosWriteCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, marker_oid), sync_marker); } @@ -1281,7 +1281,7 @@ public: sync_marker.marker = sync_marker.next_step_marker; sync_marker.next_step_marker.clear(); RGWRados *store = sync_env->store; - call(new RGWSimpleRadosWriteCR(sync_env->async_rados, store, + call(new RGWSimpleRadosWriteCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, status_oid), sync_marker)); } @@ -1487,7 +1487,7 @@ public: RGWCoroutine *alloc_finisher_cr() override { RGWRados *store = sync_env->store; - return new RGWSimpleRadosReadCR(sync_env->async_rados, store, + return new RGWSimpleRadosReadCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, RGWDataSyncStatusManager::shard_obj_name(sync_env->source_zone, shard_id)), &sync_marker); } @@ -1617,7 +1617,7 @@ public: RGWCoroutine *set_sync_info_cr() { RGWRados *store = sync_env->store; - return new RGWSimpleRadosWriteCR(sync_env->async_rados, store, + return new RGWSimpleRadosWriteCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, RGWDataSyncStatusManager::sync_status_oid(sync_env->source_zone)), sync_status.sync_info); } @@ -1922,7 +1922,7 @@ public: status.inc_marker.position = info.max_marker; map attrs; status.encode_all_attrs(attrs); - call(new RGWSimpleRadosWriteAttrsCR(sync_env->async_rados, store, obj, attrs)); + call(new RGWSimpleRadosWriteAttrsCR(sync_env->async_rados, store->svc.sysobj, obj, attrs)); } } if (info.syncstopped) { @@ -2010,7 +2010,7 @@ public: int RGWReadBucketSyncStatusCoroutine::operate() { reenter(this) { - yield call(new RGWSimpleRadosReadAttrsCR(sync_env->async_rados, sync_env->store, + yield call(new RGWSimpleRadosReadAttrsCR(sync_env->async_rados, sync_env->store->svc.sysobj, rgw_raw_obj(sync_env->store->svc.zone->get_zone_params().log_pool, oid), &attrs)); if (retcode == -ENOENT) { @@ -2130,7 +2130,7 @@ int RGWReadPendingBucketShardsCoroutine::operate() reenter(this){ //read sync status marker using CR = RGWSimpleRadosReadCR; - yield call(new CR(sync_env->async_rados, store, + yield call(new CR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, status_oid), sync_marker)); if (retcode < 0) { @@ -2381,7 +2381,7 @@ public: RGWRados *store = sync_env->store; tn->log(20, SSTR("updating marker marker_oid=" << marker_oid << " marker=" << new_marker)); - return new RGWSimpleRadosWriteAttrsCR(sync_env->async_rados, store, + return new RGWSimpleRadosWriteAttrsCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, marker_oid), attrs); } @@ -2444,7 +2444,7 @@ public: tn->log(20, SSTR("updating marker marker_oid=" << marker_oid << " marker=" << new_marker)); return new RGWSimpleRadosWriteAttrsCR(sync_env->async_rados, - store, + store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, marker_oid), attrs); } @@ -2756,7 +2756,7 @@ int RGWBucketShardFullSyncCR::operate() map attrs; sync_info.encode_state_attr(attrs); RGWRados *store = sync_env->store; - call(new RGWSimpleRadosWriteAttrsCR(sync_env->async_rados, store, + call(new RGWSimpleRadosWriteAttrsCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, status_oid), attrs)); } diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index d32fc9add8b..d33b9deac4b 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -17,6 +17,8 @@ #include "rgw_bucket.h" #include "rgw_lc.h" +#include "services/svc_sys_obj.h" + #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rgw @@ -368,7 +370,7 @@ int RGWLC::bucket_lc_process(string& shard_id) string next_marker, no_ns, list_versions; bool is_truncated; vector objs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); vector result; auto delay_ms = cct->_conf.get_val("rgw_lc_thread_delay"); boost::split(result, shard_id, boost::is_any_of(":")); diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index 33628f733b3..b8bf4291e50 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -360,18 +360,19 @@ namespace { int read_history(RGWRados *store, RGWMetadataLogHistory *state, RGWObjVersionTracker *objv_tracker) { - RGWObjectCtx ctx{store}; + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); auto& pool = store->svc.zone->get_zone_params().log_pool; const auto& oid = RGWMetadataLogHistory::oid; bufferlist bl; - int ret = rgw_get_system_obj(store, ctx, pool, oid, bl, objv_tracker, nullptr); + int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, objv_tracker, nullptr); if (ret < 0) { return ret; } if (bl.length() == 0) { /* bad history object, remove it */ rgw_raw_obj obj(pool, oid); - ret = store->delete_system_obj(obj); + auto sysobj = obj_ctx.get_obj(obj); + ret = sysobj.wop().remove(); if (ret < 0) { ldout(store->ctx(), 0) << "ERROR: meta history is empty, but cannot remove it (" << cpp_strerror(-ret) << ")" << dendl; return ret; @@ -424,7 +425,7 @@ class ReadHistoryCR : public RGWCoroutine { constexpr bool empty_on_enoent = false; using ReadCR = RGWSimpleRadosReadCR; - call(new ReadCR(store->get_async_rados(), store, obj, + call(new ReadCR(store->get_async_rados(), store->svc.sysobj, obj, &state, empty_on_enoent, objv_tracker)); } if (retcode < 0) { @@ -468,7 +469,7 @@ class WriteHistoryCR : public RGWCoroutine { RGWMetadataLogHistory::oid}; using WriteCR = RGWSimpleRadosWriteCR; - call(new WriteCR(store->get_async_rados(), store, obj, state, objv)); + call(new WriteCR(store->get_async_rados(), store->svc.sysobj, obj, state, objv)); } if (retcode < 0) { ldout(cct, 1) << "failed to write mdlog history: " @@ -801,7 +802,7 @@ int RGWMetadataManager::prepare_mutate(RGWRados *store, { bufferlist bl; real_time orig_mtime; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, objv_tracker, &orig_mtime, nullptr, nullptr); @@ -1075,9 +1076,11 @@ int RGWMetadataManager::remove_from_heap(RGWMetadataHandler *handler, const stri string oid = heap_oid(handler, key, objv_tracker->write_version); rgw_raw_obj obj(heap_pool, oid); - int ret = store->delete_system_obj(obj); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + int ret = sysobj.wop().remove(); if (ret < 0) { - ldout(store->ctx(), 0) << "ERROR: store->delete_system_obj() oid=" << oid << " returned ret=" << ret << dendl; + ldout(store->ctx(), 0) << "ERROR: sysobj.wop().remove() oid=" << oid << " returned ret=" << ret << dendl; return ret; } @@ -1138,7 +1141,11 @@ int RGWMetadataManager::remove_entry(RGWMetadataHandler *handler, string& key, R rgw_raw_obj obj(pool, oid); - ret = store->delete_system_obj(obj, objv_tracker); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + ret = sysobj.wop() + .set_objv_tracker(objv_tracker) + .remove(); /* cascading ret into post_modify() */ ret = post_modify(handler, section, key, log_data, objv_tracker, ret); diff --git a/src/rgw/rgw_object_expirer_core.cc b/src/rgw/rgw_object_expirer_core.cc index be8b8f4b7cc..cd80a758ecd 100644 --- a/src/rgw/rgw_object_expirer_core.cc +++ b/src/rgw/rgw_object_expirer_core.cc @@ -31,6 +31,8 @@ #include "rgw_usage.h" #include "rgw_object_expirer_core.h" +#include "services/svc_sys_obj.h" + #include "cls/lock/cls_lock_client.h" #define dout_context g_ceph_context @@ -43,7 +45,7 @@ int RGWObjectExpirer::init_bucket_info(const string& tenant_name, const string& bucket_id, RGWBucketInfo& bucket_info) { - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); /* * XXX Here's where it gets tricky. We went to all the trouble of diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index bd5c4d4d98f..306a31b1ba4 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -425,7 +425,7 @@ int rgw_build_bucket_policies(RGWRados* store, struct req_state* s) int ret = 0; rgw_obj_key obj; RGWUserInfo bucket_owner_info; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); string bi = s->info.args.get(RGW_SYS_PARAM_PREFIX "bucket-instance"); if (!bi.empty()) { @@ -1522,7 +1522,7 @@ int RGWGetObj::handle_user_manifest(const char *prefix) if (bucket_name.compare(s->bucket.name) != 0) { map bucket_attrs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_info(obj_ctx, s->user->user_id.tenant, bucket_name, bucket_info, NULL, &bucket_attrs); @@ -1656,7 +1656,7 @@ int RGWGetObj::handle_slo_manifest(bufferlist& bl) RGWBucketInfo bucket_info; map bucket_attrs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_info(obj_ctx, s->user->user_id.tenant, bucket_name, bucket_info, nullptr, &bucket_attrs); @@ -2822,8 +2822,7 @@ void RGWCreateBucket::execute() /* we need to make sure we read bucket info, it's not read before for this * specific request */ - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - op_ret = store->get_bucket_info(obj_ctx, s->bucket_tenant, s->bucket_name, + op_ret = store->get_bucket_info(*s->sysobj_ctx, s->bucket_tenant, s->bucket_name, s->bucket_info, nullptr, &s->bucket_attrs); if (op_ret < 0 && op_ret != -ENOENT) return; @@ -2986,11 +2985,10 @@ void RGWCreateBucket::execute() * changed in the meantime, we have to refresh. */ short tries = 0; do { - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); RGWBucketInfo binfo; map battrs; - op_ret = store->get_bucket_info(obj_ctx, s->bucket_tenant, s->bucket_name, + op_ret = store->get_bucket_info(*s->sysobj_ctx, s->bucket_tenant, s->bucket_name, binfo, nullptr, &battrs); if (op_ret < 0) { return; @@ -4355,7 +4353,7 @@ void RGWDeleteObj::execute() obj_ctx->obj.set_atomic(obj); bool ver_restored = false; - op_ret = store->swift_versioning_restore(*obj_ctx, s->bucket_owner.get_id(), + op_ret = store->swift_versioning_restore(*s->sysobj_ctx, *obj_ctx, s->bucket_owner.get_id(), s->bucket_info, obj, ver_restored); if (op_ret < 0) { return; @@ -4463,13 +4461,11 @@ int RGWCopyObj::verify_permission() } map src_attrs; - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - if (s->bucket_instance_id.empty()) { - op_ret = store->get_bucket_info(obj_ctx, src_tenant_name, src_bucket_name, src_bucket_info, NULL, &src_attrs); + op_ret = store->get_bucket_info(*s->sysobj_ctx, src_tenant_name, src_bucket_name, src_bucket_info, NULL, &src_attrs); } else { /* will only happen in intra region sync where the source and dest bucket is the same */ - op_ret = store->get_bucket_instance_info(obj_ctx, s->bucket_instance_id, src_bucket_info, NULL, &src_attrs); + op_ret = store->get_bucket_instance_info(*s->sysobj_ctx, s->bucket_instance_id, src_bucket_info, NULL, &src_attrs); } if (op_ret < 0) { if (op_ret == -ENOENT) { @@ -4524,7 +4520,7 @@ int RGWCopyObj::verify_permission() dest_bucket_info = src_bucket_info; dest_attrs = src_attrs; } else { - op_ret = store->get_bucket_info(obj_ctx, dest_tenant_name, dest_bucket_name, + op_ret = store->get_bucket_info(*s->sysobj_ctx, dest_tenant_name, dest_bucket_name, dest_bucket_info, nullptr, &dest_attrs); if (op_ret < 0) { if (op_ret == -ENOENT) { @@ -6071,7 +6067,7 @@ bool RGWBulkDelete::Deleter::delete_single(const acct_path_t& path) map battrs; ACLOwner bowner; - int ret = store->get_bucket_info(obj_ctx, s->user->user_id.tenant, + int ret = store->get_bucket_info(*s->sysobj_ctx, s->user->user_id.tenant, path.bucket_name, binfo, nullptr, &battrs); if (ret < 0) { @@ -6329,6 +6325,14 @@ static void forward_req_info(CephContext *cct, req_info& info, const std::string info.effective_uri = "/" + bucket_name; } +void RGWBulkUploadOp::init(RGWRados* const store, + struct req_state* const s, + RGWHandler* const h) +{ + RGWOp::init(store, s, h); + dir_ctx.emplace(store->svc.sysobj->init_obj_ctx()); +} + int RGWBulkUploadOp::handle_dir(const boost::string_ref path) { ldpp_dout(this, 20) << "got directory=" << path << dendl; @@ -6543,7 +6547,7 @@ int RGWBulkUploadOp::handle_file(const boost::string_ref path, RGWBucketInfo binfo; std::map battrs; ACLOwner bowner; - op_ret = store->get_bucket_info(obj_ctx, s->user->user_id.tenant, + op_ret = store->get_bucket_info(*s->sysobj_ctx, s->user->user_id.tenant, bucket_name, binfo, nullptr, &battrs); if (op_ret == -ENOENT) { ldpp_dout(this, 20) << "non existent directory=" << bucket_name << dendl; diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 52915c44800..e7f4225de13 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -45,6 +45,8 @@ #include "cls/lock/cls_lock_client.h" #include "cls/rgw/cls_rgw_client.h" +#include "services/svc_sys_obj.h" + #include "include/ceph_assert.h" using ceph::crypto::SHA1; @@ -471,7 +473,7 @@ inline ostream& operator<<(ostream& out, const RGWBulkDelete::acct_path_t &o) { class RGWBulkUploadOp : public RGWOp { - boost::optional dir_ctx; + boost::optional dir_ctx; protected: class fail_desc_t { @@ -524,10 +526,7 @@ public: void init(RGWRados* const store, struct req_state* const s, - RGWHandler* const h) override { - RGWOp::init(store, s, h); - dir_ctx.emplace(store); - } + RGWHandler* const h) override; int verify_permission() override; void pre_exec() override; diff --git a/src/rgw/rgw_orphan.cc b/src/rgw/rgw_orphan.cc index 68b8af80220..5125cf5f232 100644 --- a/src/rgw/rgw_orphan.cc +++ b/src/rgw/rgw_orphan.cc @@ -12,6 +12,7 @@ #include "rgw_orphan.h" #include "services/svc_zone.h" +#include "services/svc_sys_obj.h" #define dout_subsys ceph_subsys_rgw @@ -473,7 +474,8 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_ ldout(store->ctx(), 10) << "building linked oids for bucket instance: " << bucket_instance_id << dendl; RGWBucketInfo bucket_info; RGWObjectCtx obj_ctx(store); - int ret = store->get_bucket_instance_info(obj_ctx, bucket_instance_id, bucket_info, NULL, NULL); + auto sysobj_ctx = store->svc.sysobj->init_obj_ctx(); + int ret = store->get_bucket_instance_info(sysobj_ctx, bucket_instance_id, bucket_info, NULL, NULL); if (ret < 0) { if (ret == -ENOENT) { /* probably raced with bucket removal */ diff --git a/src/rgw/rgw_process.cc b/src/rgw/rgw_process.cc index 39a5f9ff504..8205b634df8 100644 --- a/src/rgw/rgw_process.cc +++ b/src/rgw/rgw_process.cc @@ -145,6 +145,9 @@ int process_request(RGWRados* const store, RGWObjectCtx rados_ctx(store, s); s->obj_ctx = &rados_ctx; + auto sysobj_ctx = store->svc.sysobj->init_obj_ctx(); + s->sysobj_ctx = &sysobj_ctx; + if (ret < 0) { s->cio = client_io; abort_early(s, nullptr, ret, nullptr); diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 01c346f5c12..05ef5f1ab50 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -26,6 +26,8 @@ #include "rgw_bucket.h" #include "rgw_user.h" +#include "services/svc_sys_obj.h" + #include #define dout_context g_ceph_context @@ -291,7 +293,7 @@ int BucketAsyncRefreshHandler::init_fetch() { RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_instance_info(obj_ctx, bucket, bucket_info, NULL, NULL); if (r < 0) { @@ -362,7 +364,7 @@ int RGWBucketStatsCache::fetch_stats_from_storage(const rgw_user& user, const rg { RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_instance_info(obj_ctx, bucket, bucket_info, NULL, NULL); if (r < 0) { @@ -625,7 +627,7 @@ int RGWUserStatsCache::sync_bucket(const rgw_user& user, rgw_bucket& bucket) { RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); int r = store->get_bucket_instance_info(obj_ctx, bucket, bucket_info, NULL, NULL); if (r < 0) { diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 451486b9efe..e4910996ce4 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1651,7 +1651,7 @@ int RGWRados::init_complete() ldout(cct, 20) << __func__ << " bucket index max shards: " << bucket_index_max_shards << dendl; binfo_cache = new RGWChainedCacheImpl; - binfo_cache->init(this); + binfo_cache->init(svc.cache); bool need_tombstone_cache = !svc.zone->get_zone_data_notify_to_map().empty(); /* have zones syncing from us */ @@ -2530,7 +2530,7 @@ int RGWRados::Bucket::update_bucket_id(const string& new_bucket_id) rgw_bucket bucket = bucket_info.bucket; bucket.update_bucket_id(new_bucket_id); - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = store->get_bucket_instance_info(obj_ctx, bucket, bucket_info, nullptr, nullptr); if (ret < 0) { @@ -2976,7 +2976,7 @@ int RGWRados::create_bucket(RGWUserInfo& owner, rgw_bucket& bucket, /* we need to reread the info and return it, caller will have a use for it */ RGWObjVersionTracker instance_ver = info.objv_tracker; info.objv_tracker.clear(); - RGWObjectCtx obj_ctx(this); + auto obj_ctx = svc.sysobj->init_obj_ctx(); r = get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL, NULL); if (r < 0) { if (r == -ENOENT) { @@ -3411,7 +3411,7 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket, { bucket = _bucket; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); RGWBucketInfo bucket_info; RGWBucketInfo* bucket_info_p = @@ -3439,7 +3439,7 @@ int RGWRados::BucketShard::init(const rgw_bucket& _bucket, bucket = _bucket; shard_id = sid; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); RGWBucketInfo bucket_info; RGWBucketInfo* bucket_info_p = @@ -3550,7 +3550,9 @@ int RGWRados::swift_versioning_copy(RGWObjectCtx& obj_ctx, RGWBucketInfo dest_bucket_info; - r = get_bucket_info(obj_ctx, bucket_info.bucket.tenant, bucket_info.swift_ver_location, dest_bucket_info, NULL, NULL); + auto sysobj_ctx = svc.sysobj->init_obj_ctx(); + + r = get_bucket_info(sysobj_ctx, bucket_info.bucket.tenant, bucket_info.swift_ver_location, dest_bucket_info, NULL, NULL); if (r < 0) { ldout(cct, 10) << "failed to read dest bucket info: r=" << r << dendl; if (r == -ENOENT) { @@ -3603,7 +3605,8 @@ int RGWRados::swift_versioning_copy(RGWObjectCtx& obj_ctx, return r; } -int RGWRados::swift_versioning_restore(RGWObjectCtx& obj_ctx, +int RGWRados::swift_versioning_restore(RGWSysObjectCtx& sysobj_ctx, + RGWObjectCtx& obj_ctx, const rgw_user& user, RGWBucketInfo& bucket_info, rgw_obj& obj, @@ -3616,7 +3619,7 @@ int RGWRados::swift_versioning_restore(RGWObjectCtx& obj_ctx, /* Bucket info of the bucket that stores previous versions of our object. */ RGWBucketInfo archive_binfo; - int ret = get_bucket_info(obj_ctx, bucket_info.bucket.tenant, + int ret = get_bucket_info(sysobj_ctx, bucket_info.bucket.tenant, bucket_info.swift_ver_location, archive_binfo, nullptr, nullptr); if (ret < 0) { @@ -3989,103 +3992,6 @@ int RGWRados::Object::Write::write_meta(uint64_t size, uint64_t accounted_size, return r; } -/** Write/overwrite a system object. */ -int RGWRados::put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, real_time *mtime, - map& attrs, int flags, - const bufferlist& data, - RGWObjVersionTracker *objv_tracker, - real_time set_mtime /* 0 for don't set */) -{ - rgw_rados_ref ref; - int r = get_system_obj_ref(obj, &ref); - if (r < 0) - return r; - - ObjectWriteOperation op; - - if (flags & PUT_OBJ_EXCL) { - if (!(flags & PUT_OBJ_CREATE)) - return -EINVAL; - op.create(true); // exclusive create - } else { - op.remove(); - op.set_op_flags2(LIBRADOS_OP_FLAG_FAILOK); - op.create(false); - } - - if (objv_tracker) { - objv_tracker->prepare_op_for_write(&op); - } - - if (real_clock::is_zero(set_mtime)) { - set_mtime = real_clock::now(); - } - - struct timespec mtime_ts = real_clock::to_timespec(set_mtime); - op.mtime2(&mtime_ts); - op.write_full(data); - - bufferlist acl_bl; - - for (map::iterator iter = attrs.begin(); iter != attrs.end(); ++iter) { - const string& name = iter->first; - bufferlist& bl = iter->second; - - if (!bl.length()) - continue; - - op.setxattr(name.c_str(), bl); - } - - r = ref.ioctx.operate(ref.oid, &op); - if (r < 0) { - return r; - } - - if (objv_tracker) { - objv_tracker->apply_write(); - } - - if (mtime) { - *mtime = set_mtime; - } - - return 0; -} - -int RGWRados::put_system_obj_data(void *ctx, rgw_raw_obj& obj, const bufferlist& bl, - off_t ofs, bool exclusive, - RGWObjVersionTracker *objv_tracker) -{ - rgw_rados_ref ref; - int r = get_system_obj_ref(obj, &ref); - if (r < 0) { - return r; - } - - ObjectWriteOperation op; - - if (exclusive) - op.create(true); - - if (objv_tracker) { - objv_tracker->prepare_op_for_write(&op); - } - if (ofs == -1) { - op.write_full(bl); - } else { - op.write(ofs, bl); - } - r = ref.ioctx.operate(ref.oid, &op); - if (r < 0) - return r; - - if (objv_tracker) { - objv_tracker->apply_write(); - } - return 0; -} - /** * Write/overwrite an object to the bucket storage. * bucket: the bucket to store the object in @@ -5240,7 +5146,7 @@ int RGWRados::set_bucket_owner(rgw_bucket& bucket, ACLOwner& owner) { RGWBucketInfo info; map attrs; - RGWObjectCtx obj_ctx(this); + auto obj_ctx = svc.sysobj->init_obj_ctx(); int r; if (bucket.bucket_id.empty()) { r = get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL, &attrs); @@ -5279,7 +5185,7 @@ int RGWRados::set_buckets_enabled(vector& buckets, bool enabled) RGWBucketInfo info; map attrs; - RGWObjectCtx obj_ctx(this); + auto obj_ctx = svc.sysobj->init_obj_ctx(); int r = get_bucket_info(obj_ctx, bucket.tenant, bucket.name, info, NULL, &attrs); if (r < 0) { ldout(cct, 0) << "NOTICE: get_bucket_info on bucket=" << bucket.name << " returned err=" << r << ", skipping bucket" << dendl; @@ -5305,7 +5211,7 @@ int RGWRados::set_buckets_enabled(vector& buckets, bool enabled) int RGWRados::bucket_suspended(rgw_bucket& bucket, bool *suspended) { RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(this); + auto obj_ctx = svc.sysobj->init_obj_ctx(); int ret = get_bucket_info(obj_ctx, bucket.tenant, bucket.name, bucket_info, NULL); if (ret < 0) { return ret; @@ -5819,39 +5725,12 @@ int RGWRados::delete_raw_obj(const rgw_raw_obj& obj) return 0; } -int RGWRados::delete_system_obj(rgw_raw_obj& obj, RGWObjVersionTracker *objv_tracker) -{ - if (obj.empty()) { - ldout(cct, 1) << "delete_system_obj got empty object name " - << obj << ", returning EINVAL" << dendl; - return -EINVAL; - } - rgw_rados_ref ref; - int r = get_raw_obj_ref(obj, &ref); - if (r < 0) { - return r; - } - - ObjectWriteOperation op; - - if (objv_tracker) { - objv_tracker->prepare_op_for_write(&op); - } - - op.remove(); - r = ref.ioctx.operate(ref.oid, &op); - if (r < 0) - return r; - - return 0; -} - int RGWRados::delete_obj_index(const rgw_obj& obj) { std::string oid, key; get_obj_bucket_and_oid_loc(obj, oid, key); - RGWObjectCtx obj_ctx(this); + auto obj_ctx = svc.sysobj->init_obj_ctx(); RGWBucketInfo bucket_info; int ret = get_bucket_instance_info(obj_ctx, obj.bucket, bucket_info, NULL, NULL); @@ -6274,33 +6153,6 @@ int RGWRados::Object::Stat::finish() return 0; } -/** - * Get an attribute for a system object. - * obj: the object to get attr - * name: name of the attr to retrieve - * dest: bufferlist to store the result in - * Returns: 0 on success, -ERR# otherwise. - */ -int RGWRados::system_obj_get_attr(rgw_raw_obj& obj, const char *name, bufferlist& dest) -{ - rgw_rados_ref ref; - int r = get_system_obj_ref(obj, &ref); - if (r < 0) { - return r; - } - - ObjectReadOperation op; - - int rval; - op.getxattr(name, &dest, &rval); - - r = ref.ioctx.operate(ref.oid, &op, NULL); - if (r < 0) - return r; - - return 0; -} - int RGWRados::append_atomic_test(RGWObjectCtx *rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, ObjectOperation& op, RGWObjState **pstate) @@ -6337,11 +6189,6 @@ void RGWRados::Object::invalidate_state() ctx.obj.invalidate(obj); } -void RGWRados::SystemObject::invalidate_state() -{ - ctx.raw.invalidate(obj); -} - int RGWRados::Object::prepare_atomic_modification(ObjectWriteOperation& op, bool reset_obj, const string *ptag, const char *if_match, const char *if_nomatch, bool removal_op, bool modify_tail) @@ -6435,60 +6282,6 @@ int RGWRados::Object::prepare_atomic_modification(ObjectWriteOperation& op, bool return 0; } -int RGWRados::system_obj_set_attr(void *ctx, rgw_raw_obj& obj, const char *name, bufferlist& bl, - RGWObjVersionTracker *objv_tracker) -{ - map attrs; - attrs[name] = bl; - return system_obj_set_attrs(ctx, obj, attrs, NULL, objv_tracker); -} - -int RGWRados::system_obj_set_attrs(void *ctx, rgw_raw_obj& obj, - map& attrs, - map* rmattrs, - RGWObjVersionTracker *objv_tracker) -{ - rgw_rados_ref ref; - int r = get_system_obj_ref(obj, &ref); - if (r < 0) { - return r; - } - ObjectWriteOperation op; - - if (objv_tracker) { - objv_tracker->prepare_op_for_write(&op); - } - - map::iterator iter; - if (rmattrs) { - for (iter = rmattrs->begin(); iter != rmattrs->end(); ++iter) { - const string& name = iter->first; - op.rmxattr(name.c_str()); - } - } - - for (iter = attrs.begin(); iter != attrs.end(); ++iter) { - const string& name = iter->first; - bufferlist& bl = iter->second; - - if (!bl.length()) - continue; - - op.setxattr(name.c_str(), bl); - } - - if (!op.size()) - return 0; - - bufferlist bl; - - r = ref.ioctx.operate(ref.oid, &op); - if (r < 0) - return r; - - return 0; -} - /** * Set an attr on an object. * bucket: name of the bucket holding the object @@ -6735,43 +6528,6 @@ int RGWRados::Object::Read::range_to_ofs(uint64_t obj_size, int64_t &ofs, int64_ return 0; } -int RGWRados::stat_system_obj(RGWObjectCtx& obj_ctx, - RGWRados::SystemObject::Read::GetObjState& state, - rgw_raw_obj& obj, - map *attrs, - real_time *lastmod, - uint64_t *obj_size, - RGWObjVersionTracker *objv_tracker) -{ - RGWRawObjState *astate = NULL; - - int r = get_system_obj_state(&obj_ctx, obj, &astate, objv_tracker); - if (r < 0) - return r; - - if (!astate->exists) { - return -ENOENT; - } - - if (attrs) { - *attrs = astate->attrset; - if (cct->_conf->subsys.should_gather()) { - map::iterator iter; - for (iter = attrs->begin(); iter != attrs->end(); ++iter) { - ldout(cct, 20) << "Read xattr: " << iter->first << dendl; - } - } - } - - if (obj_size) - *obj_size = astate->size; - if (lastmod) - *lastmod = astate->mtime; - - return 0; -} - - int RGWRados::Bucket::UpdateIndex::guard_reshard(BucketShard **pbs, std::function call) { RGWRados *store = target->get_store(); @@ -6819,15 +6575,6 @@ int RGWRados::Bucket::UpdateIndex::guard_reshard(BucketShard **pbs, std::functio return 0; } -int RGWRados::SystemObject::Read::stat(RGWObjVersionTracker *objv_tracker) -{ - RGWRados *store = source->get_store(); - rgw_raw_obj& obj = source->get_obj(); - - return store->stat_system_obj(source->get_ctx(), state, obj, stat_params.attrs, - stat_params.lastmod, stat_params.obj_size, objv_tracker); -} - int RGWRados::Bucket::UpdateIndex::prepare(RGWModifyOp op, const string *write_tag) { if (blind) { @@ -7059,92 +6806,6 @@ int RGWRados::Object::Read::read(int64_t ofs, int64_t end, bufferlist& bl) return bl.length(); } -int RGWRados::SystemObject::Read::GetObjState::get_ref(RGWRados *store, rgw_raw_obj& obj, rgw_rados_ref **pref) -{ - if (!has_ref) { - int r = store->get_raw_obj_ref(obj, &ref); - if (r < 0) { - return r; - } - has_ref = true; - } - *pref = &ref; - return 0; - -} - -int RGWRados::get_system_obj(RGWObjectCtx& obj_ctx, RGWRados::SystemObject::Read::GetObjState& read_state, - RGWObjVersionTracker *objv_tracker, rgw_raw_obj& obj, - bufferlist& bl, off_t ofs, off_t end, - map *attrs, - rgw_cache_entry_info *cache_info, - boost::optional) -{ - uint64_t len; - ObjectReadOperation op; - - if (end < 0) - len = 0; - else - len = end - ofs + 1; - - if (objv_tracker) { - objv_tracker->prepare_op_for_read(&op); - } - - ldout(cct, 20) << "rados->read ofs=" << ofs << " len=" << len << dendl; - op.read(ofs, len, &bl, NULL); - - if (attrs) { - op.getxattrs(attrs, NULL); - } - - rgw_rados_ref *ref; - int r = read_state.get_ref(this, obj, &ref); - if (r < 0) { - ldout(cct, 20) << "read_state.get_ref() on obj=" << obj << " returned " << r << dendl; - return r; - } - r = ref->ioctx.operate(ref->oid, &op, NULL); - if (r < 0) { - ldout(cct, 20) << "rados->read r=" << r << " bl.length=" << bl.length() << dendl; - return r; - } - ldout(cct, 20) << "rados->read r=" << r << " bl.length=" << bl.length() << dendl; - - uint64_t op_ver = ref->ioctx.get_last_version(); - - if (read_state.last_ver > 0 && - read_state.last_ver != op_ver) { - ldout(cct, 5) << "raced with an object write, abort" << dendl; - return -ECANCELED; - } - - read_state.last_ver = op_ver; - - return bl.length(); -} - -int RGWRados::SystemObject::Read::read(int64_t ofs, int64_t end, bufferlist& bl, - RGWObjVersionTracker *objv_tracker, - boost::optional refresh_version) -{ - RGWRados *store = source->get_store(); - rgw_raw_obj& obj = source->get_obj(); - - return store->get_system_obj(source->get_ctx(), state, objv_tracker, obj, bl, - ofs, end, read_params.attrs, - read_params.cache_info, refresh_version); -} - -int RGWRados::SystemObject::Read::get_attr(const char *name, bufferlist& dest) -{ - RGWRados *store = source->get_store(); - rgw_raw_obj& obj = source->get_obj(); - - return store->system_obj_get_attr(obj, name, dest); -} - struct get_obj_data; struct get_obj_aio_data { @@ -8644,7 +8305,7 @@ void RGWRados::get_bucket_instance_obj(const rgw_bucket& bucket, rgw_raw_obj& ob } } -int RGWRados::get_bucket_instance_info(RGWObjectCtx& obj_ctx, const string& meta_key, RGWBucketInfo& info, +int RGWRados::get_bucket_instance_info(RGWSysObjectCtx& obj_ctx, const string& meta_key, RGWBucketInfo& info, real_time *pmtime, map *pattrs) { size_t pos = meta_key.find(':'); @@ -8657,7 +8318,7 @@ int RGWRados::get_bucket_instance_info(RGWObjectCtx& obj_ctx, const string& meta return get_bucket_instance_from_oid(obj_ctx, oid, info, pmtime, pattrs); } -int RGWRados::get_bucket_instance_info(RGWObjectCtx& obj_ctx, const rgw_bucket& bucket, RGWBucketInfo& info, +int RGWRados::get_bucket_instance_info(RGWSysObjectCtx& obj_ctx, const rgw_bucket& bucket, RGWBucketInfo& info, real_time *pmtime, map *pattrs) { string oid; @@ -8670,7 +8331,7 @@ int RGWRados::get_bucket_instance_info(RGWObjectCtx& obj_ctx, const rgw_bucket& return get_bucket_instance_from_oid(obj_ctx, oid, info, pmtime, pattrs); } -int RGWRados::get_bucket_instance_from_oid(RGWObjectCtx& obj_ctx, const string& oid, RGWBucketInfo& info, +int RGWRados::get_bucket_instance_from_oid(RGWSysObjectCtx& obj_ctx, const string& oid, RGWBucketInfo& info, real_time *pmtime, map *pattrs, rgw_cache_entry_info *cache_info, boost::optional refresh_version) @@ -8699,7 +8360,7 @@ int RGWRados::get_bucket_instance_from_oid(RGWObjectCtx& obj_ctx, const string& return 0; } -int RGWRados::get_bucket_entrypoint_info(RGWObjectCtx& obj_ctx, +int RGWRados::get_bucket_entrypoint_info(RGWSysObjectCtx& obj_ctx, const string& tenant_name, const string& bucket_name, RGWBucketEntryPoint& entry_point, @@ -8730,7 +8391,7 @@ int RGWRados::get_bucket_entrypoint_info(RGWObjectCtx& obj_ctx, return 0; } -int RGWRados::convert_old_bucket_info(RGWObjectCtx& obj_ctx, +int RGWRados::convert_old_bucket_info(RGWSysObjectCtx& obj_ctx, const string& tenant_name, const string& bucket_name) { @@ -8768,7 +8429,7 @@ int RGWRados::convert_old_bucket_info(RGWObjectCtx& obj_ctx, return 0; } -int RGWRados::_get_bucket_info(RGWObjectCtx& obj_ctx, +int RGWRados::_get_bucket_info(RGWSysObjectCtx& obj_ctx, const string& tenant, const string& bucket_name, RGWBucketInfo& info, @@ -8856,7 +8517,7 @@ int RGWRados::_get_bucket_info(RGWObjectCtx& obj_ctx, *pattrs = e.attrs; /* chain to both bucket entry point and bucket instance */ - if (!binfo_cache->put(this, bucket_entry, &e, {&entry_cache_info, &cache_info})) { + if (!binfo_cache->put(svc.cache, bucket_entry, &e, {&entry_cache_info, &cache_info})) { ldout(cct, 20) << "couldn't put binfo cache entry, might have raced with data changes" << dendl; } @@ -8870,7 +8531,7 @@ int RGWRados::_get_bucket_info(RGWObjectCtx& obj_ctx, return 0; } -int RGWRados::get_bucket_info(RGWObjectCtx& obj_ctx, +int RGWRados::get_bucket_info(RGWSysObjectCtx& obj_ctx, const string& tenant, const string& bucket_name, RGWBucketInfo& info, real_time *pmtime, map *pattrs) @@ -8883,7 +8544,7 @@ int RGWRados::try_refresh_bucket_info(RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs) { - RGWObjectCtx obj_ctx(this); + RGWSysObjectCtx obj_ctx = svc.sysobj->init_obj_ctx(); return _get_bucket_info(obj_ctx, info.bucket.tenant, info.bucket.name, info, pmtime, pattrs, info.objv_tracker.read_version); @@ -8960,7 +8621,7 @@ int RGWRados::put_linked_bucket_info(RGWBucketInfo& info, bool exclusive, real_t int RGWRados::update_containers_stats(map& m) { - RGWObjectCtx obj_ctx(this); + auto obj_ctx = svc.sysobj->init_obj_ctx(); map::iterator iter; for (iter = m.begin(); iter != m.end(); ++iter) { @@ -10151,7 +9812,7 @@ int RGWRados::cls_user_get_bucket_stats(const rgw_bucket& bucket, cls_user_bucke { vector headers; RGWBucketInfo bucket_info; - RGWObjectCtx obj_ctx(this); + auto obj_ctx = svc.sysobj->init_obj_ctx(); int ret = get_bucket_instance_info(obj_ctx, bucket, bucket_info, NULL, NULL); if (ret < 0) { return ret; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index f0553a6fd4c..c01f5b0f505 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -54,6 +54,8 @@ class RGWSI_SyncModules; class RGWSI_SysObj; class RGWSI_SysObj_Cache; +class RGWSysObjectCtx; + /* flags for put_obj_meta() */ #define PUT_OBJ_CREATE 0x01 #define PUT_OBJ_EXCL 0x02 @@ -1062,22 +1064,6 @@ public: class RGWGetDirHeader_CB; class RGWGetUserHeader_CB; -class RGWChainedCache { -public: - virtual ~RGWChainedCache() {} - virtual void chain_cb(const string& key, void *data) = 0; - virtual void invalidate(const string& key) = 0; - virtual void invalidate_all() = 0; - - struct Entry { - RGWChainedCache *cache; - const string& key; - void *data; - - Entry(RGWChainedCache *_c, const string& _k, void *_d) : cache(_c), key(_k), data(_d) {} - }; -}; - template class RGWObjectCtxImpl { RGWRados *store; @@ -1485,60 +1471,6 @@ public: RGWCoroutinesManagerRegistry *get_cr_registry() { return cr_registry; } - class SystemObject { - RGWRados *store; - RGWObjectCtx& ctx; - rgw_raw_obj obj; - - public: - - SystemObject(RGWRados *_store, RGWObjectCtx& _ctx, rgw_raw_obj& _obj) : - store(_store), ctx(_ctx), obj(_obj) - {} - - void invalidate_state(); - - RGWRados *get_store() { return store; } - rgw_raw_obj& get_obj() { return obj; } - RGWObjectCtx& get_ctx() { return ctx; } - - struct Read { - RGWRados::SystemObject *source; - - struct GetObjState { - rgw_rados_ref ref; - bool has_ref{false}; - uint64_t last_ver{0}; - - GetObjState() {} - - int get_ref(RGWRados *store, rgw_raw_obj& obj, rgw_rados_ref **pref); - } state; - - struct StatParams { - ceph::real_time *lastmod; - uint64_t *obj_size; - map *attrs; - - StatParams() : lastmod(NULL), obj_size(NULL), attrs(NULL) {} - } stat_params; - - struct ReadParams { - rgw_cache_entry_info *cache_info{nullptr}; - map *attrs; - - ReadParams() : attrs(NULL) {} - } read_params; - - explicit Read(RGWRados::SystemObject *_source) : source(_source) {} - - int stat(RGWObjVersionTracker *objv_tracker); - int read(int64_t ofs, int64_t end, bufferlist& bl, RGWObjVersionTracker *objv_tracker, - boost::optional refresh_version = boost::none); - int get_attr(const char *name, bufferlist& dest); - }; - }; - struct BucketShard { RGWRados *store; rgw_bucket bucket; @@ -1900,28 +1832,9 @@ public: }; // class List }; // class Bucket - /** Write/overwrite an object to the bucket storage. */ - virtual int put_system_obj_impl(rgw_raw_obj& obj, uint64_t size, ceph::real_time *mtime, - map& attrs, int flags, - const bufferlist& data, - RGWObjVersionTracker *objv_tracker, - ceph::real_time set_mtime /* 0 for don't set */); - - virtual int put_system_obj_data(void *ctx, rgw_raw_obj& obj, - const bufferlist& bl, off_t ofs, bool exclusive, - RGWObjVersionTracker *objv_tracker = nullptr); int aio_put_obj_data(void *ctx, rgw_raw_obj& obj, bufferlist& bl, - off_t ofs, bool exclusive, void **handle); - - int put_system_obj(void *ctx, rgw_raw_obj& obj, const bufferlist& data, bool exclusive, - ceph::real_time *mtime, map& attrs, RGWObjVersionTracker *objv_tracker, - ceph::real_time set_mtime) { - int flags = PUT_OBJ_CREATE; - if (exclusive) - flags |= PUT_OBJ_EXCL; - - return put_system_obj_impl(obj, data.length(), mtime, attrs, flags, data, objv_tracker, set_mtime); - } + off_t ofs, bool exclusive, + void **handle); int aio_wait(void *handle); bool aio_completed(void *handle); @@ -1939,7 +1852,8 @@ public: const rgw_user& user, /* in */ RGWBucketInfo& bucket_info, /* in */ rgw_obj& obj); /* in */ - int swift_versioning_restore(RGWObjectCtx& obj_ctx, /* in/out */ + int swift_versioning_restore(RGWSysObjectCtx& sysobj_ctx, + RGWObjectCtx& obj_ctx, /* in/out */ const rgw_user& user, /* in */ RGWBucketInfo& bucket_info, /* in */ rgw_obj& obj, /* in */ @@ -2084,31 +1998,11 @@ public: const ceph::real_time& expiration_time = ceph::real_time(), rgw_zone_set *zones_trace = nullptr); - /** Delete a raw object.*/ int delete_raw_obj(const rgw_raw_obj& obj); - /* Delete a system object */ - virtual int delete_system_obj(rgw_raw_obj& src_obj, RGWObjVersionTracker *objv_tracker = NULL); - /** Remove an object from the bucket index */ int delete_obj_index(const rgw_obj& obj); - /** - * Get an attribute for a system object. - * obj: the object to get attr - * name: name of the attr to retrieve - * dest: bufferlist to store the result in - * Returns: 0 on success, -ERR# otherwise. - */ - virtual int system_obj_get_attr(rgw_raw_obj& obj, const char *name, bufferlist& dest); - - int system_obj_set_attr(void *ctx, rgw_raw_obj& obj, const char *name, bufferlist& bl, - RGWObjVersionTracker *objv_tracker); - virtual int system_obj_set_attrs(void *ctx, rgw_raw_obj& obj, - map& attrs, - map* rmattrs, - RGWObjVersionTracker *objv_tracker); - /** * Set an attr on an object. * bucket: name of the bucket holding the object @@ -2130,26 +2024,6 @@ public: return get_obj_state(rctx, bucket_info, obj, state, true); } - virtual int stat_system_obj(RGWObjectCtx& obj_ctx, - RGWRados::SystemObject::Read::GetObjState& state, - rgw_raw_obj& obj, - map *attrs, - ceph::real_time *lastmod, - uint64_t *obj_size, - RGWObjVersionTracker *objv_tracker); - - virtual int get_system_obj(RGWObjectCtx& obj_ctx, RGWRados::SystemObject::Read::GetObjState& read_state, - RGWObjVersionTracker *objv_tracker, rgw_raw_obj& obj, - bufferlist& bl, off_t ofs, off_t end, - map *attrs, - rgw_cache_entry_info *cache_info, - boost::optional refresh_version = - boost::none); - - virtual void register_chained_cache(RGWChainedCache *cache) {} - virtual bool chain_cache_entry(std::initializer_list cache_info_entries, - RGWChainedCache::Entry *chained_entry) { return false; } - int iterate_obj(RGWObjectCtx& ctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, off_t ofs, off_t end, @@ -2230,11 +2104,6 @@ public: RGWObjectCtx *rctx = static_cast(ctx); rctx->obj.set_prefetch_data(obj); } - void set_prefetch_data(void *ctx, rgw_raw_obj& obj) { - RGWObjectCtx *rctx = static_cast(ctx); - rctx->raw.set_prefetch_data(obj); - } - int decode_policy(bufferlist& bl, ACLOwner *owner); int get_bucket_stats(RGWBucketInfo& bucket_info, int shard_id, string *bucket_ver, string *master_ver, map& stats, string *max_marker, bool* syncstopped = NULL); @@ -2248,22 +2117,22 @@ public: bool exclusive, RGWObjVersionTracker& objv_tracker, ceph::real_time mtime, map *pattrs); int put_bucket_instance_info(RGWBucketInfo& info, bool exclusive, ceph::real_time mtime, map *pattrs); - int get_bucket_entrypoint_info(RGWObjectCtx& obj_ctx, const string& tenant_name, const string& bucket_name, + int get_bucket_entrypoint_info(RGWSysObjectCtx& obj_ctx, const string& tenant_name, const string& bucket_name, RGWBucketEntryPoint& entry_point, RGWObjVersionTracker *objv_tracker, ceph::real_time *pmtime, map *pattrs, rgw_cache_entry_info *cache_info = NULL, boost::optional refresh_version = boost::none); - int get_bucket_instance_info(RGWObjectCtx& obj_ctx, const string& meta_key, RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs); - int get_bucket_instance_info(RGWObjectCtx& obj_ctx, const rgw_bucket& bucket, RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs); - int get_bucket_instance_from_oid(RGWObjectCtx& obj_ctx, const string& oid, RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs, + int get_bucket_instance_info(RGWSysObjectCtx& obj_ctx, const string& meta_key, RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs); + int get_bucket_instance_info(RGWSysObjectCtx& obj_ctx, const rgw_bucket& bucket, RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs); + int get_bucket_instance_from_oid(RGWSysObjectCtx& obj_ctx, const string& oid, RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs, rgw_cache_entry_info *cache_info = NULL, boost::optional refresh_version = boost::none); - int convert_old_bucket_info(RGWObjectCtx& obj_ctx, const string& tenant_name, const string& bucket_name); + int convert_old_bucket_info(RGWSysObjectCtx& obj_ctx, const string& tenant_name, const string& bucket_name); static void make_bucket_entry_name(const string& tenant_name, const string& bucket_name, string& bucket_entry); private: - int _get_bucket_info(RGWObjectCtx& obj_ctx, const string& tenant, + int _get_bucket_info(RGWSysObjectCtx& obj_ctx, const string& tenant, const string& bucket_name, RGWBucketInfo& info, real_time *pmtime, map *pattrs, @@ -2295,7 +2164,7 @@ protected: virtual void call_zap(); public: - int get_bucket_info(RGWObjectCtx& obj_ctx, + int get_bucket_info(RGWSysObjectCtx& obj_ctx, const string& tenant_name, const string& bucket_name, RGWBucketInfo& info, ceph::real_time *pmtime, map *pattrs = NULL); @@ -2597,65 +2466,6 @@ public: }; -template -class RGWChainedCacheImpl : public RGWChainedCache { - ceph::timespan expiry; - RWLock lock; - - std::unordered_map> entries; - -public: - RGWChainedCacheImpl() : lock("RGWChainedCacheImpl::lock") {} - - void init(RGWRados *store) { - store->register_chained_cache(this); - expiry = std::chrono::seconds(store->ctx()->_conf.get_val( - "rgw_cache_expiry_interval")); - } - - boost::optional find(const string& key) { - RWLock::RLocker rl(lock); - auto iter = entries.find(key); - if (iter == entries.end()) { - return boost::none; - } - if (expiry.count() && - (ceph::coarse_mono_clock::now() - iter->second.second) > expiry) { - return boost::none; - } - - return iter->second.first; - } - - bool put(RGWRados *store, const string& key, T *entry, - std::initializer_list cache_info_entries) { - Entry chain_entry(this, key, entry); - - /* we need the store cache to call us under its lock to maintain lock ordering */ - return store->chain_cache_entry(cache_info_entries, &chain_entry); - } - - void chain_cb(const string& key, void *data) override { - T *entry = static_cast(data); - RWLock::WLocker wl(lock); - entries[key].first = *entry; - if (expiry.count() > 0) { - entries[key].second = ceph::coarse_mono_clock::now(); - } - } - - void invalidate(const string& key) override { - RWLock::WLocker wl(lock); - entries.erase(key); - } - - void invalidate_all() override { - RWLock::WLocker wl(lock); - entries.clear(); - } -}; /* RGWChainedCacheImpl */ - - #define MP_META_SUFFIX ".meta" class RGWMPObj { diff --git a/src/rgw/rgw_reshard.cc b/src/rgw/rgw_reshard.cc index 43d5a91218b..6fd4b4dbe4a 100644 --- a/src/rgw/rgw_reshard.cc +++ b/src/rgw/rgw_reshard.cc @@ -15,6 +15,7 @@ #include "common/dout.h" #include "services/svc_zone.h" +#include "services/svc_sys_obj.h" #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rgw @@ -972,7 +973,7 @@ int RGWReshard::process_single_logshard(int logshard_num) ldout(store->ctx(), 20) << __func__ << " resharding " << entry.bucket_name << dendl; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); rgw_bucket bucket; RGWBucketInfo bucket_info; map attrs; diff --git a/src/rgw/rgw_rest_bucket.cc b/src/rgw/rgw_rest_bucket.cc index bab693f3be4..857d0c9df07 100644 --- a/src/rgw/rgw_rest_bucket.cc +++ b/src/rgw/rgw_rest_bucket.cc @@ -7,6 +7,8 @@ #include "include/str_list.h" +#include "services/svc_sys_obj.h" + #define dout_subsys ceph_subsys_rgw class RGWOp_Bucket_Info : public RGWRESTOp { @@ -262,7 +264,7 @@ void RGWOp_Set_Bucket_Quota::execute() if (use_http_params) { RGWBucketInfo bucket_info; map attrs; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); http_ret = store->get_bucket_info(obj_ctx, uid.tenant, bucket, bucket_info, NULL, &attrs); if (http_ret < 0) { return; diff --git a/src/rgw/rgw_rest_log.cc b/src/rgw/rgw_rest_log.cc index e8f98b510ef..6fece1d6af4 100644 --- a/src/rgw/rgw_rest_log.cc +++ b/src/rgw/rgw_rest_log.cc @@ -377,8 +377,6 @@ void RGWOp_BILog_List::execute() { RGWBucketInfo bucket_info; unsigned max_entries; - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - if (bucket_name.empty() && bucket_instance.empty()) { dout(5) << "ERROR: neither bucket nor bucket instance specified" << dendl; http_ret = -EINVAL; @@ -392,13 +390,13 @@ void RGWOp_BILog_List::execute() { } if (!bucket_instance.empty()) { - http_ret = store->get_bucket_instance_info(obj_ctx, bucket_instance, bucket_info, NULL, NULL); + http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, bucket_instance, bucket_info, NULL, NULL); if (http_ret < 0) { dout(5) << "could not get bucket instance info for bucket instance id=" << bucket_instance << dendl; return; } } else { /* !bucket_name.empty() */ - http_ret = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL, NULL); + http_ret = store->get_bucket_info(*s->sysobj_ctx, tenant_name, bucket_name, bucket_info, NULL, NULL); if (http_ret < 0) { dout(5) << "could not get bucket info for bucket=" << bucket_name << dendl; return; @@ -470,8 +468,6 @@ void RGWOp_BILog_Info::execute() { bucket_instance = s->info.args.get("bucket-instance"); RGWBucketInfo bucket_info; - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - if (bucket_name.empty() && bucket_instance.empty()) { dout(5) << "ERROR: neither bucket nor bucket instance specified" << dendl; http_ret = -EINVAL; @@ -485,13 +481,13 @@ void RGWOp_BILog_Info::execute() { } if (!bucket_instance.empty()) { - http_ret = store->get_bucket_instance_info(obj_ctx, bucket_instance, bucket_info, NULL, NULL); + http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, bucket_instance, bucket_info, NULL, NULL); if (http_ret < 0) { dout(5) << "could not get bucket instance info for bucket instance id=" << bucket_instance << dendl; return; } } else { /* !bucket_name.empty() */ - http_ret = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL, NULL); + http_ret = store->get_bucket_info(*s->sysobj_ctx, tenant_name, bucket_name, bucket_info, NULL, NULL); if (http_ret < 0) { dout(5) << "could not get bucket info for bucket=" << bucket_name << dendl; return; @@ -532,8 +528,6 @@ void RGWOp_BILog_Delete::execute() { RGWBucketInfo bucket_info; - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - http_ret = 0; if ((bucket_name.empty() && bucket_instance.empty()) || end_marker.empty()) { @@ -549,13 +543,13 @@ void RGWOp_BILog_Delete::execute() { } if (!bucket_instance.empty()) { - http_ret = store->get_bucket_instance_info(obj_ctx, bucket_instance, bucket_info, NULL, NULL); + http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, bucket_instance, bucket_info, NULL, NULL); if (http_ret < 0) { dout(5) << "could not get bucket instance info for bucket instance id=" << bucket_instance << dendl; return; } } else { /* !bucket_name.empty() */ - http_ret = store->get_bucket_info(obj_ctx, tenant_name, bucket_name, bucket_info, NULL, NULL); + http_ret = store->get_bucket_info(*s->sysobj_ctx, tenant_name, bucket_name, bucket_info, NULL, NULL); if (http_ret < 0) { dout(5) << "could not get bucket info for bucket=" << bucket_name << dendl; return; @@ -913,7 +907,7 @@ void RGWOp_BILog_Status::execute() } // read the bucket instance info for num_shards - RGWObjectCtx ctx(store); + auto ctx = store->svc.sysobj->init_obj_ctx(); RGWBucketInfo info; http_ret = store->get_bucket_instance_info(ctx, bucket, info, nullptr, nullptr); if (http_ret < 0) { diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 26377cb708e..df49e500e84 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1297,7 +1297,6 @@ int RGWPutObj_ObjStore_S3::get_params() if (!s->length) return -ERR_LENGTH_REQUIRED; - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); map src_attrs; size_t pos; int ret; @@ -1351,7 +1350,7 @@ int RGWPutObj_ObjStore_S3::get_params() return ret; } } - ret = store->get_bucket_info(obj_ctx, + ret = store->get_bucket_info(*s->sysobj_ctx, copy_source_tenant_name, copy_source_bucket_name, copy_source_bucket_info, @@ -3591,8 +3590,7 @@ int RGWHandler_REST_S3Website::retarget(RGWOp* op, RGWOp** new_op) { if (!(s->prot_flags & RGW_REST_WEBSITE)) return 0; - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - int ret = store->get_bucket_info(obj_ctx, s->bucket_tenant, + int ret = store->get_bucket_info(*s->sysobj_ctx, s->bucket_tenant, s->bucket_name, s->bucket_info, NULL, &s->bucket_attrs); if (ret < 0) { diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index f65e4c9fea8..9f4ff390123 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -2102,7 +2102,7 @@ void RGWFormPost::get_owner_info(const req_state* const s, /* Need to get user info of bucket owner. */ RGWBucketInfo bucket_info; - int ret = store->get_bucket_info(*static_cast(s->obj_ctx), + int ret = store->get_bucket_info(*s->sysobj_ctx, bucket_tenant, bucket_name, bucket_info, nullptr); if (ret < 0) { diff --git a/src/rgw/rgw_role.cc b/src/rgw/rgw_role.cc index d68be7fe7b5..b52000d7895 100644 --- a/src/rgw/rgw_role.cc +++ b/src/rgw/rgw_role.cc @@ -17,6 +17,7 @@ #include "rgw_role.h" #include "services/svc_zone.h" +#include "services/svc_sys_obj.h" #define dout_subsys ceph_subsys_rgw @@ -299,7 +300,7 @@ int RGWRole::read_id(const string& role_name, const string& tenant, string& role auto& pool = store->svc.zone->get_zone_params().roles_pool; string oid = tenant + get_names_oid_prefix() + role_name; bufferlist bl; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL); if (ret < 0) { @@ -325,7 +326,7 @@ int RGWRole::read_info() auto& pool = store->svc.zone->get_zone_params().roles_pool; string oid = get_info_oid_prefix() + id; bufferlist bl; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL); if (ret < 0) { @@ -352,7 +353,7 @@ int RGWRole::read_name() auto& pool = store->svc.zone->get_zone_params().roles_pool; string oid = tenant + get_names_oid_prefix() + name; bufferlist bl; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = rgw_get_system_obj(store, obj_ctx, pool, oid, bl, NULL, NULL); if (ret < 0) { diff --git a/src/rgw/rgw_swift_auth.cc b/src/rgw/rgw_swift_auth.cc index 97753e37871..c30350a96a1 100644 --- a/src/rgw/rgw_swift_auth.cc +++ b/src/rgw/rgw_swift_auth.cc @@ -106,7 +106,7 @@ void TempURLEngine::get_owner_info(const DoutPrefixProvider* dpp, const req_stat /* Need to get user info of bucket owner. */ RGWBucketInfo bucket_info; - int ret = store->get_bucket_info(*static_cast(s->obj_ctx), + int ret = store->get_bucket_info(*s->sysobj_ctx, bucket_tenant, bucket_name, bucket_info, nullptr); if (ret < 0) { diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index d28a3c2fa73..51e4f2952df 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -650,7 +650,7 @@ public: yield { set_status("writing sync status"); RGWRados *store = sync_env->store; - call(new RGWSimpleRadosWriteCR(sync_env->async_rados, store, + call(new RGWSimpleRadosWriteCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, sync_env->status_oid()), status)); } @@ -681,7 +681,7 @@ public: marker.timestamp = info.last_update; RGWRados *store = sync_env->store; spawn(new RGWSimpleRadosWriteCR(sync_env->async_rados, - store, + store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, sync_env->shard_obj_name(i)), marker), true); } @@ -690,7 +690,7 @@ public: set_status("changing sync state: build full sync maps"); status.state = rgw_meta_sync_info::StateBuildingFullSyncMaps; RGWRados *store = sync_env->store; - call(new RGWSimpleRadosWriteCR(sync_env->async_rados, store, + call(new RGWSimpleRadosWriteCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, sync_env->status_oid()), status)); } @@ -734,7 +734,7 @@ bool RGWReadSyncStatusMarkersCR::spawn_next() using CR = RGWSimpleRadosReadCR; rgw_raw_obj obj{env->store->svc.zone->get_zone_params().log_pool, env->shard_obj_name(shard_id)}; - spawn(new CR(env->async_rados, env->store, obj, &markers[shard_id]), false); + spawn(new CR(env->async_rados, env->store->svc.sysobj, obj, &markers[shard_id]), false); shard_id++; return true; } @@ -760,7 +760,7 @@ int RGWReadSyncStatusCoroutine::operate() bool empty_on_enoent = false; // fail on ENOENT rgw_raw_obj obj{sync_env->store->svc.zone->get_zone_params().log_pool, sync_env->status_oid()}; - call(new ReadInfoCR(sync_env->async_rados, sync_env->store, obj, + call(new ReadInfoCR(sync_env->async_rados, sync_env->store->svc.sysobj, obj, &sync_status->sync_info, empty_on_enoent)); } if (retcode < 0) { @@ -956,7 +956,7 @@ public: int shard_id = (int)iter->first; rgw_meta_sync_marker& marker = iter->second; marker.total_entries = entries_index->get_total_entries(shard_id); - spawn(new RGWSimpleRadosWriteCR(sync_env->async_rados, sync_env->store, + spawn(new RGWSimpleRadosWriteCR(sync_env->async_rados, sync_env->store->svc.sysobj, rgw_raw_obj(sync_env->store->svc.zone->get_zone_params().log_pool, sync_env->shard_obj_name(shard_id)), marker), true); } @@ -1213,7 +1213,7 @@ public: tn->log(20, SSTR("new marker=" << new_marker)); RGWRados *store = sync_env->store; return new RGWSimpleRadosWriteCR(sync_env->async_rados, - store, + store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, marker_oid), sync_marker); } @@ -1625,7 +1625,7 @@ public: ldpp_dout(sync_env->dpp, 4) << *this << ": saving marker pos=" << temp_marker->marker << " realm_epoch=" << realm_epoch << dendl; using WriteMarkerCR = RGWSimpleRadosWriteCR; - yield call(new WriteMarkerCR(sync_env->async_rados, sync_env->store, + yield call(new WriteMarkerCR(sync_env->async_rados, sync_env->store->svc.sysobj, rgw_raw_obj(pool, sync_env->shard_obj_name(shard_id)), *temp_marker)); } @@ -1869,7 +1869,7 @@ public: RGWCoroutine *alloc_finisher_cr() override { RGWRados *store = sync_env->store; - return new RGWSimpleRadosReadCR(sync_env->async_rados, store, + return new RGWSimpleRadosReadCR(sync_env->async_rados, store->svc.sysobj, rgw_raw_obj(pool, sync_env->shard_obj_name(shard_id)), &sync_marker); } @@ -1983,7 +1983,7 @@ public: sync_status.sync_info.period = cursor.get_period().get_id(); sync_status.sync_info.realm_epoch = cursor.get_epoch(); yield call(new RGWSimpleRadosWriteCR(sync_env->async_rados, - sync_env->store, + sync_env->store->svc.sysobj, rgw_raw_obj(pool, sync_env->status_oid()), sync_status.sync_info)); } @@ -2060,7 +2060,7 @@ int RGWRemoteMetaLog::init_sync_status() int RGWRemoteMetaLog::store_sync_info(const rgw_meta_sync_info& sync_info) { tn->log(20, "store sync info"); - return run(new RGWSimpleRadosWriteCR(async_rados, store, + return run(new RGWSimpleRadosWriteCR(async_rados, store->svc.sysobj, rgw_raw_obj(store->svc.zone->get_zone_params().log_pool, sync_env.status_oid()), sync_info)); } diff --git a/src/rgw/rgw_sync_log_trim.cc b/src/rgw/rgw_sync_log_trim.cc index cfa13bfc9d9..cd15df604b7 100644 --- a/src/rgw/rgw_sync_log_trim.cc +++ b/src/rgw/rgw_sync_log_trim.cc @@ -784,7 +784,7 @@ int BucketTrimCR::operate() // read BucketTrimStatus for marker position set_status("reading trim status"); using ReadStatus = RGWSimpleRadosReadCR; - yield call(new ReadStatus(store->get_async_rados(), store, obj, + yield call(new ReadStatus(store->get_async_rados(), store->svc.sysobj, obj, &status, true, &objv)); if (retcode < 0) { ldout(cct, 10) << "failed to read bilog trim status: " @@ -842,7 +842,7 @@ int BucketTrimCR::operate() status.marker = std::move(last_cold_marker); ldout(cct, 20) << "writing bucket trim marker=" << status.marker << dendl; using WriteStatus = RGWSimpleRadosWriteCR; - yield call(new WriteStatus(store->get_async_rados(), store, obj, + yield call(new WriteStatus(store->get_async_rados(), store->svc.sysobj, obj, status, &objv)); if (retcode < 0) { ldout(cct, 4) << "failed to write updated trim status: " diff --git a/src/rgw/rgw_sync_module_aws.cc b/src/rgw/rgw_sync_module_aws.cc index 1684d2a2600..a9c0d5d9ee3 100644 --- a/src/rgw/rgw_sync_module_aws.cc +++ b/src/rgw/rgw_sync_module_aws.cc @@ -1430,7 +1430,7 @@ public: int operate() override { reenter(this) { - yield call(new RGWSimpleRadosReadCR(sync_env->async_rados, sync_env->store, + yield call(new RGWSimpleRadosReadCR(sync_env->async_rados, sync_env->store->svc.sysobj, status_obj, &status, false)); if (retcode < 0 && retcode != -ENOENT) { @@ -1493,7 +1493,7 @@ public: return set_cr_error(ret_err); } - yield call(new RGWSimpleRadosWriteCR(sync_env->async_rados, sync_env->store, status_obj, status)); + yield call(new RGWSimpleRadosWriteCR(sync_env->async_rados, sync_env->store->svc.sysobj, status_obj, status)); if (retcode < 0) { ldout(sync_env->cct, 0) << "ERROR: failed to store multipart upload state, retcode=" << retcode << dendl; /* continue with upload anyway */ diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index 592de20294c..b3e89532870 100644 --- a/src/rgw/rgw_tools.cc +++ b/src/rgw/rgw_tools.cc @@ -12,33 +12,49 @@ #include "rgw_rados.h" #include "rgw_tools.h" +#include "services/svc_sys_obj.h" + #define dout_subsys ceph_subsys_rgw #define READ_CHUNK_LEN (512 * 1024) static std::map* ext_mime_map; -int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, const bufferlist& data, bool exclusive, +int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, bufferlist& data, bool exclusive, RGWObjVersionTracker *objv_tracker, real_time set_mtime, map *pattrs) { map no_attrs; - if (!pattrs) + if (!pattrs) { pattrs = &no_attrs; + } rgw_raw_obj obj(pool, oid); - int ret = rgwstore->put_system_obj(NULL, obj, data, exclusive, NULL, *pattrs, objv_tracker, set_mtime); + auto obj_ctx = rgwstore->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + int ret = sysobj.wop() + .set_objv_tracker(objv_tracker) + .set_exclusive(exclusive) + .set_mtime(set_mtime) + .set_attrs(*pattrs) + .write(data); if (ret == -ENOENT) { ret = rgwstore->create_pool(pool); - if (ret >= 0) - ret = rgwstore->put_system_obj(NULL, obj, data, exclusive, NULL, *pattrs, objv_tracker, set_mtime); + if (ret >= 0) { + ret = sysobj.wop() + .set_objv_tracker(objv_tracker) + .set_exclusive(exclusive) + .set_mtime(set_mtime) + .set_attrs(*pattrs) + .write(data); + } } return ret; } -int rgw_get_system_obj(RGWRados *rgwstore, RGWObjectCtx& obj_ctx, const rgw_pool& pool, const string& key, bufferlist& bl, +int rgw_get_system_obj(RGWRados *rgwstore, RGWSysObjectCtx& obj_ctx, const rgw_pool& pool, const string& key, bufferlist& bl, RGWObjVersionTracker *objv_tracker, real_time *pmtime, map *pattrs, rgw_cache_entry_info *cache_info, boost::optional refresh_version) { @@ -52,19 +68,19 @@ int rgw_get_system_obj(RGWRados *rgwstore, RGWObjectCtx& obj_ctx, const rgw_pool } do { - RGWRados::SystemObject source(rgwstore, obj_ctx, obj); - RGWRados::SystemObject::Read rop(&source); + auto sysobj = obj_ctx.get_obj(obj); + auto rop = sysobj.rop(); - rop.stat_params.attrs = pattrs; - rop.stat_params.lastmod = pmtime; - - int ret = rop.stat(objv_tracker); + int ret = rop.set_attrs(pattrs) + .set_last_mod(pmtime) + .set_objv_tracker(objv_tracker) + .stat(); if (ret < 0) return ret; - rop.read_params.cache_info = cache_info; - - ret = rop.read(0, request_len - 1, bl, objv_tracker, refresh_version); + ret = rop.set_cache_info(cache_info) + .set_refresh_version(refresh_version) + .read(&bl); if (ret == -ECANCELED) { /* raced, restart */ if (!original_readv.empty()) { @@ -74,7 +90,7 @@ int rgw_get_system_obj(RGWRados *rgwstore, RGWObjectCtx& obj_ctx, const rgw_pool if (objv_tracker) { objv_tracker->read_version.clear(); } - source.invalidate_state(); + sysobj.invalidate(); continue; } if (ret < 0) @@ -92,8 +108,12 @@ int rgw_get_system_obj(RGWRados *rgwstore, RGWObjectCtx& obj_ctx, const rgw_pool int rgw_delete_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, RGWObjVersionTracker *objv_tracker) { + auto obj_ctx = rgwstore->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(rgw_raw_obj{pool, oid}); rgw_raw_obj obj(pool, oid); - return rgwstore->delete_system_obj(obj, objv_tracker); + return sysobj.wop() + .set_objv_tracker(objv_tracker) + .remove(); } void parse_mime_map_line(const char *start, const char *end) diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h index ba39a99c998..38e85f651b9 100644 --- a/src/rgw/rgw_tools.h +++ b/src/rgw/rgw_tools.h @@ -11,14 +11,14 @@ #include "rgw_common.h" class RGWRados; -class RGWObjectCtx; +class RGWSysObjectCtx; struct RGWObjVersionTracker; struct obj_version; -int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, const bufferlist& data, bool exclusive, +int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, bufferlist& data, bool exclusive, RGWObjVersionTracker *objv_tracker, real_time set_mtime, map *pattrs = NULL); -int rgw_get_system_obj(RGWRados *rgwstore, RGWObjectCtx& obj_ctx, const rgw_pool& pool, const string& key, bufferlist& bl, +int rgw_get_system_obj(RGWRados *rgwstore, RGWSysObjectCtx& obj_ctx, const rgw_pool& pool, const string& key, bufferlist& bl, RGWObjVersionTracker *objv_tracker, real_time *pmtime, map *pattrs = NULL, rgw_cache_entry_info *cache_info = NULL, boost::optional refresh_version = boost::none); diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 64d2aa27db2..3911a64961f 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -26,6 +26,8 @@ #include "rgw_quota.h" #include "services/svc_zone.h" +#include "services/svc_sys_obj.h" +#include "services/svc_sys_obj_cache.h" #define dout_subsys ceph_subsys_rgw @@ -51,7 +53,7 @@ int rgw_user_sync_all_stats(RGWRados *store, const rgw_user& user_id) bool is_truncated = false; string marker; int ret; - RGWObjectCtx obj_ctx(store); + RGWSysObjectCtx obj_ctx = store->svc.sysobj->init_obj_ctx(); do { RGWUserBuckets user_buckets; @@ -276,7 +278,7 @@ int rgw_get_user_info_from_index(RGWRados * const store, user_info_entry e; bufferlist bl; RGWUID uid; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); int ret = rgw_get_system_obj(store, obj_ctx, pool, key, bl, NULL, &e.mtime); if (ret < 0) @@ -296,7 +298,7 @@ int rgw_get_user_info_from_index(RGWRados * const store, return -EIO; } - uinfo_cache.put(store, key, &e, { &cache_info }); + uinfo_cache.put(store->svc.cache, key, &e, { &cache_info }); info = e.info; if (objv_tracker) @@ -322,7 +324,7 @@ int rgw_get_user_info_by_uid(RGWRados *store, bufferlist bl; RGWUID user_id; - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); string oid = uid.to_str(); int ret = rgw_get_system_obj(store, obj_ctx, store->svc.zone->get_zone_params().user_uid_pool, oid, bl, objv_tracker, pmtime, pattrs, cache_info); if (ret < 0) { @@ -392,20 +394,22 @@ int rgw_get_user_attrs_by_uid(RGWRados *store, map& attrs, RGWObjVersionTracker *objv_tracker) { - RGWObjectCtx obj_ctx(store); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); rgw_raw_obj obj(store->svc.zone->get_zone_params().user_uid_pool, user_id.to_str()); - RGWRados::SystemObject src(store, obj_ctx, obj); - RGWRados::SystemObject::Read rop(&src); + auto src = obj_ctx.get_obj(obj); - rop.stat_params.attrs = &attrs; - return rop.stat(objv_tracker); + return src.rop() + .set_attrs(&attrs) + .set_objv_tracker(objv_tracker) + .stat(); } int rgw_remove_key_index(RGWRados *store, RGWAccessKey& access_key) { rgw_raw_obj obj(store->svc.zone->get_zone_params().user_keys_pool, access_key.id); - int ret = store->delete_system_obj(obj); - return ret; + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + return sysobj.wop().remove(); } int rgw_remove_uid_index(RGWRados *store, rgw_user& uid) @@ -430,14 +434,17 @@ int rgw_remove_email_index(RGWRados *store, string& email) return 0; } rgw_raw_obj obj(store->svc.zone->get_zone_params().user_email_pool, email); - return store->delete_system_obj(obj); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + return sysobj.wop().remove(); } int rgw_remove_swift_name_index(RGWRados *store, string& swift_name) { rgw_raw_obj obj(store->svc.zone->get_zone_params().user_swift_pool, swift_name); - int ret = store->delete_system_obj(obj); - return ret; + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(obj); + return sysobj.wop().remove(); } /** @@ -483,7 +490,9 @@ int rgw_delete_user(RGWRados *store, RGWUserInfo& info, RGWObjVersionTracker& ob rgw_get_buckets_obj(info.user_id, buckets_obj_id); rgw_raw_obj uid_bucks(store->svc.zone->get_zone_params().user_uid_pool, buckets_obj_id); ldout(store->ctx(), 10) << "removing user buckets index" << dendl; - ret = store->delete_system_obj(uid_bucks); + auto obj_ctx = store->svc.sysobj->init_obj_ctx(); + auto sysobj = obj_ctx.get_obj(uid_bucks); + ret = sysobj.wop().remove(); if (ret < 0 && ret != -ENOENT) { ldout(store->ctx(), 0) << "ERROR: could not remove " << info.user_id << ":" << uid_bucks << ", should be fixed (err=" << ret << ")" << dendl; return ret; @@ -2816,7 +2825,7 @@ public: void rgw_user_init(RGWRados *store) { - uinfo_cache.init(store); + uinfo_cache.init(store->svc.cache); user_meta_handler = new RGWUserMetadataHandler; store->meta_mgr->register_handler(user_meta_handler); diff --git a/src/rgw/services/svc_sys_obj.cc b/src/rgw/services/svc_sys_obj.cc index a553c6b282b..b00a5d685a2 100644 --- a/src/rgw/services/svc_sys_obj.cc +++ b/src/rgw/services/svc_sys_obj.cc @@ -44,7 +44,7 @@ int RGWSI_SysObj::load(const string& conf, std::mapset_attrs(obj, attrs, nullptr, objv_tracker); } +int RGWSI_SysObj::Obj::WOp::write_attr(const char *name, bufferlist& bl) +{ + RGWSI_SysObj_Core *svc = source.core_svc; + rgw_raw_obj& obj = source.get_obj(); + + map m; + m[name] = bl; + + return svc->set_attrs(obj, m, nullptr, objv_tracker); +} + int RGWSI_SysObj::Pool::Op::list_prefixed_objs(const string& prefix, list *result) { bool is_truncated; diff --git a/src/rgw/services/svc_sys_obj.h b/src/rgw/services/svc_sys_obj.h index 869fcda441e..0d792ea7839 100644 --- a/src/rgw/services/svc_sys_obj.h +++ b/src/rgw/services/svc_sys_obj.h @@ -39,7 +39,7 @@ public: ctx(_ctx), obj(_obj) {} - void invalidate_state(); + void invalidate(); RGWSysObjectCtx& get_ctx() { return ctx; @@ -61,6 +61,11 @@ public: uint64_t *obj_size{nullptr}; rgw_cache_entry_info *cache_info{nullptr}; + ROp& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) { + objv_tracker = _objv_tracker; + return *this; + } + ROp& set_last_mod(ceph::real_time *_lastmod) { lastmod = _lastmod; return *this; @@ -76,7 +81,7 @@ public: return *this; } - ROp& set_refresh_version(const obj_version& rf) { + ROp& set_refresh_version(boost::optional& rf) { refresh_version = rf; return *this; } @@ -105,6 +110,16 @@ public: ceph::real_time *pmtime{nullptr}; bool exclusive{false}; + WOp& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) { + objv_tracker = _objv_tracker; + return *this; + } + + WOp& set_attrs(map& _attrs) { + attrs = _attrs; + return *this; + } + WOp& set_attrs(map&& _attrs) { attrs = _attrs; return *this; @@ -132,6 +147,7 @@ public: int write_data(bufferlist& bl); /* write data only */ int write_attrs(); /* write attrs only */ + int write_attr(const char *name, bufferlist& bl); /* write attrs only */ }; struct OmapOp { diff --git a/src/rgw/services/svc_sys_obj_cache.h b/src/rgw/services/svc_sys_obj_cache.h index b573a37fd25..f16ef4fa8db 100644 --- a/src/rgw/services/svc_sys_obj_cache.h +++ b/src/rgw/services/svc_sys_obj_cache.h @@ -95,4 +95,63 @@ public: int call_zap(); }; +template +class RGWChainedCacheImpl : public RGWChainedCache { + RGWSI_SysObj_Cache *svc{nullptr}; + ceph::timespan expiry; + RWLock lock; + + std::unordered_map> entries; + +public: + RGWChainedCacheImpl() : lock("RGWChainedCacheImpl::lock") {} + + void init(RGWSI_SysObj_Cache *svc) { + svc->register_chained_cache(this); + expiry = std::chrono::seconds(svc->ctx()->_conf.get_val( + "rgw_cache_expiry_interval")); + } + + boost::optional find(const string& key) { + RWLock::RLocker rl(lock); + auto iter = entries.find(key); + if (iter == entries.end()) { + return boost::none; + } + if (expiry.count() && + (ceph::coarse_mono_clock::now() - iter->second.second) > expiry) { + return boost::none; + } + + return iter->second.first; + } + + bool put(RGWSI_SysObj_Cache *svc, const string& key, T *entry, + std::initializer_list cache_info_entries) { + Entry chain_entry(this, key, entry); + + /* we need the svc cache to call us under its lock to maintain lock ordering */ + return svc->chain_cache_entry(cache_info_entries, &chain_entry); + } + + void chain_cb(const string& key, void *data) override { + T *entry = static_cast(data); + RWLock::WLocker wl(lock); + entries[key].first = *entry; + if (expiry.count() > 0) { + entries[key].second = ceph::coarse_mono_clock::now(); + } + } + + void invalidate(const string& key) override { + RWLock::WLocker wl(lock); + entries.erase(key); + } + + void invalidate_all() override { + RWLock::WLocker wl(lock); + entries.clear(); + } +}; /* RGWChainedCacheImpl */ + #endif -- 2.39.5