Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v24.1.x] cst/cache: fix in mem trim termination condition #21613

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/v/cloud_storage/cache_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -428,8 +428,16 @@ 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) {
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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
}
Expand Down
Loading