Writes should block when maximum cache size is reached #25
This commit is contained in:
		@@ -82,7 +82,7 @@ void cache_size_mgr::initialize(app_config *cfg) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
auto cache_size_mgr::shrink(std::uint64_t size) -> api_error {
 | 
					auto cache_size_mgr::shrink(std::uint64_t size) -> api_error {
 | 
				
			||||||
  mutex_lock lock(mtx_);
 | 
					  mutex_lock lock(mtx_);
 | 
				
			||||||
  if (size >= cache_size_) {
 | 
					  if (cache_size_ >= size) {
 | 
				
			||||||
    cache_size_ -= size;
 | 
					    cache_size_ -= size;
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    cache_size_ = 0U;
 | 
					    cache_size_ = 0U;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -499,7 +499,13 @@ auto open_file::close() -> bool {
 | 
				
			|||||||
    return true;
 | 
					    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(
 | 
					    utils::error::raise_api_path_error(
 | 
				
			||||||
        function_name, get_api_path(), fsi_.source_path,
 | 
					        function_name, get_api_path(), fsi_.source_path,
 | 
				
			||||||
        utils::get_last_error_code(), "failed to delete source file");
 | 
					        utils::get_last_error_code(), "failed to delete source file");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user