Skip to content

Commit 8456a55

Browse files
bhalevyavikivity
authored andcommitted
memtable_list: clear_and_add: let caller clear the old memtables
As a follow up on b8263e5, make clear_and_add synchronous yet again, and just return the swapped list of memtables so that the caller (table::clear) can clear them gently. Refs scylladb#10424 (comment) Signed-off-by: Benny Halevy <[email protected]> Closes scylladb#10540
1 parent 66086a1 commit 8456a55

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

replica/database.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,17 +1593,12 @@ lw_shared_ptr<memtable> memtable_list::new_memtable() {
15931593
}
15941594

15951595
// Synchronously swaps the active memtable with a new, empty one,
1596-
// then, clears the existing memtable(s) asynchronously.
1596+
// returning the old memtables list.
15971597
// Exception safe.
1598-
future<> memtable_list::clear_and_add() {
1598+
std::vector<replica::shared_memtable> memtable_list::clear_and_add() {
15991599
std::vector<replica::shared_memtable> new_memtables;
16001600
new_memtables.emplace_back(new_memtable());
1601-
auto old_memtables = std::exchange(_memtables, std::move(new_memtables));
1602-
// Now that the existing _memtables vector is swapped with new_memtables
1603-
// the function can yield for clearing the old_memtables.
1604-
for (auto& smt : old_memtables) {
1605-
co_await smt->clear_gently();
1606-
}
1601+
return std::exchange(_memtables, std::move(new_memtables));
16071602
}
16081603

16091604
} // namespace replica

replica/database.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ public:
221221
}
222222

223223
// Synchronously swaps the active memtable with a new, empty one,
224-
// then, clears the existing memtable(s) asynchronously.
224+
// returning the old memtables list.
225225
// Exception safe.
226-
future<> clear_and_add();
226+
std::vector<replica::shared_memtable> clear_and_add();
227227

228228
size_t size() const {
229229
return _memtables.size();

replica/table.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,10 @@ future<> table::clear() {
15131513
_commitlog->discard_completed_segments(_schema->id(), t->get_and_discard_rp_set());
15141514
}
15151515
}
1516-
co_await _memtables->clear_and_add();
1516+
auto old_memtables = _memtables->clear_and_add();
1517+
for (auto& smt : old_memtables) {
1518+
co_await smt->clear_gently();
1519+
}
15171520
co_await _cache.invalidate(row_cache::external_updater([] { /* There is no underlying mutation source */ }));
15181521
}
15191522

0 commit comments

Comments
 (0)