diff options
| author | Dan Engelbrecht <[email protected]> | 2023-10-23 09:36:34 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-23 09:36:34 +0200 |
| commit | ae72900ee97c8f31ca97ef8ba11b1c8ed8d20363 (patch) | |
| tree | 91557db49285e5f72e8ec774d53f1dc23f0336c9 /src/zenserver/cache | |
| parent | typedef for std streaming to StringBuilder (diff) | |
| download | zen-ae72900ee97c8f31ca97ef8ba11b1c8ed8d20363.tar.xz zen-ae72900ee97c8f31ca97ef8ba11b1c8ed8d20363.zip | |
Filter expired cache entries against ExpiredKeys - not CAS entries to retain (#491)
Diffstat (limited to 'src/zenserver/cache')
| -rw-r--r-- | src/zenserver/cache/cachedisklayer.cpp | 63 |
1 files changed, 23 insertions, 40 deletions
diff --git a/src/zenserver/cache/cachedisklayer.cpp b/src/zenserver/cache/cachedisklayer.cpp index 3cd725a27..aeea779fb 100644 --- a/src/zenserver/cache/cachedisklayer.cpp +++ b/src/zenserver/cache/cachedisklayer.cpp @@ -1508,17 +1508,6 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) m_SlogFile.Flush(); - std::span<const IoHash> ExpiredCacheKeys = GcCtx.ExpiredCacheKeys(m_BucketDir.string()); - std::vector<IoHash> DeleteCacheKeys; - DeleteCacheKeys.reserve(ExpiredCacheKeys.size()); - GcCtx.FilterCids(ExpiredCacheKeys, [&](const IoHash& ChunkHash, bool Keep) { - if (Keep) - { - return; - } - DeleteCacheKeys.push_back(ChunkHash); - }); - auto __ = MakeGuard([&]() { if (!DeletedChunks.empty()) { @@ -1569,6 +1558,9 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) } }); + std::span<const IoHash> ExpiredCacheKeySpan = GcCtx.ExpiredCacheKeys(m_BucketDir.string()); + std::unordered_set<IoHash, IoHash::Hasher> ExpiredCacheKeys(ExpiredCacheKeySpan.begin(), ExpiredCacheKeySpan.end()); + std::vector<DiskIndexEntry> ExpiredStandaloneEntries; IndexMap Index; std::vector<BucketPayload> Payloads; @@ -1600,7 +1592,7 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) AccessTimes = m_AccessTimes; Index = m_Index; - for (const IoHash& Key : DeleteCacheKeys) + for (const IoHash& Key : ExpiredCacheKeys) { if (auto It = Index.find(Key); It != Index.end()) { @@ -1704,43 +1696,34 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) TotalChunkCount = Index.size(); - std::vector<IoHash> TotalChunkHashes; - TotalChunkHashes.reserve(TotalChunkCount); - { - for (const auto& Entry : Index) - { - const DiskLocation& Location = Payloads[Entry.second].Location; - - if (Location.Flags & DiskLocation::kStandaloneFile) - { - continue; - } - TotalChunkHashes.push_back(Entry.first); - } - } - - TotalChunkCount = TotalChunkHashes.size(); - std::vector<BlockStoreLocation> ChunkLocations; BlockStore::ChunkIndexArray KeepChunkIndexes; std::vector<IoHash> ChunkIndexToChunkHash; ChunkLocations.reserve(TotalChunkCount); ChunkLocations.reserve(TotalChunkCount); ChunkIndexToChunkHash.reserve(TotalChunkCount); - - GcCtx.FilterCids(TotalChunkHashes, [&](const IoHash& ChunkHash, bool Keep) { - auto KeyIt = Index.find(ChunkHash); - const DiskLocation& DiskLocation = Payloads[KeyIt->second].Location; - BlockStoreLocation Location = DiskLocation.GetBlockLocation(m_PayloadAlignment); - size_t ChunkIndex = ChunkLocations.size(); - ChunkLocations.push_back(Location); - ChunkIndexToChunkHash[ChunkIndex] = ChunkHash; - if (Keep) + { + TotalChunkCount = 0; + for (const auto& Entry : Index) { + const DiskLocation& DiskLocation = Payloads[Entry.second].Location; + + if (DiskLocation.Flags & DiskLocation::kStandaloneFile) + { + continue; + } + BlockStoreLocation Location = DiskLocation.GetBlockLocation(m_PayloadAlignment); + size_t ChunkIndex = ChunkLocations.size(); + ChunkLocations.push_back(Location); + ChunkIndexToChunkHash[ChunkIndex] = Entry.first; + if (ExpiredCacheKeys.contains(Entry.first)) + { + continue; + } KeepChunkIndexes.push_back(ChunkIndex); } - }); - + } + TotalChunkCount = ChunkLocations.size(); size_t DeleteCount = TotalChunkCount - KeepChunkIndexes.size(); const bool PerformDelete = GcCtx.IsDeletionMode() && GcCtx.CollectSmallObjects(); |