From 9ef642dcc52640c00ed2b3b65e905218ecc6941e Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Fri, 20 Jan 2023 23:24:28 -0500 Subject: [PATCH] cls/log: Switch from std::list to std::vector We should not be using std::list everywhere, and this is an excellent time to switch. Signed-off-by: Adam C. Emerson --- src/cls/log/cls_log_client.cc | 10 +++++----- src/cls/log/cls_log_client.h | 4 ++-- src/cls/log/cls_log_ops.h | 4 ++-- src/rgw/driver/rados/rgw_cr_rados.h | 2 +- src/rgw/driver/rados/rgw_datalog.cc | 6 +++--- src/rgw/driver/rados/rgw_datalog.h | 2 +- src/rgw/driver/rados/rgw_metadata.cc | 4 ++-- src/rgw/driver/rados/rgw_rest_log.cc | 2 +- src/rgw/driver/rados/rgw_rest_log.h | 2 +- src/rgw/driver/rados/rgw_sync.cc | 12 ++++++------ src/rgw/rgw_admin.cc | 8 ++++---- src/rgw/rgw_mdlog.h | 4 ++-- src/rgw/services/svc_cls.cc | 6 +++--- src/rgw/services/svc_cls.h | 4 ++-- src/test/cls_log/test_cls_log.cc | 26 +++++++++++++------------- src/test/rgw/test_log_backing.cc | 4 ++-- 16 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/cls/log/cls_log_client.cc b/src/cls/log/cls_log_client.cc index 182bb9fec47e9..18510b6b2fabf 100644 --- a/src/cls/log/cls_log_client.cc +++ b/src/cls/log/cls_log_client.cc @@ -7,7 +7,7 @@ #include "include/compat.h" -using std::list; +using std::vector; using std::string; using ceph::bufferlist; @@ -16,7 +16,7 @@ using namespace librados; -void cls_log_add(librados::ObjectWriteOperation& op, list& entries, bool monotonic_inc) +void cls_log_add(librados::ObjectWriteOperation& op, vector& entries, bool monotonic_inc) { bufferlist in; cls_log_add_op call; @@ -88,11 +88,11 @@ int cls_log_trim(librados::IoCtx& io_ctx, const string& oid, const utime_t& from } class LogListCtx : public ObjectOperationCompletion { - list *entries; + vector *entries; string *marker; bool *truncated; public: - LogListCtx(list *_entries, string *_marker, bool *_truncated) : + LogListCtx(vector *_entries, string *_marker, bool *_truncated) : entries(_entries), marker(_marker), truncated(_truncated) {} void handle_completion(int r, bufferlist& outbl) override { if (r >= 0) { @@ -115,7 +115,7 @@ public: void cls_log_list(librados::ObjectReadOperation& op, const utime_t& from, const utime_t& to, const string& in_marker, int max_entries, - list& entries, + vector& entries, string *out_marker, bool *truncated) { bufferlist inbl; diff --git a/src/cls/log/cls_log_client.h b/src/cls/log/cls_log_client.h index 2afdabeb3e0a2..5187b55756786 100644 --- a/src/cls/log/cls_log_client.h +++ b/src/cls/log/cls_log_client.h @@ -14,14 +14,14 @@ void cls_log_add_prepare_entry(cls_log_entry& entry, const utime_t& timestamp, const std::string& section, const std::string& name, ceph::buffer::list& bl); -void cls_log_add(librados::ObjectWriteOperation& op, std::list& entries, bool monotonic_inc); +void cls_log_add(librados::ObjectWriteOperation& op, std::vector& entries, bool monotonic_inc); void cls_log_add(librados::ObjectWriteOperation& op, cls_log_entry& entry); void cls_log_add(librados::ObjectWriteOperation& op, const utime_t& timestamp, const std::string& section, const std::string& name, ceph::buffer::list& bl); void cls_log_list(librados::ObjectReadOperation& op, const utime_t& from, const utime_t& to, const std::string& in_marker, - int max_entries, std::list& entries, + int max_entries, std::vector& entries, std::string *out_marker, bool *truncated); void cls_log_trim(librados::ObjectWriteOperation& op, const utime_t& from_time, const utime_t& to_time, diff --git a/src/cls/log/cls_log_ops.h b/src/cls/log/cls_log_ops.h index 5a65892598b6e..50e0d743dc5c0 100644 --- a/src/cls/log/cls_log_ops.h +++ b/src/cls/log/cls_log_ops.h @@ -7,7 +7,7 @@ #include "cls_log_types.h" struct cls_log_add_op { - std::list entries; + std::vector entries; bool monotonic_inc; cls_log_add_op() : monotonic_inc(true) {} @@ -77,7 +77,7 @@ struct cls_log_list_op { WRITE_CLASS_ENCODER(cls_log_list_op) struct cls_log_list_ret { - std::list entries; + std::vector entries; std::string marker; bool truncated; diff --git a/src/rgw/driver/rados/rgw_cr_rados.h b/src/rgw/driver/rados/rgw_cr_rados.h index 3b192f1981831..bac210bc23d69 100644 --- a/src/rgw/driver/rados/rgw_cr_rados.h +++ b/src/rgw/driver/rados/rgw_cr_rados.h @@ -1524,7 +1524,7 @@ public: class RGWRadosTimelogAddCR : public RGWSimpleCoroutine { const DoutPrefixProvider *dpp; rgw::sal::RadosStore* store; - std::list entries; + std::vector entries; std::string oid; diff --git a/src/rgw/driver/rados/rgw_datalog.cc b/src/rgw/driver/rados/rgw_datalog.cc index 167cbcdba4a89..403239077d284 100644 --- a/src/rgw/driver/rados/rgw_datalog.cc +++ b/src/rgw/driver/rados/rgw_datalog.cc @@ -98,7 +98,7 @@ void rgw_data_notify_entry::decode_json(JSONObj *obj) { } class RGWDataChangesOmap final : public RGWDataChangesBE { - using centries = std::list; + using centries = std::vector; std::vector oids; public: @@ -154,7 +154,7 @@ public: std::optional marker, std::string* out_marker, bool* truncated, optional_yield y) override { - std::list log_entries; + std::vector log_entries; lr::ObjectReadOperation op; cls_log_list(op, {}, {}, std::string(marker.value_or("")), max_entries, log_entries, out_marker, truncated); @@ -235,7 +235,7 @@ public: } int is_empty(const DoutPrefixProvider *dpp, optional_yield y) override { for (auto shard = 0u; shard < oids.size(); ++shard) { - std::list log_entries; + std::vector log_entries; lr::ObjectReadOperation op; std::string out_marker; bool truncated; diff --git a/src/rgw/driver/rados/rgw_datalog.h b/src/rgw/driver/rados/rgw_datalog.h index 58042df2c62e9..e2fc16dd305cb 100644 --- a/src/rgw/driver/rados/rgw_datalog.h +++ b/src/rgw/driver/rados/rgw_datalog.h @@ -357,7 +357,7 @@ protected: return datalog.get_oid(gen_id, shard_id); } public: - using entries = std::variant, + using entries = std::variant, std::vector>; const uint64_t gen_id; diff --git a/src/rgw/driver/rados/rgw_metadata.cc b/src/rgw/driver/rados/rgw_metadata.cc index 996f73e9abea7..8878ae6c7c646 100644 --- a/src/rgw/driver/rados/rgw_metadata.cc +++ b/src/rgw/driver/rados/rgw_metadata.cc @@ -65,7 +65,7 @@ int RGWMetadataLog::get_shard_id(const string& hash_key, int *shard_id) return 0; } -int RGWMetadataLog::store_entries_in_shard(const DoutPrefixProvider *dpp, list& entries, int shard_id, librados::AioCompletion *completion) +int RGWMetadataLog::store_entries_in_shard(const DoutPrefixProvider *dpp, vector& entries, int shard_id, librados::AioCompletion *completion) { string oid; @@ -96,7 +96,7 @@ void RGWMetadataLog::complete_list_entries(void *handle) { int RGWMetadataLog::list_entries(const DoutPrefixProvider *dpp, void *handle, int max_entries, - list& entries, + vector& entries, string *last_marker, bool *truncated, optional_yield y) { diff --git a/src/rgw/driver/rados/rgw_rest_log.cc b/src/rgw/driver/rados/rgw_rest_log.cc index c2e9b7cfa187d..61e67f7c3afab 100644 --- a/src/rgw/driver/rados/rgw_rest_log.cc +++ b/src/rgw/driver/rados/rgw_rest_log.cc @@ -109,7 +109,7 @@ void RGWOp_MDLog_List::send_response() { s->formatter->dump_bool("truncated", truncated); { s->formatter->open_array_section("entries"); - for (list::iterator iter = entries.begin(); + for (auto iter = entries.begin(); iter != entries.end(); ++iter) { cls_log_entry& entry = *iter; static_cast(driver)->ctl()->meta.mgr->dump_log_entry(entry, s->formatter); diff --git a/src/rgw/driver/rados/rgw_rest_log.h b/src/rgw/driver/rados/rgw_rest_log.h index 02b1d133fc5b2..b54cdb425bb57 100644 --- a/src/rgw/driver/rados/rgw_rest_log.h +++ b/src/rgw/driver/rados/rgw_rest_log.h @@ -88,7 +88,7 @@ public: }; class RGWOp_MDLog_List : public RGWRESTOp { - std::list entries; + std::vector entries; std::string last_marker; bool truncated; public: diff --git a/src/rgw/driver/rados/rgw_sync.cc b/src/rgw/driver/rados/rgw_sync.cc index c973a039efc84..8b5768c86b68a 100644 --- a/src/rgw/driver/rados/rgw_sync.cc +++ b/src/rgw/driver/rados/rgw_sync.cc @@ -399,7 +399,7 @@ protected: } public: string marker; - list entries; + vector entries; bool truncated; RGWAsyncReadMDLogEntries(const DoutPrefixProvider *dpp, RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RadosStore* _store, @@ -416,7 +416,7 @@ class RGWReadMDLogEntriesCR : public RGWSimpleCoroutine { string marker; string *pmarker; int max_entries; - list *entries; + vector *entries; bool *truncated; RGWAsyncReadMDLogEntries *req{nullptr}; @@ -424,7 +424,7 @@ class RGWReadMDLogEntriesCR : public RGWSimpleCoroutine { public: RGWReadMDLogEntriesCR(RGWMetaSyncEnv *_sync_env, RGWMetadataLog* mdlog, int _shard_id, string*_marker, int _max_entries, - list *_entries, bool *_truncated) + vector *_entries, bool *_truncated) : RGWSimpleCoroutine(_sync_env->cct), sync_env(_sync_env), mdlog(mdlog), shard_id(_shard_id), pmarker(_marker), max_entries(_max_entries), entries(_entries), truncated(_truncated) {} @@ -1416,8 +1416,8 @@ class RGWMetaSyncShardCR : public RGWCoroutine { RGWMetaSyncShardMarkerTrack *marker_tracker = nullptr; - list log_entries; - list::iterator log_iter; + vector log_entries; + decltype(log_entries)::iterator log_iter; bool truncated = false; string mdlog_marker; @@ -2529,7 +2529,7 @@ int RGWCloneMetaLogCoroutine::state_receive_rest_response() int RGWCloneMetaLogCoroutine::state_store_mdlog_entries() { - list dest_entries; + vector dest_entries; vector::iterator iter; for (iter = data.entries.begin(); iter != data.entries.end(); ++iter) { diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 22dceda29ba21..300302f5b46e0 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -8850,7 +8850,7 @@ next: formatter->open_array_section("entries"); for (; i < g_ceph_context->_conf->rgw_md_log_max_shards; i++) { void *handle; - list entries; + vector entries; meta_log->init_list_entries(i, {}, {}, marker, &handle); bool truncated; @@ -8861,7 +8861,7 @@ next: return -ret; } - for (list::iterator iter = entries.begin(); iter != entries.end(); ++iter) { + for (auto iter = entries.begin(); iter != entries.end(); ++iter) { cls_log_entry& entry = *iter; static_cast(driver)->ctl()->meta.mgr->dump_log_entry(entry, formatter.get()); } @@ -9464,7 +9464,7 @@ next: string oid = RGWSyncErrorLogger::get_shard_oid(RGW_SYNC_ERROR_LOG_SHARD_PREFIX, shard_id); do { - list entries; + vector entries; ret = static_cast(driver)->svc()->cls->timelog.list(dpp(), oid, {}, {}, max_entries - count, entries, marker, &marker, &truncated, null_yield); if (ret == -ENOENT) { @@ -10031,7 +10031,7 @@ next: formatter->open_array_section("entries"); for (; i < g_ceph_context->_conf->rgw_data_log_num_shards; i++) { - list entries; + vector entries; RGWDataChangesLogInfo info; static_cast(driver)->svc()-> diff --git a/src/rgw/rgw_mdlog.h b/src/rgw/rgw_mdlog.h index 152126890b75b..589a340837e08 100644 --- a/src/rgw/rgw_mdlog.h +++ b/src/rgw/rgw_mdlog.h @@ -104,7 +104,7 @@ public: int add_entry(const DoutPrefixProvider *dpp, const std::string& hash_key, const std::string& section, const std::string& key, bufferlist& bl, optional_yield y); int get_shard_id(const std::string& hash_key, int *shard_id); - int store_entries_in_shard(const DoutPrefixProvider *dpp, std::list& entries, int shard_id, librados::AioCompletion *completion); + int store_entries_in_shard(const DoutPrefixProvider *dpp, std::vector& entries, int shard_id, librados::AioCompletion *completion); struct LogListCtx { int cur_shard; @@ -126,7 +126,7 @@ public: int list_entries(const DoutPrefixProvider *dpp, void *handle, int max_entries, - std::list& entries, + std::vector& entries, std::string *out_marker, bool *truncated, optional_yield y); diff --git a/src/rgw/services/svc_cls.cc b/src/rgw/services/svc_cls.cc index 342146bfefa70..7ebc0e409118d 100644 --- a/src/rgw/services/svc_cls.cc +++ b/src/rgw/services/svc_cls.cc @@ -294,9 +294,9 @@ int RGWSI_Cls::TimeLog::add(const DoutPrefixProvider *dpp, return obj.operate(dpp, &op, y); } -int RGWSI_Cls::TimeLog::add(const DoutPrefixProvider *dpp, +int RGWSI_Cls::TimeLog::add(const DoutPrefixProvider *dpp, const string& oid, - std::list& entries, + std::vector& entries, librados::AioCompletion *completion, bool monotonic_inc, optional_yield y) @@ -323,7 +323,7 @@ int RGWSI_Cls::TimeLog::list(const DoutPrefixProvider *dpp, const string& oid, const real_time& start_time, const real_time& end_time, - int max_entries, std::list& entries, + int max_entries, std::vector& entries, const string& marker, string *out_marker, bool *truncated, diff --git a/src/rgw/services/svc_cls.h b/src/rgw/services/svc_cls.h index d1d1d659be88e..eab1711d1d94d 100644 --- a/src/rgw/services/svc_cls.h +++ b/src/rgw/services/svc_cls.h @@ -99,7 +99,7 @@ public: optional_yield y); int add(const DoutPrefixProvider *dpp, const std::string& oid, - std::list& entries, + std::vector& entries, librados::AioCompletion *completion, bool monotonic_inc, optional_yield y); @@ -107,7 +107,7 @@ public: const std::string& oid, const real_time& start_time, const real_time& end_time, - int max_entries, std::list& entries, + int max_entries, std::vector& entries, const std::string& marker, std::string *out_marker, bool *truncated, diff --git a/src/test/cls_log/test_cls_log.cc b/src/test/cls_log/test_cls_log.cc index e8777ac5fedbb..a726e1cf49f88 100644 --- a/src/test/cls_log/test_cls_log.cc +++ b/src/test/cls_log/test_cls_log.cc @@ -114,7 +114,7 @@ void check_entry(cls_log_entry& entry, utime_t& start_time, int i, bool modified static int log_list(librados::IoCtx& ioctx, const std::string& oid, utime_t& from, utime_t& to, const string& in_marker, int max_entries, - list& entries, + vector& entries, string *out_marker, bool *truncated) { librados::ObjectReadOperation rop; @@ -126,7 +126,7 @@ static int log_list(librados::IoCtx& ioctx, const std::string& oid, static int log_list(librados::IoCtx& ioctx, const std::string& oid, utime_t& from, utime_t& to, int max_entries, - list& entries, bool *truncated) + vector& entries, bool *truncated) { std::string marker; return log_list(ioctx, oid, from, to, marker, max_entries, @@ -134,7 +134,7 @@ static int log_list(librados::IoCtx& ioctx, const std::string& oid, } static int log_list(librados::IoCtx& ioctx, const std::string& oid, - list& entries) + vector& entries) { utime_t from, to; bool truncated{false}; @@ -154,7 +154,7 @@ TEST_F(cls_log, test_log_add_same_time) utime_t to_time = get_time(start_time, 1, true); generate_log(ioctx, oid, 10, start_time, false); - list entries; + vector entries; bool truncated; /* check list */ @@ -164,7 +164,7 @@ TEST_F(cls_log, test_log_add_same_time) ASSERT_EQ(10, (int)entries.size()); ASSERT_EQ(0, (int)truncated); } - list::iterator iter; + vector::iterator iter; /* need to sort returned entries, all were using the same time as key */ map check_ents; @@ -214,7 +214,7 @@ TEST_F(cls_log, test_log_add_different_time) utime_t start_time = ceph_clock_now(); generate_log(ioctx, oid, 10, start_time, true); - list entries; + vector entries; bool truncated; utime_t to_time = utime_t(start_time.sec() + 10, start_time.nsec()); @@ -227,7 +227,7 @@ TEST_F(cls_log, test_log_add_different_time) ASSERT_EQ(0, (int)truncated); } - list::iterator iter; + vector::iterator iter; /* returned entries should be sorted by time */ map check_ents; @@ -299,7 +299,7 @@ TEST_F(cls_log, trim_by_time) utime_t start_time = ceph_clock_now(); generate_log(ioctx, oid, 10, start_time, true); - list entries; + vector entries; bool truncated; /* check list */ @@ -333,7 +333,7 @@ TEST_F(cls_log, trim_by_marker) utime_t zero_time; std::vector log1; { - list entries; + vector entries; ASSERT_EQ(0, log_list(ioctx, oid, entries)); ASSERT_EQ(10u, entries.size()); @@ -345,7 +345,7 @@ TEST_F(cls_log, trim_by_marker) const std::string from = ""; const std::string to = log1[0].id; ASSERT_EQ(0, do_log_trim(ioctx, oid, from, to)); - list entries; + vector entries; ASSERT_EQ(0, log_list(ioctx, oid, entries)); ASSERT_EQ(9u, entries.size()); EXPECT_EQ(log1[1].id, entries.begin()->id); @@ -356,7 +356,7 @@ TEST_F(cls_log, trim_by_marker) const std::string from = log1[8].id; const std::string to = "9"; ASSERT_EQ(0, do_log_trim(ioctx, oid, from, to)); - list entries; + vector entries; ASSERT_EQ(0, log_list(ioctx, oid, entries)); ASSERT_EQ(8u, entries.size()); EXPECT_EQ(log1[8].id, entries.rbegin()->id); @@ -367,7 +367,7 @@ TEST_F(cls_log, trim_by_marker) const std::string from = log1[3].id; const std::string to = log1[4].id; ASSERT_EQ(0, do_log_trim(ioctx, oid, from, to)); - list entries; + vector entries; ASSERT_EQ(0, log_list(ioctx, oid, entries)); ASSERT_EQ(7u, entries.size()); ASSERT_EQ(-ENODATA, do_log_trim(ioctx, oid, from, to)); @@ -377,7 +377,7 @@ TEST_F(cls_log, trim_by_marker) const std::string from = ""; const std::string to = "9"; ASSERT_EQ(0, do_log_trim(ioctx, oid, from, to)); - list entries; + vector entries; ASSERT_EQ(0, log_list(ioctx, oid, entries)); ASSERT_EQ(0u, entries.size()); ASSERT_EQ(-ENODATA, do_log_trim(ioctx, oid, from, to)); diff --git a/src/test/rgw/test_log_backing.cc b/src/test/rgw/test_log_backing.cc index e4109d535d10c..155e341d35dc5 100644 --- a/src/test/rgw/test_log_backing.cc +++ b/src/test/rgw/test_log_backing.cc @@ -94,7 +94,7 @@ protected: std::string to_marker; { lr::ObjectReadOperation op; - std::list entries; + std::vector entries; bool truncated = false; cls_log_list(op, {}, {}, {}, 1, entries, &to_marker, &truncated); auto r = rgw_rados_operate(&dp, ioctx, oid, &op, nullptr, null_yield); @@ -109,7 +109,7 @@ protected: } { lr::ObjectReadOperation op; - std::list entries; + std::vector entries; bool truncated = false; cls_log_list(op, {}, {}, {}, 1, entries, &to_marker, &truncated); auto r = rgw_rados_operate(&dp, ioctx, oid, &op, nullptr, null_yield); -- 2.39.5