Skip to content

Commit

Permalink
RGW - Zipper - make Serializer use unique_ptr
Browse files Browse the repository at this point in the history
Serializer needs to use a unique_ptr like the rest of the SAL API.

Signed-off-by: Daniel Gryniewicz <[email protected]>
  • Loading branch information
dang committed Jul 27, 2022
1 parent e439ada commit fcd7b14
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
24 changes: 9 additions & 15 deletions src/rgw/rgw_lc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -2284,8 +2282,6 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker,

exit:
lock->unlock();
notlocked:
delete lock;
return 0;
}

Expand Down Expand Up @@ -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;
Expand All @@ -2445,7 +2440,6 @@ static int guard_lc_modify(const DoutPrefixProvider *dpp,
break;
} while(true);
lock->unlock();
delete lock;
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions src/rgw/rgw_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/rgw/rgw_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -1861,12 +1861,12 @@ class RGWCompleteMultipart : public RGWOp {
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;
Expand Down
7 changes: 5 additions & 2 deletions src/rgw/rgw_sal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1350,7 +1351,9 @@ class Lifecycle {
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;
};

/**
Expand Down
11 changes: 7 additions & 4 deletions src/rgw/rgw_sal_dbstore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 5 additions & 2 deletions src/rgw/rgw_sal_dbstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class DBLifecycle : public StoreLifecycle {
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 {
Expand Down Expand Up @@ -576,7 +578,8 @@ class DBNotification : public StoreNotification {
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,
Expand Down
5 changes: 3 additions & 2 deletions src/rgw/rgw_sal_motr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_sal_motr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/rgw/rgw_sal_rados.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/rgw/rgw_sal_rados.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -704,7 +705,9 @@ class RadosLifecycle : public StoreLifecycle {
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 {
Expand Down

0 comments on commit fcd7b14

Please sign in to comment.