]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Fix cursor handling in DataLogBackends::list
authorAdam C. Emerson <aemerson@redhat.com>
Tue, 2 Feb 2021 19:09:52 +0000 (14:09 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Mon, 5 Apr 2021 17:47:49 +0000 (13:47 -0400)
Don't assume that the lowest generation not greater than the requested
generation actually is the requested generation.

(Also don't hold the lock after we get a backend.)

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
(cherry picked from commit d7739178e994ce84886d297a29f2250e4bd78daa)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/rgw/rgw_datalog.cc

index d81d955ef6f173c1a354288ec8e9fe0c421b6ebe..1db5eb86d62e1c312b64d6fdf2a931178b84ec4d 100644 (file)
@@ -704,7 +704,8 @@ int DataLogBackends::list(int shard, int max_entries,
                          std::optional<std::string_view> marker,
                          std::string* out_marker, bool* truncated)
 {
-  auto [gen_id, cursor] = cursorgeno(marker);
+  const auto [start_id, start_cursor] = cursorgeno(marker);
+  auto gen_id = start_id;
   std::string out_cursor;
   while (max_entries > 0) {
     std::vector<rgw_data_change_log_entry> gentries;
@@ -712,7 +713,10 @@ int DataLogBackends::list(int shard, int max_entries,
     auto i = lower_bound(gen_id);
     if (i == end()) return 0;
     auto be = i->second;
-    auto r = be->list(shard, max_entries, gentries, cursor,
+    l.unlock();
+    gen_id = be->gen_id;
+    auto r = be->list(shard, max_entries, gentries,
+                     gen_id == start_id ? start_cursor : std::string{},
                      &out_cursor, truncated);
     if (r < 0)
       return r;
@@ -723,10 +727,13 @@ int DataLogBackends::list(int shard, int max_entries,
     for (auto& g : gentries) {
       g.log_id = gencursor(gen_id, g.log_id);
     }
-    max_entries -= gentries.size();
+    if (gentries.size() > max_entries)
+      max_entries = 0;
+    else
+      max_entries -= gentries.size();
+
     std::move(gentries.begin(), gentries.end(),
              std::back_inserter(entries));
-    cursor = {};
     ++gen_id;
   }
   return 0;