]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/log: Switch from std::list to std::vector
authorAdam C. Emerson <aemerson@redhat.com>
Sat, 21 Jan 2023 04:24:28 +0000 (23:24 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 1 Apr 2025 15:10:13 +0000 (11:10 -0400)
We should not be using std::list everywhere, and this is an excellent
time to switch.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
16 files changed:
src/cls/log/cls_log_client.cc
src/cls/log/cls_log_client.h
src/cls/log/cls_log_ops.h
src/rgw/driver/rados/rgw_cr_rados.h
src/rgw/driver/rados/rgw_datalog.cc
src/rgw/driver/rados/rgw_datalog.h
src/rgw/driver/rados/rgw_metadata.cc
src/rgw/driver/rados/rgw_rest_log.cc
src/rgw/driver/rados/rgw_rest_log.h
src/rgw/driver/rados/rgw_sync.cc
src/rgw/radosgw-admin/radosgw-admin.cc
src/rgw/rgw_mdlog.h
src/rgw/services/svc_cls.cc
src/rgw/services/svc_cls.h
src/test/cls_log/test_cls_log.cc
src/test/rgw/test_log_backing.cc

index 182bb9fec47e9e74a7c7595c685486db68a8fda8..18510b6b2fabf029e36c3d58ae4025e51d437e8a 100644 (file)
@@ -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<cls_log_entry>& entries, bool monotonic_inc)
+void cls_log_add(librados::ObjectWriteOperation& op, vector<cls_log_entry>& 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<cls_log_entry> *entries;
+  vector<cls_log_entry> *entries;
   string *marker;
   bool *truncated;
 public:
-  LogListCtx(list<cls_log_entry> *_entries, string *_marker, bool *_truncated) :
+  LogListCtx(vector<cls_log_entry> *_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<cls_log_entry>& entries,
+                 vector<cls_log_entry>& entries,
                   string *out_marker, bool *truncated)
 {
   bufferlist inbl;
index 2afdabeb3e0a24172b68119b28a6fc84e50c1576..5187b55756786b718fd3ca753586559d8eeec818 100644 (file)
 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<cls_log_entry>& entries, bool monotonic_inc);
+void cls_log_add(librados::ObjectWriteOperation& op, std::vector<cls_log_entry>& 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<cls_log_entry>& entries,
+                 int max_entries, std::vector<cls_log_entry>& entries,
                   std::string *out_marker, bool *truncated);
 
 void cls_log_trim(librados::ObjectWriteOperation& op, const utime_t& from_time, const utime_t& to_time,
index 4d3b2f5d30914c58d882166590ca7eab9bb7e079..82207d52100ffb9a668fd2ce0774bf5bb385d123 100644 (file)
@@ -8,7 +8,7 @@
 #include "cls_log_types.h"
 
 struct cls_log_add_op {
-  std::list<cls_log_entry> entries;
+  std::vector<cls_log_entry> 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<cls_log_entry> entries;
+  std::vector<cls_log_entry> entries;
   std::string marker;
   bool truncated;
 
index 2cf99f98cc8ed7448e219389b68f81e603dfa491..ce84fce40174977771b71a10a07efa71b434d74e 100644 (file)
@@ -1519,7 +1519,7 @@ public:
 class RGWRadosTimelogAddCR : public RGWSimpleCoroutine {
   const DoutPrefixProvider *dpp;
   rgw::sal::RadosStore* store;
-  std::list<cls_log_entry> entries;
+  std::vector<cls_log_entry> entries;
 
   std::string oid;
 
index 89835a8e4d0393ca820b8f8b3e915e125378a341..99b3fedab44b3dad077724f30f125a85ede54633 100644 (file)
@@ -99,7 +99,7 @@ void rgw_data_notify_entry::decode_json(JSONObj *obj) {
 }
 
 class RGWDataChangesOmap final : public RGWDataChangesBE {
-  using centries = std::list<cls_log_entry>;
+  using centries = std::vector<cls_log_entry>;
   std::vector<std::string> oids;
 
 public:
@@ -155,7 +155,7 @@ public:
           std::optional<std::string_view> marker,
           std::string* out_marker, bool* truncated,
           optional_yield y) override {
-    std::list<cls_log_entry> log_entries;
+    std::vector<cls_log_entry> 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<cls_log_entry> log_entries;
+      std::vector<cls_log_entry> log_entries;
       lr::ObjectReadOperation op;
       std::string out_marker;
       bool truncated;
index 6cfaee9dc82e014c477863fa9fea4f9090e1fe22..74073a4e7f84fc0652c9bb5e59528d6ab0bf3433 100644 (file)
@@ -354,7 +354,7 @@ protected:
     return datalog.get_oid(gen_id, shard_id);
   }
 public:
-  using entries = std::variant<std::list<cls_log_entry>,
+  using entries = std::variant<std::vector<cls_log_entry>,
                               std::vector<ceph::buffer::list>>;
 
   const uint64_t gen_id;
index 996f73e9abea79b509e634818d7e50c9b31a4721..8878ae6c7c646863a4925979f031d57ae5ab3dbe 100644 (file)
@@ -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<cls_log_entry>& entries, int shard_id, librados::AioCompletion *completion)
+int RGWMetadataLog::store_entries_in_shard(const DoutPrefixProvider *dpp, vector<cls_log_entry>& 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<cls_log_entry>& entries,
+                                vector<cls_log_entry>& entries,
                                 string *last_marker,
                                 bool *truncated,
                                 optional_yield y) {
index 11ed91c3fa1e92c02768623f5923107772e008b8..d8e6511dd23c07c469a520b829c472b9c9a8cefa 100644 (file)
@@ -109,7 +109,7 @@ void RGWOp_MDLog_List::send_response() {
   s->formatter->dump_bool("truncated", truncated);
   {
     s->formatter->open_array_section("entries");
-    for (list<cls_log_entry>::iterator iter = entries.begin();
+    for (auto iter = entries.begin();
         iter != entries.end(); ++iter) {
       cls_log_entry& entry = *iter;
       static_cast<rgw::sal::RadosStore*>(driver)->ctl()->meta.mgr->dump_log_entry(entry, s->formatter);
index 7c7e3510c71a9d5d693b354e56e69f248d9b60d2..0fbeb00e3e0007f5dd3fde596652cb7b32fb423f 100644 (file)
@@ -88,7 +88,7 @@ public:
 };
 
 class RGWOp_MDLog_List : public RGWRESTOp {
-  std::list<cls_log_entry> entries;
+  std::vector<cls_log_entry> entries;
   std::string last_marker;
   bool truncated;
 public:
index bd730dfd6c25996ddc0986969dea65b97cdd112b..3546bbe6bc32fffec33400cd62154247c9263dd2 100644 (file)
@@ -399,7 +399,7 @@ protected:
   }
 public:
   string marker;
-  list<cls_log_entry> entries;
+  vector<cls_log_entry> 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<cls_log_entry> *entries;
+  vector<cls_log_entry> *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<cls_log_entry> *_entries, bool *_truncated)
+                        vector<cls_log_entry> *_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<cls_log_entry> log_entries;
-  list<cls_log_entry>::iterator log_iter;
+  vector<cls_log_entry> 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<cls_log_entry> dest_entries;
+  vector<cls_log_entry> dest_entries;
 
   vector<rgw_mdlog_entry>::iterator iter;
   for (iter = data.entries.begin(); iter != data.entries.end(); ++iter) {
index aa360e15575846a31dcc3a020335499afc5dbc0b..9df14dfe72afd70d377201dded37d3db16180dd7 100644 (file)
@@ -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<cls_log_entry> entries;
+      vector<cls_log_entry> entries;
 
       meta_log->init_list_entries(i, {}, {}, marker, &handle);
       bool truncated;
@@ -9715,7 +9715,7 @@ next:
           return -ret;
         }
 
-        for (list<cls_log_entry>::iterator iter = entries.begin(); iter != entries.end(); ++iter) {
+        for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
           cls_log_entry& entry = *iter;
           static_cast<rgw::sal::RadosStore*>(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<cls_log_entry> entries;
+        vector<cls_log_entry> entries;
         ret = static_cast<rgw::sal::RadosStore*>(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<cls_log_entry> entries;
+      vector<cls_log_entry> entries;
 
       RGWDataChangesLogInfo info;
       static_cast<rgw::sal::RadosStore*>(driver)->svc()->
index 4817dded9dbecfb5cd80073814fbf2cb96cbe73c..496fc5ff164706615b76abd78ec343e2951285d9 100644 (file)
@@ -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<cls_log_entry>& entries, int shard_id, librados::AioCompletion *completion);
+  int store_entries_in_shard(const DoutPrefixProvider *dpp, std::vector<cls_log_entry>& 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<cls_log_entry>& entries,
+                   std::vector<cls_log_entry>& entries,
                   std::string *out_marker,
                   bool *truncated,
                   optional_yield y);
index 9bb5de5a79e6ba598084d746d1df383fc59a7829..de4d95315579348503f2dd199f73dc377d552a81 100644 (file)
@@ -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<cls_log_entry>& entries,
+                            std::vector<cls_log_entry>& 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<cls_log_entry>& entries,
+                             int max_entries, std::vector<cls_log_entry>& entries,
                              const string& marker,
                              string *out_marker,
                              bool *truncated,
index 6648714dbc8fbc35264b84188281b9c8929c4d11..d3da4a1e9c929978fef1bf0210ba472d860d6544 100644 (file)
@@ -94,7 +94,7 @@ public:
             optional_yield y);
     int add(const DoutPrefixProvider *dpp, 
             const std::string& oid,
-            std::list<cls_log_entry>& entries,
+            std::vector<cls_log_entry>& 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<cls_log_entry>& entries,
+             int max_entries, std::vector<cls_log_entry>& entries,
              const std::string& marker,
              std::string *out_marker,
              bool *truncated,
index 91e38844deca59d8779105bbc3575cd660b9278c..fdb4b78490019b5e6f9c22a21d2e754c3c92830c 100644 (file)
@@ -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<cls_log_entry>& entries,
+                    vector<cls_log_entry>& 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<cls_log_entry>& entries, bool *truncated)
+                    vector<cls_log_entry>& 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<cls_log_entry>& entries)
+                    vector<cls_log_entry>& 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<cls_log_entry> entries;
+  vector<cls_log_entry> 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<cls_log_entry>::iterator iter;
+  vector<cls_log_entry>::iterator iter;
 
   /* need to sort returned entries, all were using the same time as key */
   map<int, cls_log_entry> 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<cls_log_entry> entries;
+  vector<cls_log_entry> 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<cls_log_entry>::iterator iter;
+  vector<cls_log_entry>::iterator iter;
 
   /* returned entries should be sorted by time */
   map<int, cls_log_entry> 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<cls_log_entry> entries;
+  vector<cls_log_entry> entries;
   bool truncated;
 
   /* check list */
@@ -334,7 +334,7 @@ TEST_F(cls_log, trim_by_marker)
 
   std::vector<cls_log_entry> log1;
   {
-    list<cls_log_entry> entries;
+    vector<cls_log_entry> 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<cls_log_entry> entries;
+    vector<cls_log_entry> 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<cls_log_entry> entries;
+    vector<cls_log_entry> 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<cls_log_entry> entries;
+    vector<cls_log_entry> 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<cls_log_entry> entries;
+    vector<cls_log_entry> entries;
     ASSERT_EQ(0, log_list(ioctx, oid, entries));
     ASSERT_EQ(0u, entries.size());
     ASSERT_EQ(-ENODATA, do_log_trim(ioctx, oid, from, to));
index 27866461ac0eff773eadb45405c0cda33270a1ce..248617e30bc1db44b530452ad960283a9d22177b 100644 (file)
@@ -95,7 +95,7 @@ protected:
       std::string to_marker;
       {
        lr::ObjectReadOperation op;
-       std::list<cls_log_entry> entries;
+       std::vector<cls_log_entry> 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<cls_log_entry> entries;
+       std::vector<cls_log_entry> 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);