From 488583ad4e7eb0fd852aaba8e56fd2b517496fae Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 5 Mar 2019 12:07:24 -0800 Subject: [PATCH] rgw: svc bucket: set bucket instance info Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rados.cc | 25 +++++++---------------- src/rgw/services/svc_bucket.cc | 37 ++++++++++++++++++++++++++++++++++ src/rgw/services/svc_bucket.h | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 18 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 31299c8f338..0a372da9576 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -7896,25 +7896,14 @@ int RGWRados::put_bucket_entrypoint_info(const string& tenant_name, const string int RGWRados::put_bucket_instance_info(RGWBucketInfo& info, bool exclusive, real_time mtime, map *pattrs) { - info.has_instance_obj = true; - bufferlist bl; - - encode(info, bl); + RGWSysObjectCtx obj_ctx = svc.sysobj->init_obj_ctx(); + auto instance = svc.bucket->instance(obj_ctx, info.bucket.tenant, info.bucket.name); - string key = info.bucket.get_key(); /* when we go through meta api, we don't use oid directly */ - int ret = rgw_bucket_instance_store_info(this, key, bl, exclusive, pattrs, &info.objv_tracker, mtime); - if (ret == -EEXIST) { - /* well, if it's exclusive we shouldn't overwrite it, because we might race with another - * bucket operation on this specific bucket (e.g., being synced from the master), but - * since bucket instace meta object is unique for this specific bucket instace, we don't - * need to return an error. - * A scenario where we'd get -EEXIST here, is in a multi-zone config, we're not on the - * master, creating a bucket, sending bucket creation to the master, we create the bucket - * locally, while in the sync thread we sync the new bucket. - */ - ret = 0; - } - return ret; + return instance.set_op() + .set_exclusive(exclusive) + .set_mtime(mtime) + .set_attrs(pattrs) + .exec(); } int RGWRados::put_linked_bucket_info(RGWBucketInfo& info, bool exclusive, real_time mtime, obj_version *pep_objv, diff --git a/src/rgw/services/svc_bucket.cc b/src/rgw/services/svc_bucket.cc index ac6474d2383..206855682e2 100644 --- a/src/rgw/services/svc_bucket.cc +++ b/src/rgw/services/svc_bucket.cc @@ -223,6 +223,31 @@ int RGWSI_Bucket::Instance::read_bucket_info(const rgw_bucket& bucket, return 0; } +int RGWSI_Bucket::Instance::write_bucket_instance_info(RGWBucketInfo& info, + bool exclusive, + real_time mtime, + map *pattrs) +{ + info.has_instance_obj = true; + bufferlist bl; + + encode(info, bl); + + string key = info.bucket.get_key(); /* when we go through meta api, we don't use oid directly */ + int ret = rgw_bucket_instance_store_info(this, key, bl, exclusive, pattrs, &info.objv_tracker, mtime); + if (ret == -EEXIST) { + /* well, if it's exclusive we shouldn't overwrite it, because we might race with another + * bucket operation on this specific bucket (e.g., being synced from the master), but + * since bucket instace meta object is unique for this specific bucket instace, we don't + * need to return an error. + * A scenario where we'd get -EEXIST here, is in a multi-zone config, we're not on the + * master, creating a bucket, sending bucket creation to the master, we create the bucket + * locally, while in the sync thread we sync the new bucket. + */ + ret = 0; + } + return ret; +} int RGWSI_Bucket::Instance::GetOp::exec() { @@ -240,3 +265,15 @@ int RGWSI_Bucket::Instance::GetOp::exec() return 0; } + +int RGWSI_Bucket::Instance::SetOp::exec() +{ + int r = source.write_bucket_instance_info(source.bucket_info, + exclusive, + mtime, pattrs); + if (r < 0) { + return r; + } + + return 0; +} diff --git a/src/rgw/services/svc_bucket.h b/src/rgw/services/svc_bucket.h index 2657548620a..a4a734522a4 100644 --- a/src/rgw/services/svc_bucket.h +++ b/src/rgw/services/svc_bucket.h @@ -95,6 +95,10 @@ public: boost::optional refresh_version, optional_yield y); + int write_bucket_instance_info(RGWBucketInfo& info, + bool exclusive, + real_time mtime, + map *pattrs); public: Instance(RGWSI_Bucket *_bucket_svc, RGWSysObjectCtx& _ctx, @@ -163,9 +167,41 @@ public: int exec(); }; + struct SetOp { + Instance& source; + + ceph::real_time mtime; + map *pattrs{nullptr}; + bool exclusive{false}; + + + SetOp& set_mtime(const ceph::real_time& _mtime) { + mtime = _mtime; + return *this; + } + + SetOp& set_attrs(map *_attrs) { + pattrs = _attrs; + return *this; + } + + SetOp& set_exclusive(bool _exclusive) { + exclusive = _exclusive; + return *this; + } + + SetOp(Instance& _source) : source(_source) {} + + int exec(); + }; + GetOp get_op() { return GetOp(*this); } + + SetOp set_op() { + return SetOp(*this); + } }; Instance instance(RGWSysObjectCtx& _ctx, -- 2.39.5