diff --git a/sstables/sstables_manager.cc b/sstables/sstables_manager.cc index 06fd44d639..cd6d4d5a63 100644 --- a/sstables/sstables_manager.cc +++ b/sstables/sstables_manager.cc @@ -227,15 +227,25 @@ future<> sstables_manager::components_reloader_fiber() { } } +void sstables_manager::reclaim_memory_and_stop_tracking_sstable(sstable* sst) { + // remove the sstable from the memory tracking metrics + _total_reclaimable_memory -= sst->total_reclaimable_memory_size(); + _total_memory_reclaimed -= sst->total_memory_reclaimed(); + // reclaim any remaining memory from the sstable + sst->reclaim_memory_from_components(); + // disable further reload of components + _reclaimed.erase(*sst); + sst->disable_component_memory_reload(); +} + void sstables_manager::add(sstable* sst) { _active.push_back(*sst); } void sstables_manager::deactivate(sstable* sst) { - // Remove SSTable from the reclaimable memory tracking - _total_reclaimable_memory -= sst->total_reclaimable_memory_size(); - _total_memory_reclaimed -= sst->total_memory_reclaimed(); - _reclaimed.erase(*sst); + // Drop reclaimable components if they are still in memory + // and remove SSTable from the reclaimable memory tracking + reclaim_memory_and_stop_tracking_sstable(sst); // At this point, sst has a reference count of zero, since we got here from // lw_shared_ptr_deleter::dispose(). diff --git a/sstables/sstables_manager.hh b/sstables/sstables_manager.hh index e792f7e2a9..d861b9240d 100644 --- a/sstables/sstables_manager.hh +++ b/sstables/sstables_manager.hh @@ -219,6 +219,10 @@ private: // Fiber to reload reclaimed components back into memory when memory becomes available. future<> components_reloader_fiber(); size_t get_memory_available_for_reclaimable_components(); + // Reclaim memory from the SSTable and remove it from the memory tracking metrics. + // The method is idempotent and for an sstable that is deleted, it is called both + // during unlink and during deactivation. + void reclaim_memory_and_stop_tracking_sstable(sstable* sst); private: db::large_data_handler& get_large_data_handler() const { return _large_data_handler;