Skip to content

Commit b044a96

Browse files
authored
Merge pull request #53062 from xxhdx1985126/wip-seastore-list-objects
crimson/os/seastore: return ghobject_t::max as the end when list_objects reaches the end of the listing Reviewed-by: Yingxin Cheng <[email protected]> Reviewed-by: Chunmei Liu <[email protected]>
2 parents 3a9a5e8 + e989538 commit b044a96

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ FLTreeOnodeManager::list_onodes_ret FLTreeOnodeManager::list_onodes(
134134
const ghobject_t& end,
135135
uint64_t limit)
136136
{
137+
LOG_PREFIX(FLTreeOnodeManager::list_onodes);
138+
DEBUGT("start {}, end {}, limit {}", trans, start, end, limit);
137139
return tree.lower_bound(trans, start
138140
).si_then([this, &trans, end, limit] (auto&& cursor) {
139141
using crimson::os::seastore::onode::full_key_t;
@@ -145,21 +147,28 @@ FLTreeOnodeManager::list_onodes_ret FLTreeOnodeManager::list_onodes(
145147
return trans_intr::repeat(
146148
[this, &trans, end, &to_list, &current_cursor, &ret] ()
147149
-> eagain_ifuture<seastar::stop_iteration> {
150+
LOG_PREFIX(FLTreeOnodeManager::list_onodes);
148151
if (current_cursor.is_end()) {
152+
DEBUGT("reached the onode tree end", trans);
149153
std::get<1>(ret) = ghobject_t::get_max();
150154
return seastar::make_ready_future<seastar::stop_iteration>(
151155
seastar::stop_iteration::yes);
152156
} else if (current_cursor.get_ghobj() >= end) {
157+
DEBUGT("reached the end {} > {}",
158+
trans, current_cursor.get_ghobj(), end);
153159
std::get<1>(ret) = end;
154160
return seastar::make_ready_future<seastar::stop_iteration>(
155161
seastar::stop_iteration::yes);
156162
}
157163
if (to_list == 0) {
164+
DEBUGT("reached the limit", trans);
158165
std::get<1>(ret) = current_cursor.get_ghobj();
159166
return seastar::make_ready_future<seastar::stop_iteration>(
160167
seastar::stop_iteration::yes);
161168
}
162-
std::get<0>(ret).emplace_back(current_cursor.get_ghobj());
169+
auto ghobj = current_cursor.get_ghobj();
170+
DEBUGT("found onode for {}", trans, ghobj);
171+
std::get<0>(ret).emplace_back(std::move(ghobj));
163172
return tree.get_next(trans, current_cursor
164173
).si_then([&to_list, &current_cursor] (auto&& next_cursor) mutable {
165174
// we intentionally hold the current_cursor during get_next() to

src/crimson/os/seastore/seastore.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,14 @@ SeaStore::Shard::list_objects(CollectionRef ch,
688688
std::vector<ghobject_t>(),
689689
ghobject_t::get_max()));
690690
} else {
691+
LOG_PREFIX(SeaStore::list_objects);
692+
DEBUGT("start {}, end {}, limit {}, bits {}",
693+
t, start, end, limit, *bits);
691694
auto filter = SeaStore::get_objs_range(ch, *bits);
692695
using list_iertr = OnodeManager::list_onodes_iertr;
693696
using repeat_ret = list_iertr::future<seastar::stop_iteration>;
694697
return trans_intr::repeat(
695-
[this, &t, &ret, &limit,
698+
[this, &t, &ret, &limit, end,
696699
filter, ranges = get_ranges(ch, start, end, filter)
697700
]() mutable -> repeat_ret {
698701
if (limit == 0 || ranges.empty()) {
@@ -704,9 +707,12 @@ SeaStore::Shard::list_objects(CollectionRef ch,
704707
auto pstart = ite->first;
705708
auto pend = ite->second;
706709
ranges.pop_front();
710+
LOG_PREFIX(SeaStore::list_objects);
711+
DEBUGT("pstart {}, pend {}, limit {}", t, pstart, pend, limit);
707712
return onode_manager->list_onodes(
708713
t, pstart, pend, limit
709-
).si_then([&limit, &ret, pend](auto &&_ret) mutable {
714+
).si_then([&limit, &ret, pend, &t, last=ranges.empty(), end]
715+
(auto &&_ret) mutable {
710716
auto &next_objects = std::get<0>(_ret);
711717
auto &ret_objects = std::get<0>(ret);
712718
ret_objects.insert(
@@ -716,9 +722,15 @@ SeaStore::Shard::list_objects(CollectionRef ch,
716722
std::get<1>(ret) = std::get<1>(_ret);
717723
assert(limit >= next_objects.size());
718724
limit -= next_objects.size();
725+
LOG_PREFIX(SeaStore::list_objects);
726+
DEBUGT("got {} objects, left limit {}",
727+
t, next_objects.size(), limit);
728+
if (last && std::get<1>(ret) == pend) {
729+
std::get<1>(ret) = end;
730+
}
719731
assert(limit == 0 ||
720-
std::get<1>(_ret) == pend ||
721-
std::get<1>(_ret) == ghobject_t::get_max());
732+
std::get<1>(ret) == pend ||
733+
std::get<1>(ret) == ghobject_t::get_max());
722734
return list_iertr::make_ready_future<
723735
seastar::stop_iteration
724736
>(seastar::stop_iteration::no);

src/crimson/os/seastore/seastore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class SeaStore final : public FuturizedStore {
144144
CollectionRef c,
145145
const ghobject_t& oid) final;
146146

147+
/// std::get<1>(ret) returns end if and only if the listing has listed all
148+
/// the items within the range, otherwise it returns the next key to be listed.
147149
seastar::future<std::tuple<std::vector<ghobject_t>, ghobject_t>> list_objects(
148150
CollectionRef c,
149151
const ghobject_t& start,

src/test/crimson/seastore/test_seastore.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ struct seastore_test_t :
592592
EXPECT_GE(next, right_bound);
593593
} else {
594594
// next <= *correct_end since *correct_end is the next object to list
595-
EXPECT_LE(next, *correct_end);
595+
EXPECT_LE(listed.back(), *correct_end);
596596
// next > *(correct_end - 1) since we already listed it
597597
EXPECT_GT(next, *(correct_end - 1));
598598
}

0 commit comments

Comments
 (0)