Skip to content

Commit 84cb814

Browse files
Merge pull request #21613 from vbotbuildovich/backport-pr-21606-v24.1.x-336
[v24.1.x] cst/cache: fix in mem trim termination condition
2 parents c3845c2 + de5c0c9 commit 84cb814

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/v/cloud_storage/cache_service.cc

+24-8
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ ss::future<> cache::trim(
390390
vlog(
391391
cst_log.debug,
392392
"in-memory trim: set target_size {}/{}, size {}/{}, reserved {}/{}, "
393-
"pending {}/{}), candidates for deletion: {}, size to delete: {}, "
393+
"pending {}/{}, candidates for deletion: {}, size to delete: {}, "
394394
"objects to delete: {}",
395395
target_size,
396396
target_objects,
@@ -428,8 +428,16 @@ ss::future<> cache::trim(
428428
auto undeletable_bytes = (co_await access_time_tracker_size()).value_or(0);
429429

430430
if (
431-
size_to_delete < undeletable_bytes
432-
&& objects_to_delete < undeletable_objects) {
431+
size_to_delete <= undeletable_bytes
432+
&& objects_to_delete <= undeletable_objects) {
433+
vlog(
434+
cst_log.debug,
435+
"in-memory trim finished: size/objects to delete: {}/{}, undeletable "
436+
"size/objects: {}/{}",
437+
size_to_delete,
438+
objects_to_delete,
439+
undeletable_bytes,
440+
undeletable_objects);
433441
_last_clean_up = ss::lowres_clock::now();
434442
_last_trim_failed = false;
435443
co_return;
@@ -465,7 +473,7 @@ ss::future<> cache::trim(
465473
vlog(
466474
cst_log.debug,
467475
"trim: set target_size {}/{}, size {}/{}, walked size {} (max {}/{}), "
468-
" reserved {}/{}, pending {}/{}), candidates for deletion: {}, filtered "
476+
" reserved {}/{}, pending {}/{}, candidates for deletion: {}, filtered "
469477
"out: {}",
470478
target_size,
471479
target_objects,
@@ -482,10 +490,8 @@ ss::future<> cache::trim(
482490
filtered_out_files);
483491

484492
// Sort by atime for the subsequent LRU trimming loop
485-
std::sort(
486-
candidates_for_deletion.begin(),
487-
candidates_for_deletion.end(),
488-
[](auto& a, auto& b) { return a.access_time < b.access_time; });
493+
std::ranges::sort(
494+
candidates_for_deletion, {}, &file_list_item::access_time);
489495

490496
vlog(
491497
cst_log.debug,
@@ -1758,6 +1764,12 @@ ss::future<> cache::do_reserve_space(uint64_t bytes, size_t objects) {
17581764
// do the trim.
17591765
co_await trim_throttled_unlocked();
17601766
did_trim = true;
1767+
} else {
1768+
vlog(
1769+
cst_log.debug,
1770+
"Did not trim, may_trim_now: {}, may_exceed: {}",
1771+
may_trim_now,
1772+
may_exceed);
17611773
}
17621774

17631775
if (!may_reserve_space(bytes, objects)) {
@@ -1768,6 +1780,10 @@ ss::future<> cache::do_reserve_space(uint64_t bytes, size_t objects) {
17681780
if (may_exceed) {
17691781
// Tip off the next caller that they may proactively
17701782
// exceed the cache size without waiting for a trim.
1783+
vlog(
1784+
cst_log.debug,
1785+
"Last trim failed to free up space, will exceed max "
1786+
"bytes");
17711787
_last_trim_failed = true;
17721788
}
17731789
}

0 commit comments

Comments
 (0)