From 85d02f5da211cf60ba69e4b63639c21bf8952e30 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/radosgw-admin/radosgw-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 182bb9fec47..18510b6b2fa 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 2afdabeb3e0..5187b557567 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 4d3b2f5d309..82207d52100 100644 --- a/src/cls/log/cls_log_ops.h +++ b/src/cls/log/cls_log_ops.h @@ -8,7 +8,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) {} @@ -93,7 +93,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 2cf99f98cc8..ce84fce4017 100644 --- a/src/rgw/driver/rados/rgw_cr_rados.h +++ b/src/rgw/driver/rados/rgw_cr_rados.h @@ -1519,7 +1519,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 89835a8e4d0..99b3fedab44 100644 --- a/src/rgw/driver/rados/rgw_datalog.cc +++ b/src/rgw/driver/rados/rgw_datalog.cc @@ -99,7 +99,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: @@ -155,7 +155,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); @@ -236,7 +236,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 6cfaee9dc82..74073a4e7f8 100644 --- a/src/rgw/driver/rados/rgw_datalog.h +++ b/src/rgw/driver/rados/rgw_datalog.h @@ -354,7 +354,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 996f73e9abe..8878ae6c7c6 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 11ed91c3fa1..d8e6511dd23 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 7c7e3510c71..0fbeb00e3e0 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 bd730dfd6c2..3546bbe6bc3 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) {} @@ -1450,8 +1450,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; @@ -2583,7 +2583,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/radosgw-admin/radosgw-admin.cc b/src/rgw/radosgw-admin/radosgw-admin.cc index aa360e15575..9df14dfe72a 100644 --- a/src/rgw/radosgw-admin/radosgw-admin.cc +++ b/src/rgw/radosgw-admin/radosgw-admin.cc @@ -9704,7 +9704,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; @@ -9715,7 +9715,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()); } @@ -10329,7 +10329,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) { @@ -10898,7 +10898,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 4817dded9db..496fc5ff164 100644 --- a/src/rgw/rgw_mdlog.h +++ b/src/rgw/rgw_mdlog.h @@ -108,7 +108,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; @@ -130,7 +130,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 9bb5de5a79e..de4d9531557 100644 --- a/src/rgw/services/svc_cls.cc +++ b/src/rgw/services/svc_cls.cc @@ -280,9 +280,9 @@ int RGWSI_Cls::TimeLog::add(const DoutPrefixProvider *dpp, return obj.operate(dpp, std::move(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) @@ -309,7 +309,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 6648714dbc8..d3da4a1e9c9 100644 --- a/src/rgw/services/svc_cls.h +++ b/src/rgw/services/svc_cls.h @@ -94,7 +94,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); @@ -102,7 +102,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 91e38844dec..fdb4b784900 100644 --- a/src/test/cls_log/test_cls_log.cc +++ b/src/test/cls_log/test_cls_log.cc @@ -116,7 +116,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; @@ -128,7 +128,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, @@ -136,7 +136,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}; @@ -156,7 +156,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 */ @@ -166,7 +166,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; @@ -216,7 +216,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()); @@ -229,7 +229,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; @@ -301,7 +301,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 */ @@ -334,7 +334,7 @@ TEST_F(cls_log, trim_by_marker) std::vector log1; { - list entries; + vector entries; ASSERT_EQ(0, log_list(ioctx, oid, entries)); ASSERT_EQ(10u, entries.size()); @@ -346,7 +346,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); @@ -357,7 +357,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); @@ -368,7 +368,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)); @@ -378,7 +378,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 27866461ac0..248617e30bc 100644 --- a/src/test/rgw/test_log_backing.cc +++ b/src/test/rgw/test_log_backing.cc @@ -95,7 +95,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, std::move(op), nullptr, null_yield); @@ -110,7 +110,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, std::move(op), nullptr, null_yield); -- 2.39.5