From 2c727f37fbacbb024077760f3449685ccfb9ece6 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 2 Jul 2021 01:09:16 +0200 Subject: [PATCH] api: Drop sstable index caches on system/drop_sstable_caches --- database.cc | 5 +++++ sstables/sstables.cc | 6 ++++++ sstables/sstables.hh | 3 +++ 3 files changed, 14 insertions(+) diff --git a/database.cc b/database.cc index 13a262827b..d03d1b1a0a 100644 --- a/database.cc +++ b/database.cc @@ -1334,6 +1334,11 @@ database::drop_caches() const { for (auto&& e : tables) { table& t = *e.second; co_await t.get_row_cache().invalidate(row_cache::external_updater([] {})); + + auto sstables = t.get_sstables(); + for (sstables::shared_sstable sst : *sstables) { + co_await sst->drop_caches(); + } } co_return; } diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 126a8983a9..9c0eb90d1b 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -1396,6 +1396,12 @@ future<> sstable::create_data() noexcept { }); } +future<> sstable::drop_caches() { + return _cached_index_file->evict_gently().then([this] { + return _index_cache->evict_gently(); + }); +} + future<> sstable::read_filter(const io_priority_class& pc) { if (!has_component(component_type::Filter)) { _components->filter = std::make_unique(); diff --git a/sstables/sstables.hh b/sstables/sstables.hh index 7012b6fd02..d41800bef6 100644 --- a/sstables/sstables.hh +++ b/sstables/sstables.hh @@ -815,6 +815,9 @@ public: return _origin; } + // Drops all evictable in-memory caches of on-disk content. + future<> drop_caches(); + // Allow the test cases from sstable_test.cc to test private methods. We use // a placeholder to avoid cluttering this class too much. The sstable_test class // will then re-export as public every method it needs.