Skip to content

Commit 283f4c2

Browse files
committed
common: extend MapCacher API
to include 'no out' version of get_next() Signed-off-by: Ronen Friedman <[email protected]>
1 parent ce58c88 commit 283f4c2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/common/map_cacher.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define MAPCACHER_H
1717

1818
#include "include/Context.h"
19+
#include "include/expected.hpp"
1920
#include "common/sharedptr_registry.hpp"
2021

2122
namespace MapCacher {
@@ -130,6 +131,50 @@ class MapCacher {
130131
return -EINVAL;
131132
} ///< @return error value, 0 on success, -ENOENT if no more entries
132133

134+
/// Fetch first key/value std::pair after specified key
135+
struct PosAndData {
136+
K last_key;
137+
V data;
138+
};
139+
using MaybePosAndData = tl::expected<PosAndData, int>;
140+
141+
MaybePosAndData get_1st_after_key(
142+
K key ///< [in] key after which to get next
143+
)
144+
{
145+
ceph_assert(driver);
146+
while (true) {
147+
std::pair<K, boost::optional<V>> cached;
148+
bool got_cached = in_progress.get_next(key, &cached);
149+
150+
///\todo a driver->get_next() that returns an expected<K, V> would be nice
151+
bool got_store{false};
152+
std::pair<K, V> store;
153+
int r = driver->get_next(key, &store);
154+
if (r < 0 && r != -ENOENT) {
155+
return tl::unexpected(r);
156+
} else if (r == 0) {
157+
got_store = true;
158+
}
159+
160+
if (!got_cached && !got_store) {
161+
return tl::unexpected(-ENOENT);
162+
} else if (got_cached && (!got_store || store.first >= cached.first)) {
163+
if (cached.second) {
164+
return PosAndData{cached.first, *cached.second};
165+
} else {
166+
key = cached.first;
167+
continue; // value was cached as removed, recurse
168+
}
169+
} else {
170+
return PosAndData{store.first, store.second};
171+
}
172+
}
173+
ceph_abort(); // not reachable
174+
return tl::unexpected(-EINVAL);
175+
}
176+
177+
133178
/// Adds operation setting keys to Transaction
134179
void set_keys(
135180
const std::map<K, V> &keys, ///< [in] keys/values to std::set

src/osd/scrubber/ScrubStore.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class Store {
9797
std::map<std::string, ceph::buffer::list> results;
9898
};
9999

100+
using CacherPosData =
101+
MapCacher::MapCacher<std::string, ceph::buffer::list>::PosAndData;
102+
using ExpCacherPosData = tl::expected<CacherPosData, int>;
103+
104+
100105
std::vector<ceph::buffer::list> get_errors(const std::string& start,
101106
const std::string& end,
102107
uint64_t max_return) const;

0 commit comments

Comments
 (0)