diff --git a/src/Interpreters/Cache/FileCache.cpp b/src/Interpreters/Cache/FileCache.cpp index 0c4f813c8fe..3360c6e3a48 100644 --- a/src/Interpreters/Cache/FileCache.cpp +++ b/src/Interpreters/Cache/FileCache.cpp @@ -1023,7 +1023,7 @@ void FileCache::loadMetadataForKeys(const fs::path & keys_dir) if (limits_satisfied) { - KeyMetadata::iterator file_segment_metadata_it; + bool inserted = false; try { auto file_segment = std::make_shared(key, offset, size, @@ -1033,21 +1033,20 @@ void FileCache::loadMetadataForKeys(const fs::path & keys_dir) key_metadata, cache_it); - auto [_, inserted] = key_metadata->emplace(offset, std::make_shared(std::move(file_segment))); - if (!inserted) - { - cache_it->remove(lockCache()); - chassert(false); - } + inserted = key_metadata->emplace(offset, std::make_shared(std::move(file_segment))).second; + } catch (...) { tryLogCurrentException(__PRETTY_FUNCTION__); chassert(false); + } + if (!inserted) + { cache_it->remove(lockCache()); fs::remove(offset_it->path()); - continue; + chassert(false); } } else