]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: extend MapCacher API
authorRonen Friedman <rfriedma@redhat.com>
Mon, 23 Sep 2024 10:25:05 +0000 (05:25 -0500)
committerRonen Friedman <rfriedma@redhat.com>
Thu, 10 Oct 2024 16:29:20 +0000 (11:29 -0500)
to include 'no out' version of get_next()

Signed-off-by: Ronen Friedman <rfriedma@redhat.com>
src/common/map_cacher.hpp
src/osd/scrubber/ScrubStore.h

index 4d843be75dc643bf1761c08b35ee738b29582a4f..95353425de9e6076ce5bcef850094b88e9aebbbc 100644 (file)
@@ -16,6 +16,7 @@
 #define MAPCACHER_H
 
 #include "include/Context.h"
+#include "include/expected.hpp"
 #include "common/sharedptr_registry.hpp"
 
 namespace MapCacher {
@@ -130,6 +131,50 @@ public:
     return -EINVAL;
   } ///< @return error value, 0 on success, -ENOENT if no more entries
 
+  /// Fetch first key/value std::pair after specified key
+  struct PosAndData {
+    K last_key;
+    V data;
+  };
+  using MaybePosAndData = tl::expected<PosAndData, int>;
+
+  MaybePosAndData get_1st_after_key(
+      K key  ///< [in] key after which to get next
+  )
+  {
+    ceph_assert(driver);
+    while (true) {
+      std::pair<K, boost::optional<V>> cached;
+      bool got_cached = in_progress.get_next(key, &cached);
+
+      ///\todo a driver->get_next() that returns an expected<K, V> would be nice
+      bool got_store{false};
+      std::pair<K, V> store;
+      int r = driver->get_next(key, &store);
+      if (r < 0 && r != -ENOENT) {
+        return tl::unexpected(r);
+      } else if (r == 0) {
+       got_store = true;
+      }
+
+      if (!got_cached && !got_store) {
+        return tl::unexpected(-ENOENT);
+      } else if (got_cached && (!got_store || store.first >= cached.first)) {
+       if (cached.second) {
+         return PosAndData{cached.first, *cached.second};
+       } else {
+         key = cached.first;
+         continue;  // value was cached as removed, recurse
+       }
+      } else {
+       return PosAndData{store.first, store.second};
+      }
+    }
+    ceph_abort();  // not reachable
+    return tl::unexpected(-EINVAL);
+  }
+
+
   /// Adds operation setting keys to Transaction
   void set_keys(
     const std::map<K, V> &keys,  ///< [in] keys/values to std::set
index a83841e2cfbb2368345f1c323a7f9771607d4475..7d590d2d1915e6ed56fd0a240b3f38c0376d727d 100644 (file)
@@ -97,6 +97,11 @@ class Store {
     std::map<std::string, ceph::buffer::list> results;
   };
 
+  using CacherPosData =
+      MapCacher::MapCacher<std::string, ceph::buffer::list>::PosAndData;
+  using ExpCacherPosData = tl::expected<CacherPosData, int>;
+
+
   std::vector<ceph::buffer::list> get_errors(const std::string& start,
                                             const std::string& end,
                                             uint64_t max_return) const;