From a04593b9b10661c9b650d2c0dff679542e82bf65 Mon Sep 17 00:00:00 2001 From: Abhijat Malviya Date: Wed, 24 Jul 2024 13:41:58 +0530 Subject: [PATCH 1/2] cst/cache: Fix trim terminate condition At the end of an in-memory trim if the size to delete is equal to or less than undeletable bytes the trim should finish, because further trimming will not result in extra space being freed up. (cherry picked from commit a8594fee1144f236842efffaa75786d84e2329d7) --- src/v/cloud_storage/cache_service.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/v/cloud_storage/cache_service.cc b/src/v/cloud_storage/cache_service.cc index 66a2c9184b9b9..14e3191d30d3c 100644 --- a/src/v/cloud_storage/cache_service.cc +++ b/src/v/cloud_storage/cache_service.cc @@ -428,8 +428,8 @@ ss::future<> cache::trim( auto undeletable_bytes = (co_await access_time_tracker_size()).value_or(0); if ( - size_to_delete < undeletable_bytes - && objects_to_delete < undeletable_objects) { + size_to_delete <= undeletable_bytes + && objects_to_delete <= undeletable_objects) { _last_clean_up = ss::lowres_clock::now(); _last_trim_failed = false; co_return; From de5c0c9509e8ca51605efe3f0400fdd0a5b921e1 Mon Sep 17 00:00:00 2001 From: Abhijat Malviya Date: Wed, 24 Jul 2024 14:19:20 +0530 Subject: [PATCH 2/2] cst/cache: Adds logs (cherry picked from commit 1fe047d82d8a057a92a0266d428abe85533bad41) --- src/v/cloud_storage/cache_service.cc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/v/cloud_storage/cache_service.cc b/src/v/cloud_storage/cache_service.cc index 14e3191d30d3c..2e178796134ea 100644 --- a/src/v/cloud_storage/cache_service.cc +++ b/src/v/cloud_storage/cache_service.cc @@ -390,7 +390,7 @@ ss::future<> cache::trim( vlog( cst_log.debug, "in-memory trim: set target_size {}/{}, size {}/{}, reserved {}/{}, " - "pending {}/{}), candidates for deletion: {}, size to delete: {}, " + "pending {}/{}, candidates for deletion: {}, size to delete: {}, " "objects to delete: {}", target_size, target_objects, @@ -430,6 +430,14 @@ ss::future<> cache::trim( if ( size_to_delete <= undeletable_bytes && objects_to_delete <= undeletable_objects) { + vlog( + cst_log.debug, + "in-memory trim finished: size/objects to delete: {}/{}, undeletable " + "size/objects: {}/{}", + size_to_delete, + objects_to_delete, + undeletable_bytes, + undeletable_objects); _last_clean_up = ss::lowres_clock::now(); _last_trim_failed = false; co_return; @@ -465,7 +473,7 @@ ss::future<> cache::trim( vlog( cst_log.debug, "trim: set target_size {}/{}, size {}/{}, walked size {} (max {}/{}), " - " reserved {}/{}, pending {}/{}), candidates for deletion: {}, filtered " + " reserved {}/{}, pending {}/{}, candidates for deletion: {}, filtered " "out: {}", target_size, target_objects, @@ -482,10 +490,8 @@ ss::future<> cache::trim( filtered_out_files); // Sort by atime for the subsequent LRU trimming loop - std::sort( - candidates_for_deletion.begin(), - candidates_for_deletion.end(), - [](auto& a, auto& b) { return a.access_time < b.access_time; }); + std::ranges::sort( + candidates_for_deletion, {}, &file_list_item::access_time); vlog( cst_log.debug, @@ -1758,6 +1764,12 @@ ss::future<> cache::do_reserve_space(uint64_t bytes, size_t objects) { // do the trim. co_await trim_throttled_unlocked(); did_trim = true; + } else { + vlog( + cst_log.debug, + "Did not trim, may_trim_now: {}, may_exceed: {}", + may_trim_now, + may_exceed); } if (!may_reserve_space(bytes, objects)) { @@ -1768,6 +1780,10 @@ ss::future<> cache::do_reserve_space(uint64_t bytes, size_t objects) { if (may_exceed) { // Tip off the next caller that they may proactively // exceed the cache size without waiting for a trim. + vlog( + cst_log.debug, + "Last trim failed to free up space, will exceed max " + "bytes"); _last_trim_failed = true; } }