]> 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 Emerson <aemerson@redhat.com>
Thu, 14 Sep 2023 21:48:00 +0000 (17:48 -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/rgw_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 5a65892598b6e21a4b9f69f45bbdbafece94d7e2..50e0d743dc5c0558a41e13ecf2d589e4685b8b36 100644 (file)
@@ -7,7 +7,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) {}
@@ -77,7 +77,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 3b192f1981831efb0e5124f714f4d96e81d9088c..bac210bc23d692e2657fe56958b0cb0ec7c3863c 100644 (file)
@@ -1524,7 +1524,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 167cbcdba4a89daa06c9bf1b7fea1fbab5110fbe..403239077d284b7cc06f7cf9580778b5bcc16992 100644 (file)
@@ -98,7 +98,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:
@@ -154,7 +154,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);
@@ -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<cls_log_entry> log_entries;
+      std::vector<cls_log_entry> log_entries;
       lr::ObjectReadOperation op;
       std::string out_marker;
       bool truncated;
index 58042df2c62e9261013c9d1469711c22c96ce318..e2fc16dd305cbc4167bcf929f938b3defaa4ee3e 100644 (file)
@@ -357,7 +357,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 c2e9b7cfa187d496cef3f4ddb714fdf1fa97a791..61e67f7c3afabf28a0477cb35a4d4a1e0f72028b 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 02b1d133fc5b2e30c6109a7ad8681d7e0d799f24..b54cdb425bb573240f77002922dde4db648e7d3c 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 c973a039efc84762291b453e0fb622237beb3895..8b5768c86b68afc0d1c3a21c0eb718a2d2a881ee 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) {}
@@ -1416,8 +1416,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;
@@ -2529,7 +2529,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 22dceda29ba215b40f5e6f306b4cbfb2f91a68cf..300302f5b46e012d407df159ea93c51002924d2d 100644 (file)
@@ -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<cls_log_entry> entries;
+      vector<cls_log_entry> entries;
 
       meta_log->init_list_entries(i, {}, {}, marker, &handle);
       bool truncated;
@@ -8861,7 +8861,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());
         }
@@ -9464,7 +9464,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) {
@@ -10031,7 +10031,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 152126890b75bda270d8763a42b4ba5d017ce2c6..589a340837e08d24b827647111e2f0d6e68a0491 100644 (file)
@@ -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<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;
@@ -126,7 +126,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 342146bfefa700c19ad1c73f2758fb374f968b7f..7ebc0e409118def7764a98d5c26f79c1d927741d 100644 (file)
@@ -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<cls_log_entry>& entries,
+                            std::vector<cls_log_entry>& 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<cls_log_entry>& entries,
+                             int max_entries, std::vector<cls_log_entry>& entries,
                              const string& marker,
                              string *out_marker,
                              bool *truncated,
index d1d1d659be88e11e223f93bd805e2ed4ecdcd3f0..eab1711d1d94db47d30b4b4e0f1f151b67c6f1ce 100644 (file)
@@ -99,7 +99,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);
@@ -107,7 +107,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 e8777ac5fedbbc65b8d12c3ebb2ed009630eca01..a726e1cf49f88d7c6208fd0f02400f3d36e6ed0d 100644 (file)
@@ -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<cls_log_entry>& entries,
+                    vector<cls_log_entry>& 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<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,
@@ -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<cls_log_entry>& entries)
+                    vector<cls_log_entry>& 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<cls_log_entry> entries;
+  vector<cls_log_entry> 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<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;
@@ -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<cls_log_entry> entries;
+  vector<cls_log_entry> 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<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;
@@ -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<cls_log_entry> entries;
+  vector<cls_log_entry> entries;
   bool truncated;
 
   /* check list */
@@ -333,7 +333,7 @@ TEST_F(cls_log, trim_by_marker)
   utime_t zero_time;
   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());
 
@@ -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<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);
@@ -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<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);
@@ -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<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));
@@ -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<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 e4109d535d10cc7693b5dafd288b78c39ea750a4..155e341d35dc585d87d644820dc236f3f03d1e24 100644 (file)
@@ -94,7 +94,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, &op, nullptr, null_yield);
@@ -109,7 +109,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, &op, nullptr, null_yield);