Skip to content

Commit 019a75c

Browse files
committed
osd/SnapMapper: replace omap_get_values by omap_iterate in get_next
Signed-off-by: Chunmei Liu <[email protected]>
1 parent d725a9f commit 019a75c

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

src/osd/SnapMapper.cc

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,42 @@ int OSDriver::get_next(
108108
{
109109
CRIMSON_DEBUG("OSDriver::{} key {}", __func__, key);
110110
using crimson::os::FuturizedStore;
111-
return interruptor::green_get(os->omap_get_values(
112-
ch, hoid, key
113-
).safe_then_unpack([&key, next] (bool, FuturizedStore::Shard::omap_values_t&& vals) {
111+
ObjectStore::omap_iter_seek_t start_from{
112+
key,
113+
ObjectStore::omap_iter_seek_t::UPPER_BOUND
114+
};
115+
std::function<ObjectStore::omap_iter_ret_t(std::string_view, std::string_view)> callback =
116+
[key, next] (std::string_view _key, std::string_view _value)
117+
{
114118
CRIMSON_DEBUG("OSDriver::get_next key {} got omap values", key);
115-
if (auto nit = std::begin(vals);
116-
nit == std::end(vals) || !SnapMapper::is_mapping(nit->first)) {
119+
if (!SnapMapper::is_mapping(std::string(_key))) {
117120
CRIMSON_DEBUG("OSDriver::get_next key {} no more values", key);
118-
return -ENOENT;
121+
return ObjectStore::omap_iter_ret_t::NEXT;
119122
} else {
120-
CRIMSON_DEBUG("OSDriver::get_next returning next: {}, ", nit->first);
121-
ceph_assert(nit->first > key);
122-
*next = *nit;
123-
return 0;
123+
CRIMSON_DEBUG("OSDriver::get_next returning next: {}, ", _key);
124+
ceph_assertf(_key > key,
125+
"Key order violation: input_key='%s' got_key='%s'",
126+
key.c_str(), std::string(_key).c_str());
127+
ceph::bufferlist bl;
128+
bl.append(_value);
129+
*next = std::make_pair(_key, bl);
130+
return ObjectStore::omap_iter_ret_t::STOP;
124131
}
125-
}, FuturizedStore::Shard::read_errorator::all_same_way([] {
126-
CRIMSON_DEBUG("OSDriver::get_next saw error returning EINVAL");
127-
return -EINVAL;
128-
}))); // this requires seastar::thread
132+
};
133+
return interruptor::green_get(
134+
os->omap_iterate(ch, hoid, start_from, callback
135+
).safe_then([key] (auto ret) {
136+
if (ret == ObjectStore::omap_iter_ret_t::NEXT) {
137+
CRIMSON_DEBUG("OSDriver::get_next key {} no more values", key);
138+
return -ENOENT;
139+
}
140+
return 0; // found and Stopped
141+
}, FuturizedStore::Shard::read_errorator::all_same_way([] {
142+
CRIMSON_DEBUG("OSDriver::get_next saw error returning EINVAL");
143+
return -EINVAL;
144+
})
145+
)
146+
); // this requires seastar::thread
129147
}
130148

131149
int OSDriver::get_next_or_current(

0 commit comments

Comments
 (0)