Skip to content

Commit

Permalink
cst/cache: Remove tmp file on put failure
Browse files Browse the repository at this point in the history
  • Loading branch information
nvartolomei committed Nov 4, 2024
1 parent dfeff1b commit d63c50c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/v/cloud_storage/cache_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,19 @@ ss::future<> cache::put(
eptr = std::current_exception();
}

// If we failed to write to the tmp file, we should delete it, maybe do an
// eager trim, and rethrow the exception.
if (eptr) {
try {
co_await delete_file_and_empty_parents(tmp_filepath.native());
} catch (...) {
vlog(
cst_log.error,
"Failed to delete tmp file {}: {}",
tmp_filepath.native(),
std::current_exception());
}

if (no_space_on_device) {
vlog(cst_log.error, "Out of space while writing to cache");

Expand Down
4 changes: 1 addition & 3 deletions src/v/cloud_storage/tests/cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,8 @@ FIXTURE_TEST(test_clean_up_on_stream_exception, cache_test_fixture) {
BOOST_CHECK_EQUAL(sharded_cache.local().get_usage_bytes(), 0);
BOOST_CHECK_EQUAL(sharded_cache.local().get_usage_objects(), 0);

// TODO: This is not expected behavior. The temporary file should be cleaned
// up on exception.
vlog(test_log.info, "Counting files in cache directory");
BOOST_CHECK_EQUAL(count_files(CACHE_DIR.native()).get(), 1);
BOOST_CHECK_EQUAL(count_files(CACHE_DIR.native()).get(), 0);

vlog(test_log.info, "Test passed");
}
Expand Down

0 comments on commit d63c50c

Please sign in to comment.