Skip to content

Commit

Permalink
Merge pull request #10858 from jcsp/22.3.x-cache-minimal
Browse files Browse the repository at this point in the history
[v22.3.x] Cache observability improvements
  • Loading branch information
jcsp committed May 22, 2023
2 parents 0336553 + e54f3db commit b0d7431
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/v/cloud_storage/cache_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ uint64_t cache::get_total_cleaned() { return _total_cleaned; }
ss::future<> cache::consume_cache_space(size_t sz) {
vassert(ss::this_shard_id() == 0, "This method can only run on shard 0");
_current_cache_size += sz;
probe.set_size(_current_cache_size);
if (_current_cache_size > _max_cache_size) {
if (ss::lowres_clock::now() - _last_clean_up > min_clean_up_interval) {
auto units = ss::try_get_units(_cleanup_sm, 1);
Expand Down Expand Up @@ -178,11 +179,14 @@ ss::future<> cache::clean_up_at_start() {
ss::future<> cache::clean_up_cache() {
vassert(ss::this_shard_id() == 0, "Method can only be invoked on shard 0");
gate_guard guard{_gate};

vlog(cst_log.info, "Scanning cache prior to trim...");
auto [current_cache_size, candidates_for_deletion, _]
= co_await _walker.walk(_cache_dir.native(), _access_time_tracker);
_current_cache_size = current_cache_size;
probe.set_size(_current_cache_size);
probe.set_num_files(candidates_for_deletion.size());
auto initial_object_count = candidates_for_deletion.size();
probe.set_num_files(initial_object_count);

// Updating the access time tracker in case if some files were removed
// from cache directory by the user manually.
Expand All @@ -195,6 +199,12 @@ ss::future<> cache::clean_up_cache() {

uint64_t deleted_size = 0;
if (_current_cache_size >= _max_cache_size) {
vlog(
cst_log.info,
"Trimming cache ({} >= {})",
_current_cache_size,
_max_cache_size);

auto size_to_delete
= _current_cache_size
- (_max_cache_size * (long double)_cache_size_low_watermark);
Expand Down Expand Up @@ -270,9 +280,11 @@ ss::future<> cache::clean_up_cache() {
}
_total_cleaned += deleted_size;
_current_cache_size -= deleted_size;
probe.set_size(_current_cache_size);
probe.set_num_files(initial_object_count - i_to_delete);
vlog(
cst_log.debug,
"Cache eviction deleted {} files of total size {}.",
cst_log.info,
"Trimmed cache: deleted {} files of total size {}.",
i_to_delete,
deleted_size);
}
Expand Down

0 comments on commit b0d7431

Please sign in to comment.