summaryrefslogtreecommitdiffstats
path: root/src/common/map_cacher.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/map_cacher.hpp')
-rw-r--r--src/common/map_cacher.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/common/map_cacher.hpp b/src/common/map_cacher.hpp
index 4d843be75dc..95353425de9 100644
--- a/src/common/map_cacher.hpp
+++ b/src/common/map_cacher.hpp
@@ -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