fix race in operations with external temporary data in cache

This commit is contained in:
Anton Popov 2023-12-18 20:02:20 +00:00
parent bd17ee769e
commit 27d632f5e4
2 changed files with 10 additions and 1 deletions

View File

@ -352,7 +352,10 @@ CacheMetadata::removeEmptyKey(
try
{
if (fs::exists(key_directory))
{
fs::remove_all(key_directory);
LOG_TEST(log, "Directory ({}) for key {} removed", key_directory.string(), key);
}
}
catch (...)
{
@ -365,7 +368,10 @@ CacheMetadata::removeEmptyKey(
{
std::unique_lock mutex(key_prefix_directory_mutex);
if (fs::exists(key_prefix_directory) && fs::is_empty(key_prefix_directory))
{
fs::remove(key_prefix_directory);
LOG_TEST(log, "Prefix directory ({}) for key {} removed", key_prefix_directory.string(), key);
}
}
catch (...)
{

View File

@ -106,7 +106,10 @@ FileSegmentsHolderPtr TemporaryDataOnDisk::createCacheFile(size_t max_file_size)
const auto key = FileSegment::Key::random();
auto holder = file_cache->set(key, 0, std::max(10_MiB, max_file_size), CreateFileSegmentSettings(FileSegmentKind::Temporary, /* unbounded */ true));
fs::create_directories(file_cache->getPathInLocalCache(key));
chassert(holder->size() == 1);
holder->back().getKeyMetadata()->createBaseDirectory();
return holder;
}