]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
RGW - Zipper - make Serializer use unique_ptr
authorDaniel Gryniewicz <dang@redhat.com>
Fri, 8 Jul 2022 17:50:42 +0000 (13:50 -0400)
committerDaniel Gryniewicz <dang@redhat.com>
Wed, 27 Jul 2022 17:32:53 +0000 (13:32 -0400)
Serializer needs to use a unique_ptr like the rest of the SAL API.

Signed-off-by: Daniel Gryniewicz <dang@redhat.com>
src/rgw/rgw_lc.cc
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_sal.h
src/rgw/rgw_sal_dbstore.cc
src/rgw/rgw_sal_dbstore.h
src/rgw/rgw_sal_motr.cc
src/rgw/rgw_sal_motr.h
src/rgw/rgw_sal_rados.cc
src/rgw/rgw_sal_rados.h

index a8b6bc655d1d5729f4b1b2baa75875defdc798f3..69c0e6c32457afa9b817d6d1c872975e0992c01c 100644 (file)
@@ -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<rgw::sal::LCSerializer> 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<rgw::sal::LCSerializer> serializer(
+  std::unique_ptr<rgw::sal::LCSerializer> serializer =
     sal_lc->get_serializer(lc_index_lock_name, obj_names[index],
-                          std::string()));
+                          std::string());
 
   std::unique_ptr<rgw::sal::Lifecycle::LCEntry> 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<rgw::sal::LCSerializer> 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<rgw::sal::LCSerializer> 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;
 }
 
index 5c3e50d3ee0a2749bf08618c9bf1e959f497a163..7625ebd2ead4f8c278c68d58e6c93e81f4cd7ffd 100644 (file)
@@ -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();
index 9176d2389350a0314827e163fa39b1e32cafc548..75508c0660493ae286f56420b2974db54519978e 100644 (file)
@@ -1861,12 +1861,12 @@ protected:
   std::string etag;
   std::string version_id;
   bufferlist data;
-  rgw::sal::MPSerializer* serializer;
+  std::unique_ptr<rgw::sal::MPSerializer> 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;
index 799af26367db6d64799fa24714f0bdef9d56a22e..09a15d3607a7abd2143372616d3ffb4ce4fa4d55 100644 (file)
@@ -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<MPSerializer> 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<LCSerializer> get_serializer(const std::string& lock_name,
+                                                      const std::string& oid,
+                                                      const std::string& cookie) = 0;
 };
 
 /**
index dbf0f812920c8af3c9521ad7e65f7f2d74a88460..664e104858ce0e3d814572d5f985dc9a2fff31d2 100644 (file)
@@ -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<MPSerializer> DBObject::get_serializer(const DoutPrefixProvider *dpp,
+                                                        const std::string& lock_name)
   {
-    return new MPDBSerializer(dpp, store, this, lock_name);
+    return std::make_unique<MPDBSerializer>(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<LCSerializer> 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<LCDBSerializer>(store, oid, lock_name, cookie);
   }
 
   std::unique_ptr<Notification> DBStore::get_notification(
index 239211de6c851c767cd7b16b1f4b2c9128f3133c..88f9ef750a0f88651c2d3a34927229be2dce91f9 100644 (file)
@@ -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<LCHead>* 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<LCSerializer> 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<Object> clone() override {
         return std::unique_ptr<Object>(new DBObject(*this));
       }
-      virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override;
+      virtual std::unique_ptr<MPSerializer> 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,
index 85d61aa2b03a0699e9a647032437bd9ae48cf638..1de0955ae5b13b315635e880704d3341291e8156 100644 (file)
@@ -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<MPSerializer> MotrObject::get_serializer(const DoutPrefixProvider *dpp,
+                                                         const std::string& lock_name)
 {
-  return new MPMotrSerializer(dpp, store, this, lock_name);
+  return std::make_unique<MPMotrSerializer>(dpp, store, this, lock_name);
 }
 
 int MotrObject::transition(Bucket* bucket,
index e2684637ca24c2432d6981177b81dd95cd97b74d..c3784d2324f76e5047a60af055b0cb0de39cac04 100644 (file)
@@ -609,7 +609,7 @@ class MotrObject : public StoreObject {
     virtual std::unique_ptr<Object> clone() override {
       return std::unique_ptr<Object>(new MotrObject(*this));
     }
-    virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override;
+    virtual std::unique_ptr<MPSerializer> 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,
index 2533e210972e13af6eb2193c17d4c1212c9517f2..6d7c93c9ce14f554e86a5e5f69268b4fd1dc3e77 100644 (file)
@@ -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<MPSerializer> RadosObject::get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name)
 {
-  return new MPRadosSerializer(dpp, store, this, lock_name);
+  return std::make_unique<MPRadosSerializer>(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<LCSerializer> 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<LCRadosSerializer>(store, oid, lock_name, cookie);
 }
 
 int RadosNotification::publish_reserve(const DoutPrefixProvider *dpp, RGWObjTags* obj_tags)
index 47fcb12797f66583bfcf4c280895efc4254b7155..edf2321aac9372f0ff1ff4ca688fe66e76e0c9af 100644 (file)
@@ -418,7 +418,8 @@ class RadosObject : public StoreObject {
     virtual std::unique_ptr<Object> clone() override {
       return std::unique_ptr<Object>(new RadosObject(*this));
     }
-    virtual MPSerializer* get_serializer(const DoutPrefixProvider *dpp, const std::string& lock_name) override;
+    virtual std::unique_ptr<MPSerializer> 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<LCHead>* 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<LCSerializer> get_serializer(const std::string& lock_name,
+                                                      const std::string& oid,
+                                                      const std::string& cookie) override;
 };
 
 class RadosNotification : public StoreNotification {