From fcd7b14a675cbb3e79f5d88637e953091b14cd09 Mon Sep 17 00:00:00 2001 From: Daniel Gryniewicz Date: Fri, 8 Jul 2022 13:50:42 -0400 Subject: [PATCH] RGW - Zipper - make Serializer use unique_ptr Serializer needs to use a unique_ptr like the rest of the SAL API. Signed-off-by: Daniel Gryniewicz --- src/rgw/rgw_lc.cc | 24 +++++++++--------------- src/rgw/rgw_op.cc | 4 ++-- src/rgw/rgw_op.h | 6 +++--- src/rgw/rgw_sal.h | 7 +++++-- src/rgw/rgw_sal_dbstore.cc | 11 +++++++---- src/rgw/rgw_sal_dbstore.h | 7 +++++-- src/rgw/rgw_sal_motr.cc | 5 +++-- src/rgw/rgw_sal_motr.h | 2 +- src/rgw/rgw_sal_rados.cc | 10 ++++++---- src/rgw/rgw_sal_rados.h | 7 +++++-- 10 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index a8b6bc655d1d5..69c0e6c32457a 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -1707,9 +1707,8 @@ int RGWLC::bucket_lc_post(int index, int max_lock_sec, { utime_t lock_duration(cct->_conf->rgw_lc_lock_max_time, 0); - rgw::sal::LCSerializer* lock = sal_lc->get_serializer(lc_index_lock_name, - obj_names[index], - cookie); + std::unique_ptr lock = + sal_lc->get_serializer(lc_index_lock_name, obj_names[index], cookie); ldpp_dout(this, 5) << "RGWLC::bucket_lc_post(): POST " << entry << " index: " << index << " worker ix: " << worker->ix @@ -1753,7 +1752,6 @@ int RGWLC::bucket_lc_post(int index, int max_lock_sec, } clean: lock->unlock(); - delete lock; ldpp_dout(this, 20) << "RGWLC::bucket_lc_post() unlock " << obj_names[index] << dendl; return 0; @@ -1902,9 +1900,9 @@ int RGWLC::process_bucket(int index, int max_lock_secs, LCWorker* worker, << dendl; int ret = 0; - std::unique_ptr serializer( + std::unique_ptr serializer = sal_lc->get_serializer(lc_index_lock_name, obj_names[index], - std::string())); + std::string()); std::unique_ptr entry; if (max_lock_secs <= 0) { @@ -2055,7 +2053,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, << "index: " << index << " worker ix: " << worker->ix << dendl; - rgw::sal::LCSerializer* lock = + std::unique_ptr lock = sal_lc->get_serializer(lc_index_lock_name, lc_shard, std::string()); utime_t lock_for_s(max_lock_secs, 0); @@ -2076,7 +2074,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, ldpp_dout(this, 0) << "RGWLC::process(): failed to aquire lock on " << lc_shard << " after " << shard_lock.get_retries() << dendl; - goto notlocked; + return 0; } do { @@ -2235,7 +2233,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, ldpp_dout(this, 0) << "RGWLC::process(): failed to aquire lock on " << lc_shard << " after " << shard_lock.get_retries() << dendl; - goto notlocked; + return 0; } if (ret == -ENOENT) { @@ -2284,8 +2282,6 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, exit: lock->unlock(); -notlocked: - delete lock; return 0; } @@ -2417,9 +2413,8 @@ static int guard_lc_modify(const DoutPrefixProvider *dpp, entry->set_status(lc_uninitial); int max_lock_secs = cct->_conf->rgw_lc_lock_max_time; - rgw::sal::LCSerializer* lock = sal_lc->get_serializer(lc_index_lock_name, - oid, - cookie); + std::unique_ptr lock = + sal_lc->get_serializer(lc_index_lock_name, oid, cookie); utime_t time(max_lock_secs, 0); int ret; @@ -2445,7 +2440,6 @@ static int guard_lc_modify(const DoutPrefixProvider *dpp, break; } while(true); lock->unlock(); - delete lock; return ret; } diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 5c3e50d3ee0a2..7625ebd2ead4f 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -6464,10 +6464,10 @@ bool RGWCompleteMultipart::check_previously_completed(const RGWMultiCompleteUplo void RGWCompleteMultipart::complete() { /* release exclusive lock iff not already */ - if (unlikely(serializer && serializer->is_locked())) { + if (unlikely(serializer.get() && serializer->is_locked())) { int r = serializer->unlock(); if (r < 0) { - ldpp_dout(this, 0) << "WARNING: failed to unlock " << serializer << dendl; + ldpp_dout(this, 0) << "WARNING: failed to unlock " << *serializer.get() << dendl; } } send_response(); diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 9176d2389350a..75508c0660493 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -1861,12 +1861,12 @@ protected: std::string etag; std::string version_id; bufferlist data; - rgw::sal::MPSerializer* serializer; + std::unique_ptr serializer; jspan multipart_trace; public: - RGWCompleteMultipart() : serializer(nullptr) {} - ~RGWCompleteMultipart() override { delete serializer; } + RGWCompleteMultipart() {} + ~RGWCompleteMultipart() = default; int verify_permission(optional_yield y) override; void pre_exec() override; diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index 799af26367db6..09a15d3607a7a 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -989,7 +989,8 @@ class Object { /** Create a randomized instance ID for this object */ virtual void gen_rand_obj_instance_name() = 0; /** Get a multipart serializer for this object */ - virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) = 0; + virtual std::unique_ptr get_serializer(const DoutPrefixProvider *dpp, + const std::string& lock_name) = 0; /** Move the data of an object to new placement storage */ virtual int transition(Bucket* bucket, const rgw_placement_rule& placement_rule, @@ -1350,7 +1351,9 @@ public: virtual int put_head(const std::string& oid, LCHead& head) = 0; /** Get a serializer for lifecycle */ - virtual LCSerializer* get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) = 0; + virtual std::unique_ptr get_serializer(const std::string& lock_name, + const std::string& oid, + const std::string& cookie) = 0; }; /** diff --git a/src/rgw/rgw_sal_dbstore.cc b/src/rgw/rgw_sal_dbstore.cc index dbf0f812920c8..664e104858ce0 100644 --- a/src/rgw/rgw_sal_dbstore.cc +++ b/src/rgw/rgw_sal_dbstore.cc @@ -722,9 +722,10 @@ namespace rgw::sal { return op_target.obj_omap_set_val_by_key(dpp, key, val, must_exist); } - MPSerializer* DBObject::get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) + std::unique_ptr DBObject::get_serializer(const DoutPrefixProvider *dpp, + const std::string& lock_name) { - return new MPDBSerializer(dpp, store, this, lock_name); + return std::make_unique(dpp, store, this, lock_name); } int DBObject::transition(Bucket* bucket, @@ -1807,9 +1808,11 @@ namespace rgw::sal { return store->getDB()->put_head(oid, head); } - LCSerializer* DBLifecycle::get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) + std::unique_ptr DBLifecycle::get_serializer(const std::string& lock_name, + const std::string& oid, + const std::string& cookie) { - return new LCDBSerializer(store, oid, lock_name, cookie); + return std::make_unique(store, oid, lock_name, cookie); } std::unique_ptr DBStore::get_notification( diff --git a/src/rgw/rgw_sal_dbstore.h b/src/rgw/rgw_sal_dbstore.h index 239211de6c851..88f9ef750a0f8 100644 --- a/src/rgw/rgw_sal_dbstore.h +++ b/src/rgw/rgw_sal_dbstore.h @@ -55,7 +55,9 @@ public: virtual int rm_entry(const std::string& oid, LCEntry& entry) override; virtual int get_head(const std::string& oid, std::unique_ptr* head) override; virtual int put_head(const std::string& oid, LCHead& head) override; - virtual LCSerializer* get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) override; + virtual std::unique_ptr get_serializer(const std::string& lock_name, + const std::string& oid, + const std::string& cookie) override; }; class DBNotification : public StoreNotification { @@ -576,7 +578,8 @@ protected: virtual std::unique_ptr clone() override { return std::unique_ptr(new DBObject(*this)); } - virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override; + virtual std::unique_ptr get_serializer(const DoutPrefixProvider *dpp, + const std::string& lock_name) override; virtual int transition(Bucket* bucket, const rgw_placement_rule& placement_rule, const real_time& mtime, diff --git a/src/rgw/rgw_sal_motr.cc b/src/rgw/rgw_sal_motr.cc index 85d61aa2b03a0..1de0955ae5b13 100644 --- a/src/rgw/rgw_sal_motr.cc +++ b/src/rgw/rgw_sal_motr.cc @@ -1110,9 +1110,10 @@ int MotrObject::omap_set_val_by_key(const DoutPrefixProvider *dpp, const std::st return 0; } -MPSerializer* MotrObject::get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) +std::unique_ptr MotrObject::get_serializer(const DoutPrefixProvider *dpp, + const std::string& lock_name) { - return new MPMotrSerializer(dpp, store, this, lock_name); + return std::make_unique(dpp, store, this, lock_name); } int MotrObject::transition(Bucket* bucket, diff --git a/src/rgw/rgw_sal_motr.h b/src/rgw/rgw_sal_motr.h index e2684637ca24c..c3784d2324f76 100644 --- a/src/rgw/rgw_sal_motr.h +++ b/src/rgw/rgw_sal_motr.h @@ -609,7 +609,7 @@ class MotrObject : public StoreObject { virtual std::unique_ptr clone() override { return std::unique_ptr(new MotrObject(*this)); } - virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override; + virtual std::unique_ptr get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override; virtual int transition(Bucket* bucket, const rgw_placement_rule& placement_rule, const real_time& mtime, diff --git a/src/rgw/rgw_sal_rados.cc b/src/rgw/rgw_sal_rados.cc index 2533e210972e1..6d7c93c9ce14f 100644 --- a/src/rgw/rgw_sal_rados.cc +++ b/src/rgw/rgw_sal_rados.cc @@ -1721,9 +1721,9 @@ int RadosObject::omap_set_val_by_key(const DoutPrefixProvider *dpp, const std::s return sysobj.omap().set_must_exist(must_exist).set(dpp, key, val, y); } -MPSerializer* RadosObject::get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) +std::unique_ptr RadosObject::get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) { - return new MPRadosSerializer(dpp, store, this, lock_name); + return std::make_unique(dpp, store, this, lock_name); } int RadosObject::transition(Bucket* bucket, @@ -2799,9 +2799,11 @@ int RadosLifecycle::put_head(const std::string& oid, LCHead& head) return cls_rgw_lc_put_head(*store->getRados()->get_lc_pool_ctx(), oid, cls_head); } -LCSerializer* RadosLifecycle::get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) +std::unique_ptr RadosLifecycle::get_serializer(const std::string& lock_name, + const std::string& oid, + const std::string& cookie) { - return new LCRadosSerializer(store, oid, lock_name, cookie); + return std::make_unique(store, oid, lock_name, cookie); } int RadosNotification::publish_reserve(const DoutPrefixProvider *dpp, RGWObjTags* obj_tags) diff --git a/src/rgw/rgw_sal_rados.h b/src/rgw/rgw_sal_rados.h index 47fcb12797f66..edf2321aac937 100644 --- a/src/rgw/rgw_sal_rados.h +++ b/src/rgw/rgw_sal_rados.h @@ -418,7 +418,8 @@ class RadosObject : public StoreObject { virtual std::unique_ptr clone() override { return std::unique_ptr(new RadosObject(*this)); } - virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override; + virtual std::unique_ptr get_serializer(const DoutPrefixProvider *dpp, + const std::string& lock_name) override; virtual int transition(Bucket* bucket, const rgw_placement_rule& placement_rule, const real_time& mtime, @@ -704,7 +705,9 @@ public: virtual int rm_entry(const std::string& oid, LCEntry& entry) override; virtual int get_head(const std::string& oid, std::unique_ptr* head) override; virtual int put_head(const std::string& oid, LCHead& head) override; - virtual LCSerializer* get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) override; + virtual std::unique_ptr get_serializer(const std::string& lock_name, + const std::string& oid, + const std::string& cookie) override; }; class RadosNotification : public StoreNotification { -- 2.39.5