Skip to content

Commit

Permalink
cloud_storage: minimal cache observability fixes
Browse files Browse the repository at this point in the history
- Update size+count stats continuously, not just
  at the beginning of trim.
- Log info-level messages at start+end of trim.
  • Loading branch information
jcsp committed May 18, 2023
1 parent b412a64 commit 4231293
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 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,16 @@ 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 +201,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 +282,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 4231293

Please sign in to comment.