diff options
| author | Dan Engelbrecht <[email protected]> | 2022-06-14 15:34:06 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-06-14 15:34:06 +0200 |
| commit | 304bb51b305e10cf2dc1fdda0bba0dec2bd19b2b (patch) | |
| tree | 1fa261770f0d4014775858f246f473f13ce79206 /zenserver/cache/structuredcachestore.cpp | |
| parent | small cleanup (diff) | |
| download | zen-304bb51b305e10cf2dc1fdda0bba0dec2bd19b2b.tar.xz zen-304bb51b305e10cf2dc1fdda0bba0dec2bd19b2b.zip | |
review feedback
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 7bcd7b06a..4be33170c 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -1315,10 +1315,8 @@ ZenCacheDiskLayer::CacheBucket::Scrub(ScrubContext& Ctx) auto ValidateEntry = [](ZenContentType ContentType, IoBuffer Buffer) { if (ContentType == ZenContentType::kCbObject) { - if (CbValidateError Error = ValidateCompactBinary(Buffer, CbValidateMode::All); Error != CbValidateError::None) - { - return false; - } + CbValidateError Error = ValidateCompactBinary(Buffer, CbValidateMode::All); + return Error == CbValidateError::None; } if (ContentType == ZenContentType::kCompressedBinary) { @@ -1332,7 +1330,7 @@ ZenCacheDiskLayer::CacheBucket::Scrub(ScrubContext& Ctx) RwLock::SharedLockScope _(m_IndexLock); - size_t BlockChunkInitialCount = m_Index.size() / 4; + const size_t BlockChunkInitialCount = m_Index.size() / 4; ChunkLocations.reserve(BlockChunkInitialCount); ChunkIndexToChunkHash.reserve(BlockChunkInitialCount); @@ -1382,44 +1380,45 @@ ZenCacheDiskLayer::CacheBucket::Scrub(ScrubContext& Ctx) } } - m_BlockStore.IterateChunks( - ChunkLocations, - [&](size_t ChunkIndex, const void* Data, uint64_t Size) { - const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex]; - if (!Data) - { - // ChunkLocation out of range of stored blocks - BadKeys.push_back(Hash); - return; - } - IoBuffer Buffer(IoBuffer::Wrap, Data, Size); - if (!Buffer) - { - BadKeys.push_back(Hash); - return; - } - ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType(); - if (!ValidateEntry(ContentType, Buffer)) - { - BadKeys.push_back(Hash); - return; - } - }, - [&](size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size) { - const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex]; - IoBuffer Buffer(IoBuffer::BorrowedFile, File.GetBasicFile().Handle(), Offset, Size); - if (!Buffer) - { - BadKeys.push_back(Hash); - return; - } - ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType(); - if (!ValidateEntry(ContentType, Buffer)) - { - BadKeys.push_back(Hash); - return; - } - }); + const auto ValidateSmallChunk = [&](size_t ChunkIndex, const void* Data, uint64_t Size) { + const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex]; + if (!Data) + { + // ChunkLocation out of range of stored blocks + BadKeys.push_back(Hash); + return; + } + IoBuffer Buffer(IoBuffer::Wrap, Data, Size); + if (!Buffer) + { + BadKeys.push_back(Hash); + return; + } + ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType(); + if (!ValidateEntry(ContentType, Buffer)) + { + BadKeys.push_back(Hash); + return; + } + }; + + const auto ValidateLargeChunk = [&](size_t ChunkIndex, BlockStoreFile& File, uint64_t Offset, uint64_t Size) { + const IoHash& Hash = ChunkIndexToChunkHash[ChunkIndex]; + IoBuffer Buffer(IoBuffer::BorrowedFile, File.GetBasicFile().Handle(), Offset, Size); + if (!Buffer) + { + BadKeys.push_back(Hash); + return; + } + ZenContentType ContentType = m_Index.at(Hash).Location.GetContentType(); + if (!ValidateEntry(ContentType, Buffer)) + { + BadKeys.push_back(Hash); + return; + } + }; + + m_BlockStore.IterateChunks(ChunkLocations, ValidateSmallChunk, ValidateLargeChunk); _.ReleaseNow(); |