From: Adam C. Emerson Date: Tue, 2 Feb 2021 19:09:52 +0000 (-0500) Subject: rgw: Fix cursor handling in DataLogBackends::list X-Git-Tag: v16.2.2~8^2~9^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0a2bee7e18367fbb1be73ece26e1a6efb099c161;p=ceph.git rgw: Fix cursor handling in DataLogBackends::list 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 (cherry picked from commit d7739178e994ce84886d297a29f2250e4bd78daa) Signed-off-by: Adam C. Emerson --- diff --git a/src/rgw/rgw_datalog.cc b/src/rgw/rgw_datalog.cc index d81d955ef6f17..1db5eb86d62e1 100644 --- a/src/rgw/rgw_datalog.cc +++ b/src/rgw/rgw_datalog.cc @@ -704,7 +704,8 @@ int DataLogBackends::list(int shard, int max_entries, std::optional 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 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;