Merge pull request #54985 from kssenii/add-assertion-in-desctructor

Add assertion
This commit is contained in:
Kseniia Sumarokova 2023-09-26 12:24:03 +02:00 committed by GitHub
commit 745673181e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View File

@ -1059,6 +1059,9 @@ void FileCache::loadMetadataForKeys(const fs::path & keys_dir)
FileCache::~FileCache()
{
deactivateBackgroundOperations();
#ifdef ABORT_ON_LOGICAL_ERROR
assertCacheCorrectness();
#endif
}
void FileCache::deactivateBackgroundOperations()
@ -1143,14 +1146,15 @@ size_t FileCache::getFileSegmentsNum() const
void FileCache::assertCacheCorrectness()
{
auto lock = lockCache();
main_priority->iterate([&](LockedKey &, const FileSegmentMetadataPtr & segment_metadata)
metadata.iterate([&](LockedKey & locked_key)
{
const auto & file_segment = *segment_metadata->file_segment;
UNUSED(file_segment);
chassert(file_segment.assertCorrectness());
return PriorityIterationResult::CONTINUE;
}, lock);
for (const auto & [_, file_segment_metadata] : locked_key)
{
const auto & file_segment = *file_segment_metadata->file_segment;
UNUSED(file_segment);
chassert(file_segment.assertCorrectness());
}
});
}
FileCache::QueryContextHolder::QueryContextHolder(

View File

@ -362,12 +362,6 @@ public:
return;
inserted = keys.insert(key).second;
}
/// There is an invariant that key cannot be submitted for removal if it is already in removal queue.
/// Because
/// 1) when submit key to removal it acquires state REMOVING and we submit key for removal only if it has ACTIVE state.
/// 2) if a key is added to cache and it was found in removal queue - it will be removed from the queue and get state ACTIVE.
/// and both these actions are synchronized by the same KeyGuard.
chassert(inserted);
if (inserted)
{
CurrentMetrics::add(CurrentMetrics::FilesystemCacheDelayedCleanupElements);