From a0d604f8f37d19523344d0fbd18a268cfcd5ae17 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 5 Jul 2024 16:31:07 -0400 Subject: [PATCH] rgw/sal: LCHead and LCEntry don't need abstraction Signed-off-by: Casey Bodley get dbstore to compile too --- src/rgw/driver/dbstore/common/dbstore.cc | 42 ++--- src/rgw/driver/dbstore/common/dbstore.h | 20 +-- src/rgw/driver/dbstore/sqlite/sqliteDB.cc | 22 +-- src/rgw/driver/dbstore/tests/dbstore_tests.cc | 63 ++++--- src/rgw/driver/rados/rgw_sal_rados.cc | 47 +++--- src/rgw/driver/rados/rgw_sal_rados.h | 17 +- src/rgw/rgw_admin.cc | 10 +- src/rgw/rgw_lc.cc | 156 +++++++++--------- src/rgw/rgw_lc.h | 14 +- src/rgw/rgw_sal.h | 79 +++------ src/rgw/rgw_sal_dbstore.cc | 14 +- src/rgw/rgw_sal_dbstore.h | 17 +- src/rgw/rgw_sal_filter.cc | 57 ++----- src/rgw/rgw_sal_filter.h | 45 +---- src/rgw/rgw_sal_store.h | 68 -------- 15 files changed, 246 insertions(+), 425 deletions(-) diff --git a/src/rgw/driver/dbstore/common/dbstore.cc b/src/rgw/driver/dbstore/common/dbstore.cc index d548bc4d8c0..b3aed3948c8 100644 --- a/src/rgw/driver/dbstore/common/dbstore.cc +++ b/src/rgw/driver/dbstore/common/dbstore.cc @@ -1973,7 +1973,7 @@ int DB::Object::Delete::create_dm(const DoutPrefixProvider *dpp, } int DB::get_entry(const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + rgw::sal::LCEntry& entry) { int ret = 0; const DoutPrefixProvider *dpp = get_def_dpp(); @@ -1982,7 +1982,7 @@ int DB::get_entry(const std::string& oid, const std::string& marker, InitializeParams(dpp, ¶ms); params.op.lc_entry.index = oid; - params.op.lc_entry.entry.set_bucket(marker); + params.op.lc_entry.entry.bucket = marker; params.op.query_str = "get_entry"; ret = ProcessOp(dpp, "GetLCEntry", ¶ms); @@ -1992,14 +1992,8 @@ int DB::get_entry(const std::string& oid, const std::string& marker, goto out; } - if (!params.op.lc_entry.entry.get_start_time() == 0) { //ensure entry found - rgw::sal::Lifecycle::LCEntry* e; - e = new rgw::sal::StoreLifecycle::StoreLCEntry(params.op.lc_entry.entry); - if (!e) { - ret = -ENOMEM; - goto out; - } - entry->reset(e); + if (params.op.lc_entry.entry.start_time != 0) { //ensure entry found + entry = std::move(params.op.lc_entry.entry); } out: @@ -2007,7 +2001,7 @@ out: } int DB::get_next_entry(const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + rgw::sal::LCEntry& entry) { int ret = 0; const DoutPrefixProvider *dpp = get_def_dpp(); @@ -2016,7 +2010,7 @@ int DB::get_next_entry(const std::string& oid, const std::string& marker, InitializeParams(dpp, ¶ms); params.op.lc_entry.index = oid; - params.op.lc_entry.entry.set_bucket(marker); + params.op.lc_entry.entry.bucket = marker; params.op.query_str = "get_next_entry"; ret = ProcessOp(dpp, "GetLCEntry", ¶ms); @@ -2026,21 +2020,15 @@ int DB::get_next_entry(const std::string& oid, const std::string& marker, goto out; } - if (!params.op.lc_entry.entry.get_start_time() == 0) { //ensure entry found - rgw::sal::Lifecycle::LCEntry* e; - e = new rgw::sal::StoreLifecycle::StoreLCEntry(params.op.lc_entry.entry); - if (!e) { - ret = -ENOMEM; - goto out; - } - entry->reset(e); + if (params.op.lc_entry.entry.start_time != 0) { //ensure entry found + entry = std::move(params.op.lc_entry.entry); } out: return ret; } -int DB::set_entry(const std::string& oid, rgw::sal::Lifecycle::LCEntry& entry) +int DB::set_entry(const std::string& oid, const rgw::sal::LCEntry& entry) { int ret = 0; const DoutPrefixProvider *dpp = get_def_dpp(); @@ -2063,7 +2051,7 @@ out: } int DB::list_entries(const std::string& oid, const std::string& marker, - uint32_t max_entries, std::vector>& entries) + uint32_t max_entries, std::vector& entries) { int ret = 0; const DoutPrefixProvider *dpp = get_def_dpp(); @@ -2085,14 +2073,14 @@ int DB::list_entries(const std::string& oid, const std::string& marker, } for (auto& entry : params.op.lc_entry.list_entries) { - entries.push_back(std::make_unique(std::move(entry))); + entries.push_back(std::move(entry)); } out: return ret; } -int DB::rm_entry(const std::string& oid, rgw::sal::Lifecycle::LCEntry& entry) +int DB::rm_entry(const std::string& oid, const rgw::sal::LCEntry& entry) { int ret = 0; const DoutPrefixProvider *dpp = get_def_dpp(); @@ -2114,7 +2102,7 @@ out: return ret; } -int DB::get_head(const std::string& oid, std::unique_ptr* head) +int DB::get_head(const std::string& oid, rgw::sal::LCHead& head) { int ret = 0; const DoutPrefixProvider *dpp = get_def_dpp(); @@ -2131,13 +2119,13 @@ int DB::get_head(const std::string& oid, std::unique_ptr(params.op.lc_head.head); + head = std::move(params.op.lc_head.head); out: return ret; } -int DB::put_head(const std::string& oid, rgw::sal::Lifecycle::LCHead& head) +int DB::put_head(const std::string& oid, const rgw::sal::LCHead& head) { int ret = 0; const DoutPrefixProvider *dpp = get_def_dpp(); diff --git a/src/rgw/driver/dbstore/common/dbstore.h b/src/rgw/driver/dbstore/common/dbstore.h index 3f8191f5a92..605477ef4ad 100644 --- a/src/rgw/driver/dbstore/common/dbstore.h +++ b/src/rgw/driver/dbstore/common/dbstore.h @@ -104,15 +104,15 @@ struct DBOpObjectDataInfo { struct DBOpLCHeadInfo { std::string index; - rgw::sal::StoreLifecycle::StoreLCHead head; + rgw::sal::LCHead head; }; struct DBOpLCEntryInfo { std::string index; - rgw::sal::StoreLifecycle::StoreLCEntry entry; + rgw::sal::LCEntry entry; // used for list query std::string min_marker; - std::list list_entries; + std::list list_entries; }; struct DBOpInfo { @@ -1979,15 +1979,15 @@ class DB { RGWObjState *astate, void *arg); int get_entry(const std::string& oid, const std::string& marker, - std::unique_ptr* entry); + rgw::sal::LCEntry& entry); int get_next_entry(const std::string& oid, const std::string& marker, - std::unique_ptr* entry); - int set_entry(const std::string& oid, rgw::sal::Lifecycle::LCEntry& entry); + rgw::sal::LCEntry& entry); + int set_entry(const std::string& oid, const rgw::sal::LCEntry& entry); int list_entries(const std::string& oid, const std::string& marker, - uint32_t max_entries, std::vector>& entries); - int rm_entry(const std::string& oid, rgw::sal::Lifecycle::LCEntry& entry); - int get_head(const std::string& oid, std::unique_ptr* head); - int put_head(const std::string& oid, rgw::sal::Lifecycle::LCHead& head); + uint32_t max_entries, std::vector& entries); + int rm_entry(const std::string& oid, const rgw::sal::LCEntry& entry); + int get_head(const std::string& oid, rgw::sal::LCHead& head); + int put_head(const std::string& oid, const rgw::sal::LCHead& head); int delete_stale_objs(const DoutPrefixProvider *dpp, const std::string& bucket, uint32_t min_wait); int createGC(const DoutPrefixProvider *_dpp); diff --git a/src/rgw/driver/dbstore/sqlite/sqliteDB.cc b/src/rgw/driver/dbstore/sqlite/sqliteDB.cc index 554d8fe94cf..f503d67b795 100644 --- a/src/rgw/driver/dbstore/sqlite/sqliteDB.cc +++ b/src/rgw/driver/dbstore/sqlite/sqliteDB.cc @@ -561,9 +561,9 @@ static int list_lc_entry(const DoutPrefixProvider *dpp, DBOpInfo &op, sqlite3_st return -1; op.lc_entry.index = (const char*)sqlite3_column_text(stmt, LCEntryIndex); - op.lc_entry.entry.set_bucket((const char*)sqlite3_column_text(stmt, LCEntryBucketName)); - op.lc_entry.entry.set_start_time(sqlite3_column_int(stmt, LCEntryStartTime)); - op.lc_entry.entry.set_status(sqlite3_column_int(stmt, LCEntryStatus)); + op.lc_entry.entry.bucket = (const char*)sqlite3_column_text(stmt, LCEntryBucketName); + op.lc_entry.entry.start_time = sqlite3_column_int(stmt, LCEntryStartTime); + op.lc_entry.entry.status = sqlite3_column_int(stmt, LCEntryStatus); op.lc_entry.list_entries.push_back(op.lc_entry.entry); @@ -577,10 +577,10 @@ static int list_lc_head(const DoutPrefixProvider *dpp, DBOpInfo &op, sqlite3_stm int64_t start_date; op.lc_head.index = (const char*)sqlite3_column_text(stmt, LCHeadIndex); - op.lc_head.head.set_marker((const char*)sqlite3_column_text(stmt, LCHeadMarker)); + op.lc_head.head.marker = (const char*)sqlite3_column_text(stmt, LCHeadMarker); SQL_DECODE_BLOB_PARAM(dpp, stmt, LCHeadStartDate, start_date, sdb); - op.lc_head.head.get_start_date() = start_date; + op.lc_head.head.start_date = start_date; return 0; } @@ -2692,13 +2692,13 @@ int SQLInsertLCEntry::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *par SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.index.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.bucket_name, sdb); - SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.entry.get_bucket().c_str(), sdb); + SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.entry.bucket.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.status, sdb); - SQL_BIND_INT(dpp, stmt, index, params->op.lc_entry.entry.get_status(), sdb); + SQL_BIND_INT(dpp, stmt, index, params->op.lc_entry.entry.status, sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.start_time, sdb); - SQL_BIND_INT(dpp, stmt, index, params->op.lc_entry.entry.get_start_time(), sdb); + SQL_BIND_INT(dpp, stmt, index, params->op.lc_entry.entry.start_time, sdb); out: return rc; @@ -2741,7 +2741,7 @@ int SQLRemoveLCEntry::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *par SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.index.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_entry.bucket_name, sdb); - SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.entry.get_bucket().c_str(), sdb); + SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_entry.entry.bucket.c_str(), sdb); out: return rc; @@ -2796,7 +2796,7 @@ int SQLGetLCEntry::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *params SQL_BIND_TEXT(dpp, *pstmt, index, params->op.lc_entry.index.c_str(), sdb); SQL_BIND_INDEX(dpp, *pstmt, index, p_params.op.lc_entry.bucket_name, sdb); - SQL_BIND_TEXT(dpp, *pstmt, index, params->op.lc_entry.entry.get_bucket().c_str(), sdb); + SQL_BIND_TEXT(dpp, *pstmt, index, params->op.lc_entry.entry.bucket.c_str(), sdb); out: return rc; @@ -2892,7 +2892,7 @@ int SQLInsertLCHead::Bind(const DoutPrefixProvider *dpp, struct DBOpParams *para SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_head.index.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_head.marker, sdb); - SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_head.head.get_marker().c_str(), sdb); + SQL_BIND_TEXT(dpp, stmt, index, params->op.lc_head.head.marker.c_str(), sdb); SQL_BIND_INDEX(dpp, stmt, index, p_params.op.lc_head.start_date, sdb); SQL_ENCODE_BLOB_PARAM(dpp, stmt, index, static_cast(params->op.lc_head.head.start_date), sdb); diff --git a/src/rgw/driver/dbstore/tests/dbstore_tests.cc b/src/rgw/driver/dbstore/tests/dbstore_tests.cc index c89addeade1..2ceed7218d8 100644 --- a/src/rgw/driver/dbstore/tests/dbstore_tests.cc +++ b/src/rgw/driver/dbstore/tests/dbstore_tests.cc @@ -1255,31 +1255,30 @@ TEST_F(DBStoreTest, LCHead) { std::string index1 = "bucket1"; std::string index2 = "bucket2"; time_t lc_time = ceph_clock_now(); - std::unique_ptr head; - std::string ents[] = {"entry1", "entry2", "entry3"}; - rgw::sal::StoreLifecycle::StoreLCHead head1(lc_time, 0, ents[0]); - rgw::sal::StoreLifecycle::StoreLCHead head2(lc_time, 0, ents[1]); - rgw::sal::StoreLifecycle::StoreLCHead head3(lc_time, 0, ents[2]); + rgw::sal::LCHead head; + rgw::sal::LCHead head1{lc_time, "entry1"}; + rgw::sal::LCHead head2{lc_time, "entry2"}; + rgw::sal::LCHead head3{lc_time, "entry3"}; ret = db->put_head(index1, head1); ASSERT_EQ(ret, 0); ret = db->put_head(index2, head2); ASSERT_EQ(ret, 0); - ret = db->get_head(index1, &head); + ret = db->get_head(index1, head); ASSERT_EQ(ret, 0); - ASSERT_EQ(head->get_marker(), "entry1"); + ASSERT_EQ(head.marker, "entry1"); - ret = db->get_head(index2, &head); + ret = db->get_head(index2, head); ASSERT_EQ(ret, 0); - ASSERT_EQ(head->get_marker(), "entry2"); + ASSERT_EQ(head.marker, "entry2"); // update index1 ret = db->put_head(index1, head3); ASSERT_EQ(ret, 0); - ret = db->get_head(index1, &head); + ret = db->get_head(index1, head); ASSERT_EQ(ret, 0); - ASSERT_EQ(head->get_marker(), "entry3"); + ASSERT_EQ(head.marker, "entry3"); } TEST_F(DBStoreTest, LCEntry) { @@ -1290,13 +1289,13 @@ TEST_F(DBStoreTest, LCEntry) { std::string index2 = "lcindex2"; typedef enum {lc_uninitial = 1, lc_complete} status; std::string ents[] = {"bucket1", "bucket2", "bucket3", "bucket4"}; - std::unique_ptr entry; - rgw::sal::StoreLifecycle::StoreLCEntry entry1(ents[0], lc_time, lc_uninitial); - rgw::sal::StoreLifecycle::StoreLCEntry entry2(ents[1], lc_time, lc_uninitial); - rgw::sal::StoreLifecycle::StoreLCEntry entry3(ents[2], lc_time, lc_uninitial); - rgw::sal::StoreLifecycle::StoreLCEntry entry4(ents[3], lc_time, lc_uninitial); + rgw::sal::LCEntry entry; + rgw::sal::LCEntry entry1{ents[0], lc_time, lc_uninitial}; + rgw::sal::LCEntry entry2{ents[1], lc_time, lc_uninitial}; + rgw::sal::LCEntry entry3{ents[2], lc_time, lc_uninitial}; + rgw::sal::LCEntry entry4{ents[3], lc_time, lc_uninitial}; - vector> lc_entries; + vector lc_entries; ret = db->set_entry(index1, entry1); ASSERT_EQ(ret, 0); @@ -1308,44 +1307,44 @@ TEST_F(DBStoreTest, LCEntry) { ASSERT_EQ(ret, 0); // get entry index1, entry1 - ret = db->get_entry(index1, ents[0], &entry); + ret = db->get_entry(index1, ents[0], entry); ASSERT_EQ(ret, 0); - ASSERT_EQ(entry->get_status(), lc_uninitial); - ASSERT_EQ(entry->get_start_time(), lc_time); + ASSERT_EQ(entry.status, lc_uninitial); + ASSERT_EQ(entry.start_time, lc_time); // get next entry index1, entry2 - ret = db->get_next_entry(index1, ents[1], &entry); + ret = db->get_next_entry(index1, ents[1], entry); ASSERT_EQ(ret, 0); - ASSERT_EQ(entry->get_bucket(), ents[2]); - ASSERT_EQ(entry->get_status(), lc_uninitial); - ASSERT_EQ(entry->get_start_time(), lc_time); + ASSERT_EQ(entry.bucket, ents[2]); + ASSERT_EQ(entry.status, lc_uninitial); + ASSERT_EQ(entry.start_time, lc_time); // update entry4 to entry5 entry4.status = lc_complete; ret = db->set_entry(index2, entry4); ASSERT_EQ(ret, 0); - ret = db->get_entry(index2, ents[3], &entry); + ret = db->get_entry(index2, ents[3], entry); ASSERT_EQ(ret, 0); - ASSERT_EQ(entry->get_status(), lc_complete); + ASSERT_EQ(entry.status, lc_complete); // list entries ret = db->list_entries(index1, "", 5, lc_entries); ASSERT_EQ(ret, 0); for (const auto& ent: lc_entries) { cout << "###################### \n"; - cout << "lc entry.bucket : " << ent->get_bucket() << "\n"; - cout << "lc entry.status : " << ent->get_status() << "\n"; + cout << "lc entry.bucket : " << ent.bucket << "\n"; + cout << "lc entry.status : " << ent.status << "\n"; } // remove index1, entry3 ret = db->rm_entry(index1, entry3); ASSERT_EQ(ret, 0); - // get next entry index1, entry2.. should be null - entry.release(); - ret = db->get_next_entry(index1, ents[1], &entry); + // get next entry index1, entry2.. should be empty + entry = rgw::sal::LCEntry{}; + ret = db->get_next_entry(index1, ents[1], entry); ASSERT_EQ(ret, 0); - ASSERT_EQ(entry.get(), nullptr); + ASSERT_TRUE(entry.bucket.empty()); } TEST_F(DBStoreTest, RemoveBucket) { diff --git a/src/rgw/driver/rados/rgw_sal_rados.cc b/src/rgw/driver/rados/rgw_sal_rados.cc index 50c738d5435..4ee5482e435 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.cc +++ b/src/rgw/driver/rados/rgw_sal_rados.cc @@ -3614,7 +3614,7 @@ int LCRadosSerializer::try_lock(const DoutPrefixProvider *dpp, utime_t dur, opti int RadosLifecycle::get_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + LCEntry& entry) { librados::ObjectReadOperation op; bufferlist bl; @@ -3632,13 +3632,15 @@ int RadosLifecycle::get_entry(const DoutPrefixProvider* dpp, optional_yield y, return ret; } - *entry = std::make_unique(cls_entry.bucket, cls_entry.start_time, cls_entry.status); + entry.bucket = std::move(cls_entry.bucket); + entry.start_time = cls_entry.start_time; + entry.status = cls_entry.status; return 0; } int RadosLifecycle::get_next_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + LCEntry& entry) { librados::ObjectReadOperation op; bufferlist bl; @@ -3656,18 +3658,20 @@ int RadosLifecycle::get_next_entry(const DoutPrefixProvider* dpp, optional_yield return ret; } - *entry = std::make_unique(cls_entry.bucket, cls_entry.start_time, cls_entry.status); + entry.bucket = std::move(cls_entry.bucket); + entry.start_time = cls_entry.start_time; + entry.status = cls_entry.status; return 0; } int RadosLifecycle::set_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) + const std::string& oid, const LCEntry& entry) { cls_rgw_lc_entry cls_entry; - cls_entry.bucket = entry.get_bucket(); - cls_entry.start_time = entry.get_start_time(); - cls_entry.status = entry.get_status(); + cls_entry.bucket = entry.bucket; + cls_entry.start_time = entry.start_time; + cls_entry.status = entry.status; librados::ObjectWriteOperation op; cls_rgw_lc_set_entry(op, cls_entry); @@ -3678,7 +3682,7 @@ int RadosLifecycle::set_entry(const DoutPrefixProvider* dpp, optional_yield y, int RadosLifecycle::list_entries(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - uint32_t max_entries, std::vector>& entries) + uint32_t max_entries, std::vector& entries) { entries.clear(); @@ -3699,20 +3703,19 @@ int RadosLifecycle::list_entries(const DoutPrefixProvider* dpp, optional_yield y } for (auto& entry : cls_entries) { - entries.push_back(std::make_unique(entry.bucket, oid, - entry.start_time, entry.status)); + entries.push_back(LCEntry{entry.bucket, entry.start_time, entry.status}); } return ret; } int RadosLifecycle::rm_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) + const std::string& oid, const LCEntry& entry) { cls_rgw_lc_entry cls_entry; - cls_entry.bucket = entry.get_bucket(); - cls_entry.start_time = entry.get_start_time(); - cls_entry.status = entry.get_status(); + cls_entry.bucket = entry.bucket; + cls_entry.start_time = entry.start_time; + cls_entry.status = entry.status; librados::ObjectWriteOperation op; cls_rgw_lc_rm_entry(op, cls_entry); @@ -3722,7 +3725,7 @@ int RadosLifecycle::rm_entry(const DoutPrefixProvider* dpp, optional_yield y, } int RadosLifecycle::get_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, std::unique_ptr* head) + const std::string& oid, LCHead& head) { librados::ObjectReadOperation op; bufferlist bl; @@ -3740,18 +3743,20 @@ int RadosLifecycle::get_head(const DoutPrefixProvider* dpp, optional_yield y, return ret; } - *head = std::make_unique(cls_head.start_date, cls_head.shard_rollover_date, cls_head.marker); + head.start_date = cls_head.start_date; + head.shard_rollover_date = cls_head.shard_rollover_date; + head.marker = std::move(cls_head.marker); return 0; } int RadosLifecycle::put_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCHead& head) + const std::string& oid, const LCHead& head) { cls_rgw_lc_obj_head cls_head; - cls_head.marker = head.get_marker(); - cls_head.start_date = head.get_start_date(); - cls_head.shard_rollover_date = head.get_shard_rollover_date(); + cls_head.marker = head.marker; + cls_head.start_date = head.start_date; + cls_head.shard_rollover_date = head.shard_rollover_date; librados::ObjectWriteOperation op; cls_rgw_lc_put_head(op, cls_head); diff --git a/src/rgw/driver/rados/rgw_sal_rados.h b/src/rgw/driver/rados/rgw_sal_rados.h index 98d0bc9d005..6b944269cc4 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.h +++ b/src/rgw/driver/rados/rgw_sal_rados.h @@ -868,31 +868,30 @@ public: } }; -class RadosLifecycle : public StoreLifecycle { +class RadosLifecycle : public Lifecycle { RadosStore* store; public: RadosLifecycle(RadosStore* _st) : store(_st) {} - using StoreLifecycle::get_entry; virtual int get_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) override; + LCEntry& entry) override; virtual int get_next_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) override; + LCEntry& entry) override; virtual int set_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) override; + const std::string& oid, const LCEntry& entry) override; virtual int list_entries(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, uint32_t max_entries, - std::vector>& entries) override; + std::vector& entries) override; virtual int rm_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) override; + const std::string& oid, const LCEntry& entry) override; virtual int get_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, std::unique_ptr* head) override; - virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, LCHead& head) override; + virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y, + const std::string& oid, const LCHead& head) override; virtual std::unique_ptr get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) override; diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 7397055db2a..74402bc4e73 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -8818,7 +8818,7 @@ next: if (opt_cmd == OPT::LC_LIST) { formatter->open_array_section("lifecycle_list"); - vector> bucket_lc_map; + vector bucket_lc_map; string marker; int index{0}; #define MAX_LC_LIST_ENTRIES 100 @@ -8835,17 +8835,15 @@ next: } for (const auto& entry : bucket_lc_map) { formatter->open_object_section("bucket_lc_info"); - formatter->dump_string("bucket", entry->get_bucket()); - formatter->dump_string("shard", entry->get_oid()); + formatter->dump_string("bucket", entry.bucket); char exp_buf[100]; - time_t t{time_t(entry->get_start_time())}; + time_t t = entry.start_time; if (std::strftime( exp_buf, sizeof(exp_buf), "%a, %d %b %Y %T %Z", std::gmtime(&t))) { formatter->dump_string("started", exp_buf); } - string lc_status = LC_STATUS[entry->get_status()]; - formatter->dump_string("status", lc_status); + formatter->dump_string("status", LC_STATUS[entry.status]); formatter->close_section(); // objs formatter->flush(cout); } diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index fb3002b0a38..0c80ad1b765 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -258,13 +258,13 @@ void RGWLC::finalize() delete[] obj_names; } -static inline std::ostream& operator<<(std::ostream &os, rgw::sal::Lifecycle::LCEntry& ent) { +static inline std::ostream& operator<<(std::ostream &os, rgw::sal::LCEntry& ent) { os << ""; return os; } @@ -1834,7 +1834,7 @@ public: }; int RGWLC::bucket_lc_post(int index, int max_lock_sec, - rgw::sal::Lifecycle::LCEntry& entry, int& result, + rgw::sal::LCEntry& entry, int& result, LCWorker* worker) { utime_t lock_duration(cct->_conf->rgw_lc_lock_max_time, 0); @@ -1872,9 +1872,9 @@ int RGWLC::bucket_lc_post(int index, int max_lock_sec, } goto clean; } else if (result < 0) { - entry.set_status(lc_failed); + entry.status = lc_failed; } else { - entry.set_status(lc_complete); + entry.status = lc_complete; } ret = sal_lc->set_entry(this, null_yield, obj_names[index], entry); @@ -1891,12 +1891,12 @@ clean: } /* RGWLC::bucket_lc_post */ int RGWLC::list_lc_progress(string& marker, uint32_t max_entries, - vector>& progress_map, + vector& progress_map, int& index) { progress_map.clear(); for(; index < max_objs; index++, marker="") { - vector> entries; + vector entries; int ret = sal_lc->list_entries(this, null_yield, obj_names[index], marker, max_entries, entries); if (ret < 0) { @@ -1914,7 +1914,7 @@ int RGWLC::list_lc_progress(string& marker, uint32_t max_entries, /* update index, marker tuple */ if (progress_map.size() > 0) - marker = progress_map.back()->get_bucket(); + marker = progress_map.back().bucket; if (progress_map.size() >= max_entries) break; @@ -2034,7 +2034,6 @@ int RGWLC::process_bucket(int index, int max_lock_secs, LCWorker* worker, std::unique_ptr serializer = sal_lc->get_serializer(lc_index_lock_name, obj_names[index], worker->thr_name()); - std::unique_ptr entry; if (max_lock_secs <= 0) { return -EAGAIN; } @@ -2053,11 +2052,12 @@ int RGWLC::process_bucket(int index, int max_lock_secs, LCWorker* worker, std::unique_lock lock( *(serializer.get()), std::adopt_lock); + rgw::sal::LCEntry entry; ret = sal_lc->get_entry(this, null_yield, obj_names[index], - bucket_entry_marker, &entry); + bucket_entry_marker, entry); if (ret >= 0) { - if (entry->get_status() == lc_processing) { - if (expired_session(entry->get_start_time())) { + if (entry.status == lc_processing) { + if (expired_session(entry.start_time)) { ldpp_dout(this, 5) << "RGWLC::process_bucket(): STALE lc session found for: " << entry << " index: " << index << " worker ix: " << worker->ix << " (clearing)" @@ -2074,7 +2074,7 @@ int RGWLC::process_bucket(int index, int max_lock_secs, LCWorker* worker, } /* do nothing if no bucket */ - if ((! entry) || entry->get_bucket().empty()) { + if ((ret < 0) || entry.bucket.empty()) { return ret; } @@ -2082,11 +2082,11 @@ int RGWLC::process_bucket(int index, int max_lock_secs, LCWorker* worker, << " index: " << index << " worker ix: " << worker->ix << dendl; - entry->set_status(lc_processing); - ret = sal_lc->set_entry(this, null_yield, obj_names[index], *entry); + entry.status = lc_processing; + ret = sal_lc->set_entry(this, null_yield, obj_names[index], entry); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process_bucket() failed to set obj entry " - << obj_names[index] << entry->get_bucket() << entry->get_status() + << obj_names[index] << entry.bucket << entry.status << dendl; return ret; } @@ -2096,10 +2096,10 @@ int RGWLC::process_bucket(int index, int max_lock_secs, LCWorker* worker, << dendl; lock.unlock(); - ret = bucket_lc_process(entry->get_bucket(), worker, thread_stop_at(), once); + ret = bucket_lc_process(entry.bucket, worker, thread_stop_at(), once); ldpp_dout(this, 5) << "RGWLC::process_bucket(): END entry 2: " << entry << " index: " << index << " worker ix: " << worker->ix << " ret: " << ret << dendl; - bucket_lc_post(index, max_lock_secs, *entry, ret, worker); + bucket_lc_post(index, max_lock_secs, entry, ret, worker); return ret; } /* RGWLC::process_bucket */ @@ -2144,15 +2144,15 @@ static inline bool already_run_today(CephContext* cct, time_t start_date) } /* already_run_today */ inline int RGWLC::advance_head(const std::string& lc_shard, - rgw::sal::Lifecycle::LCHead& head, - rgw::sal::Lifecycle::LCEntry& entry, + rgw::sal::LCHead& head, + const rgw::sal::LCEntry& entry, time_t start_date) { int ret{0}; - std::unique_ptr next_entry; + rgw::sal::LCEntry next_entry; ret = sal_lc->get_next_entry(this, null_yield, lc_shard, - entry.get_bucket(), &next_entry); + entry.bucket, next_entry); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() failed to get obj entry " << lc_shard << dendl; @@ -2160,8 +2160,8 @@ inline int RGWLC::advance_head(const std::string& lc_shard, } /* save the next position */ - head.set_marker(next_entry->get_bucket()); - head.set_start_date(start_date); + head.marker = next_entry.bucket; + head.start_date = start_date; ret = sal_lc->put_head(this, null_yield, lc_shard, head); if (ret < 0) { @@ -2175,17 +2175,17 @@ exit: } /* advance head */ inline int RGWLC::check_if_shard_done(const std::string& lc_shard, - rgw::sal::Lifecycle::LCHead& head, int worker_ix) + rgw::sal::LCHead& head, int worker_ix) { int ret{0}; - if (head.get_marker().empty()) { + if (head.marker.empty()) { /* done with this shard */ ldpp_dout(this, 5) << "RGWLC::process() next_entry not found. cycle finished lc_shard=" << lc_shard << " worker=" << worker_ix << dendl; - head.set_shard_rollover_date(ceph_clock_now()); + head.shard_rollover_date = ceph_clock_now(); ret = sal_lc->put_head(this, null_yield, lc_shard, head); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() failed to put head " @@ -2198,8 +2198,8 @@ inline int RGWLC::check_if_shard_done(const std::string& lc_shard, } inline int RGWLC::update_head(const std::string& lc_shard, - rgw::sal::Lifecycle::LCHead& head, - rgw::sal::Lifecycle::LCEntry& entry, + rgw::sal::LCHead& head, + rgw::sal::LCEntry& entry, time_t start_date, int worker_ix) { int ret{0}; @@ -2229,8 +2229,8 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, int ret{0}; const auto& lc_shard = obj_names[index]; - std::unique_ptr head; - std::unique_ptr entry; //string = bucket_name:bucket_id, start_time, int = LC_BUCKET_STATUS + rgw::sal::LCHead head; + rgw::sal::LCEntry entry; //string = bucket_name:bucket_id, start_time, int = LC_BUCKET_STATUS ldpp_dout(this, 5) << "RGWLC::process(): ENTER: " << "index: " << index << " worker ix: " << worker->ix @@ -2264,7 +2264,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, utime_t now = ceph_clock_now(); /* preamble: find an inital bucket/marker */ - ret = sal_lc->get_head(this, null_yield, lc_shard, &head); + ret = sal_lc->get_head(this, null_yield, lc_shard, head); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() failed to get obj head " << lc_shard << ", ret=" << ret << dendl; @@ -2273,18 +2273,18 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, /* if there is nothing at head, try to reinitialize head.marker with the * first entry in the queue */ - if (head->get_marker().empty() && - allow_shard_rollover(cct, now, head->get_shard_rollover_date()) /* prevent multiple passes by diff. + if (head.marker.empty() && + allow_shard_rollover(cct, now, head.shard_rollover_date) /* prevent multiple passes by diff. * rgws,in same cycle */) { ldpp_dout(this, 5) << "RGWLC::process() process shard rollover lc_shard=" << lc_shard - << " head.marker=" << head->get_marker() - << " head.shard_rollover_date=" << head->get_shard_rollover_date() + << " head.marker=" << head.marker + << " head.shard_rollover_date=" << head.shard_rollover_date << dendl; - vector> entries; + vector entries; int ret = sal_lc->list_entries(this, null_yield, lc_shard, - head->get_marker(), 1, entries); + head.marker, 1, entries); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() sal_lc->list_entries(lc_shard, head.marker, 1, " << "entries) returned error ret==" << ret << dendl; @@ -2292,27 +2292,27 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, } if (entries.size() > 0) { entry = std::move(entries.front()); - head->set_marker(entry->get_bucket()); - head->set_start_date(now); - head->set_shard_rollover_date(0); + head.marker = entry.bucket; + head.start_date= now; + head.shard_rollover_date = 0; } } else { ldpp_dout(this, 0) << "RGWLC::process() head.marker !empty() at START for shard==" << lc_shard << " head last stored at " - << rgw_to_asctime(utime_t(time_t(head->get_start_date()), 0)) + << rgw_to_asctime(utime_t(head.start_date, 0)) << dendl; /* fetches the entry pointed to by head.bucket */ ret = sal_lc->get_entry(this, null_yield, lc_shard, - head->get_marker(), &entry); + head.marker, entry); if (ret == -ENOENT) { /* skip to next entry */ - std::unique_ptr tmp_entry = sal_lc->get_entry(); - tmp_entry->set_bucket(head->get_marker()); + rgw::sal::LCEntry tmp_entry; + tmp_entry.bucket = head.marker; - if (update_head(lc_shard, *head.get(), *tmp_entry.get(), now, worker->ix) != 0) { - goto exit; - } + if (update_head(lc_shard, head, tmp_entry, now, worker->ix) != 0) { + goto exit; + } continue; } if (ret < 0) { @@ -2322,9 +2322,9 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, } } - if (entry && !entry->get_bucket().empty()) { - if (entry->get_status() == lc_processing) { - if (expired_session(entry->get_start_time())) { + if (!entry.bucket.empty()) { + if (entry.status == lc_processing) { + if (expired_session(entry.start_time)) { ldpp_dout(this, 5) << "RGWLC::process(): STALE lc session found for: " << entry << " index: " << index << " worker ix: " << worker->ix @@ -2334,19 +2334,19 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, << "RGWLC::process(): ACTIVE entry: " << entry << " index: " << index << " worker ix: " << worker->ix << dendl; /* skip to next entry */ - if (update_head(lc_shard, *head.get(), *entry.get(), now, worker->ix) != 0) { + if (update_head(lc_shard, head, entry, now, worker->ix) != 0) { goto exit; } continue; } } else { - if ((entry->get_status() == lc_complete) && - already_run_today(cct, entry->get_start_time())) { + if ((entry.status == lc_complete) && + already_run_today(cct, entry.start_time)) { ldpp_dout(this, 5) << "RGWLC::process() worker ix: " << worker->ix - << " SKIP processing for already-processed bucket " << entry->get_bucket() + << " SKIP processing for already-processed bucket " << entry.bucket << dendl; /* skip to next entry */ - if (update_head(lc_shard, *head.get(), *entry.get(), now, worker->ix) != 0) { + if (update_head(lc_shard, head, entry, now, worker->ix) != 0) { goto exit; } continue; @@ -2368,18 +2368,18 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, << " index: " << index << " worker ix: " << worker->ix << dendl; - entry->set_status(lc_processing); - entry->set_start_time(now); + entry.status = lc_processing; + entry.start_time = now; - ret = sal_lc->set_entry(this, null_yield, lc_shard, *entry); + ret = sal_lc->set_entry(this, null_yield, lc_shard, entry); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() failed to set obj entry " - << lc_shard << entry->get_bucket() << entry->get_status() << dendl; + << lc_shard << entry.bucket << entry.status << dendl; goto exit; } /* advance head for next waiter, then process */ - if (advance_head(lc_shard, *head.get(), *entry.get(), now) < 0) { + if (advance_head(lc_shard, head, entry, now) < 0) { goto exit; } @@ -2390,7 +2390,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, /* drop lock so other instances can make progress while this * bucket is being processed */ lock->unlock(); - ret = bucket_lc_process(entry->get_bucket(), worker, thread_stop_at(), once); + ret = bucket_lc_process(entry.bucket, worker, thread_stop_at(), once); ldpp_dout(this, 5) << "RGWLC::process(): END entry 2: " << entry << " index: " << index << " worker ix: " << worker->ix << " ret: " << ret << dendl; @@ -2407,7 +2407,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, /* XXXX are we SURE the only way result could == ENOENT is when * there is no such bucket? It is currently the value returned * from bucket_lc_process(...) */ - ret = sal_lc->rm_entry(this, null_yield, lc_shard, *entry); + ret = sal_lc->rm_entry(this, null_yield, lc_shard, entry); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() failed to remove entry " << lc_shard << " (nonfatal)" @@ -2416,11 +2416,11 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, } } else { if (ret < 0) { - entry->set_status(lc_failed); + entry.status = lc_failed; } else { - entry->set_status(lc_complete); + entry.status = lc_complete; } - ret = sal_lc->set_entry(this, null_yield, lc_shard, *entry); + ret = sal_lc->set_entry(this, null_yield, lc_shard, entry); if (ret < 0) { ldpp_dout(this, 0) << "RGWLC::process() failed to set entry on lc_shard=" << lc_shard << " entry=" << entry @@ -2430,7 +2430,7 @@ int RGWLC::process(int index, int max_lock_secs, LCWorker* worker, } } - if (check_if_shard_done(lc_shard, *head.get(), worker->ix) != 0 ) { + if (check_if_shard_done(lc_shard, head, worker->ix) != 0 ) { goto exit; } } while(1 && !once && !going_down()); @@ -2569,9 +2569,9 @@ static int guard_lc_modify(const DoutPrefixProvider *dpp, get_lc_oid(cct, bucket_lc_key, &oid); /* XXX it makes sense to take shard_id for a bucket_id? */ - std::unique_ptr entry = sal_lc->get_entry(); - entry->set_bucket(bucket_lc_key); - entry->set_status(lc_uninitial); + rgw::sal::LCEntry entry; + entry.bucket = bucket_lc_key; + entry.status = lc_uninitial; int max_lock_secs = cct->_conf->rgw_lc_lock_max_time; std::unique_ptr lock = @@ -2598,7 +2598,7 @@ static int guard_lc_modify(const DoutPrefixProvider *dpp, << oid << ", ret=" << ret << dendl; break; } - ret = f(sal_lc, oid, *entry.get()); + ret = f(sal_lc, oid, entry); if (ret < 0) { ldpp_dout(dpp, 0) << "RGWLC::RGWPutLC() failed to set entry on " << oid << ", ret=" << ret << dendl; @@ -2634,7 +2634,7 @@ int RGWLC::set_bucket_config(const DoutPrefixProvider* dpp, optional_yield y, ret = guard_lc_modify(dpp, driver, sal_lc.get(), b, cookie, [&](rgw::sal::Lifecycle* sal_lc, const string& oid, - rgw::sal::Lifecycle::LCEntry& entry) { + rgw::sal::LCEntry& entry) { return sal_lc->set_entry(dpp, y, oid, entry); }); @@ -2663,7 +2663,7 @@ int RGWLC::remove_bucket_config(const DoutPrefixProvider* dpp, optional_yield y, ret = guard_lc_modify(dpp, driver, sal_lc.get(), b, cookie, [&](rgw::sal::Lifecycle* sal_lc, const string& oid, - rgw::sal::Lifecycle::LCEntry& entry) { + rgw::sal::LCEntry& entry) { return sal_lc->rm_entry(dpp, y, oid, entry); }); @@ -2692,13 +2692,13 @@ int fix_lc_shard_entry(const DoutPrefixProvider *dpp, std::string lc_oid; get_lc_oid(driver->ctx(), bucket_lc_key, &lc_oid); - std::unique_ptr entry; + rgw::sal::LCEntry entry; // There are multiple cases we need to encounter here // 1. entry exists and is already set to marker, happens in plain buckets & newly resharded buckets // 2. entry doesn't exist, which usually happens when reshard has happened prior to update and next LC process has already dropped the update // 3. entry exists matching the current bucket id which was after a reshard (needs to be updated to the marker) // We are not dropping the old marker here as that would be caught by the next LC process update - int ret = sal_lc->get_entry(dpp, null_yield, lc_oid, bucket_lc_key, &entry); + int ret = sal_lc->get_entry(dpp, null_yield, lc_oid, bucket_lc_key, entry); if (ret == 0) { ldpp_dout(dpp, 5) << "Entry already exists, nothing to do" << dendl; return ret; // entry is already existing correctly set to marker @@ -2716,7 +2716,7 @@ int fix_lc_shard_entry(const DoutPrefixProvider *dpp, driver, sal_lc, bucket->get_key(), cookie, [dpp, &lc_oid](rgw::sal::Lifecycle* slc, const string& oid, - rgw::sal::Lifecycle::LCEntry& entry) { + rgw::sal::LCEntry& entry) { return slc->set_entry(dpp, null_yield, lc_oid, entry); }); diff --git a/src/rgw/rgw_lc.h b/src/rgw/rgw_lc.h index d53e14cee65..b4c6ad4a86b 100644 --- a/src/rgw/rgw_lc.h +++ b/src/rgw/rgw_lc.h @@ -628,15 +628,15 @@ public: const std::unique_ptr& optional_bucket, bool once); int advance_head(const std::string& lc_shard, - rgw::sal::Lifecycle::LCHead& head, - rgw::sal::Lifecycle::LCEntry& entry, + rgw::sal::LCHead& head, + const rgw::sal::LCEntry& entry, time_t start_date); int check_if_shard_done(const std::string& lc_shard, - rgw::sal::Lifecycle::LCHead& head, + rgw::sal::LCHead& head, int worker_ix); int update_head(const std::string& lc_shard, - rgw::sal::Lifecycle::LCHead& head, - rgw::sal::Lifecycle::LCEntry& entry, + rgw::sal::LCHead& head, + rgw::sal::LCEntry& entry, time_t start_date, int worker_ix); int process(int index, int max_lock_secs, LCWorker* worker, bool once); int process_bucket(int index, int max_lock_secs, LCWorker* worker, @@ -644,12 +644,12 @@ public: bool expired_session(time_t started); time_t thread_stop_at(); int list_lc_progress(std::string& marker, uint32_t max_entries, - std::vector>&, + std::vector&, int& index); int bucket_lc_process(std::string& shard_id, LCWorker* worker, time_t stop_at, bool once); int bucket_lc_post(int index, int max_lock_sec, - rgw::sal::Lifecycle::LCEntry& entry, int& result, LCWorker* worker); + rgw::sal::LCEntry& entry, int& result, LCWorker* worker); bool going_down(); void start_processor(); void stop_processor(); diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index 8ddfb7f7c7d..92f55cd3bb5 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -1491,6 +1491,21 @@ public: virtual ~LCSerializer() = default; }; +/** Head of a lifecycle run. Used for tracking parallel lifecycle runs. */ +struct LCHead { + time_t start_date = 0; + std::string marker; + time_t shard_rollover_date = 0; +}; + +/** Single entry in a lifecycle run. Multiple entries can exist processing different + * buckets. */ +struct LCEntry { + std::string bucket; + uint64_t start_time = 0; + uint32_t status = 0; +}; + /** * @brief Abstraction for lifecycle processing * @@ -1500,84 +1515,34 @@ public: */ class Lifecycle { public: - /** Head of a lifecycle run. Used for tracking parallel lifecycle runs. */ - struct LCHead { - LCHead() = default; - virtual ~LCHead() = default; - - virtual time_t& get_start_date() = 0; - virtual void set_start_date(time_t) = 0; - virtual std::string& get_marker() = 0; - virtual void set_marker(const std::string&) = 0; - virtual time_t& get_shard_rollover_date() = 0; - virtual void set_shard_rollover_date(time_t) = 0; - }; - - /** Single entry in a lifecycle run. Multiple entries can exist processing different - * buckets. */ - struct LCEntry { - LCEntry() = default; - virtual ~LCEntry() = default; - - virtual std::string& get_bucket() = 0; - virtual void set_bucket(const std::string&) = 0; - virtual std::string& get_oid() = 0; - virtual void set_oid(const std::string&) = 0; - virtual uint64_t get_start_time() = 0; - virtual void set_start_time(uint64_t) = 0; - virtual uint32_t get_status() = 0; - virtual void set_status(uint32_t) = 0; - - /** Print the entry to @a out */ - virtual void print(std::ostream& out) const = 0; - - friend inline std::ostream& operator<<(std::ostream& out, const LCEntry& e) { - e.print(out); - return out; - } - friend inline std::ostream& operator<<(std::ostream& out, const LCEntry* e) { - if (!e) - out << ""; - else - e->print(out); - return out; - } - friend inline std::ostream& operator<<(std::ostream& out, const std::unique_ptr& p) { - out << p.get(); - return out; - } - }; - Lifecycle() = default; virtual ~Lifecycle() = default; - /** Get an empty entry */ - virtual std::unique_ptr get_entry() = 0; /** Get an entry matching the given marker */ virtual int get_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) = 0; + LCEntry& entry) = 0; /** Get the entry following the given marker */ virtual int get_next_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) = 0; + LCEntry& entry) = 0; /** Store a modified entry in then backing store */ virtual int set_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) = 0; + const std::string& oid, const LCEntry& entry) = 0; /** List all known entries */ virtual int list_entries(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, uint32_t max_entries, - std::vector>& entries) = 0; + std::vector& entries) = 0; /** Remove an entry from the backing store */ virtual int rm_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) = 0; + const std::string& oid, const LCEntry& entry) = 0; /** Get a head */ virtual int get_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, std::unique_ptr* head) = 0; + const std::string& oid, LCHead& head) = 0; /** Store a modified head to the backing store */ virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCHead& head) = 0; + const std::string& oid, const LCHead& head) = 0; /** Get a serializer for lifecycle */ virtual std::unique_ptr get_serializer(const std::string& lock_name, diff --git a/src/rgw/rgw_sal_dbstore.cc b/src/rgw/rgw_sal_dbstore.cc index 51627914db2..44b95128100 100644 --- a/src/rgw/rgw_sal_dbstore.cc +++ b/src/rgw/rgw_sal_dbstore.cc @@ -1840,45 +1840,45 @@ namespace rgw::sal { int DBLifecycle::get_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + LCEntry& entry) { return store->getDB()->get_entry(oid, marker, entry); } int DBLifecycle::get_next_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + LCEntry& entry) { return store->getDB()->get_next_entry(oid, marker, entry); } int DBLifecycle::set_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) + const std::string& oid, const LCEntry& entry) { return store->getDB()->set_entry(oid, entry); } int DBLifecycle::list_entries(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - uint32_t max_entries, vector>& entries) + uint32_t max_entries, vector& entries) { return store->getDB()->list_entries(oid, marker, max_entries, entries); } int DBLifecycle::rm_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) + const std::string& oid, const LCEntry& entry) { return store->getDB()->rm_entry(oid, entry); } int DBLifecycle::get_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, std::unique_ptr* head) + const std::string& oid, LCHead& head) { return store->getDB()->get_head(oid, head); } int DBLifecycle::put_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCHead& head) + const std::string& oid, const LCHead& head) { return store->getDB()->put_head(oid, head); } diff --git a/src/rgw/rgw_sal_dbstore.h b/src/rgw/rgw_sal_dbstore.h index f163b874eb0..6075a52c299 100644 --- a/src/rgw/rgw_sal_dbstore.h +++ b/src/rgw/rgw_sal_dbstore.h @@ -38,31 +38,30 @@ public: } }; -class DBLifecycle : public StoreLifecycle { +class DBLifecycle : public Lifecycle { DBStore* store; public: DBLifecycle(DBStore* _st) : store(_st) {} - using StoreLifecycle::get_entry; virtual int get_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) override; + LCEntry& entry) override; virtual int get_next_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) override; + LCEntry& entry) override; virtual int set_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) override; + const std::string& oid, const LCEntry& entry) override; virtual int list_entries(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, uint32_t max_entries, - std::vector>& entries) override; + std::vector& entries) override; virtual int rm_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) override; + const std::string& oid, const LCEntry& entry) override; virtual int get_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, std::unique_ptr* head) override; - virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, LCHead& head) override; + virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y, + const std::string& oid, const LCHead& head) override; virtual std::unique_ptr get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) override; diff --git a/src/rgw/rgw_sal_filter.cc b/src/rgw/rgw_sal_filter.cc index 5afefa3d258..bfa5e3c29be 100644 --- a/src/rgw/rgw_sal_filter.cc +++ b/src/rgw/rgw_sal_filter.cc @@ -1324,40 +1324,22 @@ int FilterLCSerializer::try_lock(const DoutPrefixProvider *dpp, utime_t dur, return next->try_lock(dpp, dur, y); } -std::unique_ptr FilterLifecycle::get_entry() -{ - std::unique_ptr e = next->get_entry(); - return std::make_unique(std::move(e)); -} - int FilterLifecycle::get_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + LCEntry& entry) { - std::unique_ptr ne; - int ret = next->get_entry(dpp, y, oid, marker, &ne); - if (ret < 0) - return ret; - - *entry = std::make_unique(std::move(ne)); - return 0; + return next->get_entry(dpp, y, oid, marker, entry); } int FilterLifecycle::get_next_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) + LCEntry& entry) { - std::unique_ptr ne; - int ret = next->get_next_entry(dpp, y, oid, marker, &ne); - if (ret < 0) - return ret; - - *entry = std::make_unique(std::move(ne)); - return 0; + return next->get_next_entry(dpp, y, oid, marker, entry); } int FilterLifecycle::set_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) + const std::string& oid, const LCEntry& entry) { return next->set_entry(dpp, y, oid, entry); } @@ -1365,42 +1347,27 @@ int FilterLifecycle::set_entry(const DoutPrefixProvider* dpp, optional_yield y, int FilterLifecycle::list_entries(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, uint32_t max_entries, - std::vector>& entries) + std::vector& entries) { - std::vector> ne; - int ret = next->list_entries(dpp, y, oid, marker, max_entries, ne); - if (ret < 0) - return ret; - - for (auto& ent : ne) { - entries.emplace_back(std::make_unique(std::move(ent))); - } - - return 0; + return next->list_entries(dpp, y, oid, marker, max_entries, entries); } int FilterLifecycle::rm_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) + const std::string& oid, const LCEntry& entry) { return next->rm_entry(dpp, y, oid, entry); } int FilterLifecycle::get_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, std::unique_ptr* head) + const std::string& oid, LCHead& head) { - std::unique_ptr nh; - int ret = next->get_head(dpp, y, oid, &nh); - if (ret < 0) - return ret; - - *head = std::make_unique(std::move(nh)); - return 0; + return next->get_head(dpp, y, oid, head); } int FilterLifecycle::put_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCHead& head) + const std::string& oid, const LCHead& head) { - return next->put_head(dpp, y, oid, *(dynamic_cast(head).next.get())); + return next->put_head(dpp, y, oid, head); } std::unique_ptr FilterLifecycle::get_serializer( diff --git a/src/rgw/rgw_sal_filter.h b/src/rgw/rgw_sal_filter.h index fc2e3aeffa3..70c1b200812 100644 --- a/src/rgw/rgw_sal_filter.h +++ b/src/rgw/rgw_sal_filter.h @@ -969,59 +969,28 @@ protected: std::unique_ptr next; public: - struct FilterLCHead : LCHead { - std::unique_ptr next; - - FilterLCHead(std::unique_ptr _next) : next(std::move(_next)) {} - virtual ~FilterLCHead() = default; - - virtual time_t& get_start_date() override { return next->get_start_date(); } - virtual void set_start_date(time_t t) override { next->set_start_date(t); } - virtual std::string& get_marker() override { return next->get_marker(); } - virtual void set_marker(const std::string& m) override { next->set_marker(m); } - virtual time_t& get_shard_rollover_date() override { return next->get_shard_rollover_date(); } - virtual void set_shard_rollover_date(time_t t) override { next->set_shard_rollover_date(t); } - }; - - struct FilterLCEntry : LCEntry { - std::unique_ptr next; - - FilterLCEntry(std::unique_ptr _next) : next(std::move(_next)) {} - virtual ~FilterLCEntry() = default; - - virtual std::string& get_bucket() override { return next->get_bucket(); } - virtual void set_bucket(const std::string& b) override { next->set_bucket(b); } - virtual std::string& get_oid() override { return next->get_oid(); } - virtual void set_oid(const std::string& o) override { next->set_oid(o); } - virtual uint64_t get_start_time() override { return next->get_start_time(); } - virtual void set_start_time(uint64_t t) override { next->set_start_time(t); } - virtual uint32_t get_status() override { return next->get_status(); } - virtual void set_status(uint32_t s) override { next->set_status(s); } - virtual void print(std::ostream& out) const override { return next->print(out); } - }; FilterLifecycle(std::unique_ptr _next) : next(std::move(_next)) {} virtual ~FilterLifecycle() = default; - virtual std::unique_ptr get_entry() override; virtual int get_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) override; + LCEntry& entry) override; virtual int get_next_entry(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, - std::unique_ptr* entry) override; + LCEntry& entry) override; virtual int set_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) override; + const std::string& oid, const LCEntry& entry) override; virtual int list_entries(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, const std::string& marker, uint32_t max_entries, - std::vector>& entries) override; + std::vector& entries) override; virtual int rm_entry(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, LCEntry& entry) override; + const std::string& oid, const LCEntry& entry) override; virtual int get_head(const DoutPrefixProvider* dpp, optional_yield y, - const std::string& oid, std::unique_ptr* head) override; - virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y, const std::string& oid, LCHead& head) override; + virtual int put_head(const DoutPrefixProvider* dpp, optional_yield y, + const std::string& oid, const LCHead& head) override; virtual std::unique_ptr get_serializer(const std::string& lock_name, const std::string& oid, const std::string& cookie) override; diff --git a/src/rgw/rgw_sal_store.h b/src/rgw/rgw_sal_store.h index 6084612d127..5b71166bc96 100644 --- a/src/rgw/rgw_sal_store.h +++ b/src/rgw/rgw_sal_store.h @@ -428,74 +428,6 @@ public: virtual void print(std::ostream& out) const override { out << oid; } }; -class StoreLifecycle : public Lifecycle { -public: - struct StoreLCHead : LCHead { - time_t start_date{0}; - time_t shard_rollover_date{0}; - std::string marker; - - StoreLCHead() = default; - StoreLCHead(time_t _start_date, time_t _rollover_date, std::string& _marker) : start_date(_start_date), shard_rollover_date(_rollover_date), marker(_marker) {} - - StoreLCHead& operator=(LCHead& _h) { - start_date = _h.get_start_date(); - shard_rollover_date = _h.get_shard_rollover_date(); - marker = _h.get_marker(); - - return *this; - } - - virtual time_t& get_start_date() override { return start_date; } - virtual void set_start_date(time_t _date) override { start_date = _date; } - virtual std::string& get_marker() override { return marker; } - virtual void set_marker(const std::string& _marker) override { marker = _marker; } - virtual time_t& get_shard_rollover_date() override { return shard_rollover_date; } - virtual void set_shard_rollover_date(time_t _date) override { shard_rollover_date = _date; } - }; - - struct StoreLCEntry : LCEntry { - std::string bucket; - std::string oid; - uint64_t start_time{0}; - uint32_t status{0}; - - StoreLCEntry() = default; - StoreLCEntry(std::string& _bucket, uint64_t _time, uint32_t _status) : bucket(_bucket), start_time(_time), status(_status) {} - StoreLCEntry(std::string& _bucket, std::string _oid, uint64_t _time, uint32_t _status) : bucket(_bucket), oid(_oid), start_time(_time), status(_status) {} - StoreLCEntry(const StoreLCEntry& _e) = default; - - StoreLCEntry& operator=(LCEntry& _e) { - bucket = _e.get_bucket(); - oid = _e.get_oid(); - start_time = _e.get_start_time(); - status = _e.get_status(); - - return *this; - } - - virtual std::string& get_bucket() override { return bucket; } - virtual void set_bucket(const std::string& _bucket) override { bucket = _bucket; } - virtual std::string& get_oid() override { return oid; } - virtual void set_oid(const std::string& _oid) override { oid = _oid; } - virtual uint64_t get_start_time() override { return start_time; } - virtual void set_start_time(uint64_t _time) override { start_time = _time; } - virtual uint32_t get_status() override { return status; } - virtual void set_status(uint32_t _status) override { status = _status; } - virtual void print(std::ostream& out) const override { - out << bucket << ":" << oid << ":" << start_time << ":" << status; - } - }; - - StoreLifecycle() = default; - virtual ~StoreLifecycle() = default; - - virtual std::unique_ptr get_entry() override { - return std::make_unique(); - } - using Lifecycle::get_entry; -}; - class StoreNotification : public Notification { protected: Object* obj; -- 2.39.5