Writes should block when maximum cache size is reached #25

This commit is contained in:
Scott E. Graves 2024-12-18 13:51:16 -06:00
parent 9961cb700e
commit 80fd52625e
2 changed files with 8 additions and 2 deletions

View File

@ -82,7 +82,7 @@ void cache_size_mgr::initialize(app_config *cfg) {
auto cache_size_mgr::shrink(std::uint64_t size) -> api_error {
mutex_lock lock(mtx_);
if (size >= cache_size_) {
if (cache_size_ >= size) {
cache_size_ -= size;
} else {
cache_size_ = 0U;

View File

@ -499,7 +499,13 @@ auto open_file::close() -> bool {
return true;
}
if (not utils::file::file(fsi_.source_path).remove()) {
auto file = utils::file::file{fsi_.source_path};
if (file.remove()) {
err = cache_size_mgr::instance().shrink(file.size().value_or(0U));
if (err != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, err,
} "failed to shrink cache");
} else {
utils::error::raise_api_path_error(
function_name, get_api_path(), fsi_.source_path,
utils::get_last_error_code(), "failed to delete source file");