diff options
Diffstat (limited to 'src/zenserver/cache/cachedisklayer.cpp')
| -rw-r--r-- | src/zenserver/cache/cachedisklayer.cpp | 71 |
1 files changed, 60 insertions, 11 deletions
diff --git a/src/zenserver/cache/cachedisklayer.cpp b/src/zenserver/cache/cachedisklayer.cpp index af8b6227b..6ab3c7746 100644 --- a/src/zenserver/cache/cachedisklayer.cpp +++ b/src/zenserver/cache/cachedisklayer.cpp @@ -54,6 +54,13 @@ namespace { #pragma pack(pop) + template<typename T> + void Reset(T& V) + { + T Tmp; + V.swap(Tmp); + } + const char* IndexExtension = ".uidx"; const char* LogExtension = ".slog"; @@ -2367,6 +2374,7 @@ public: { Stopwatch Timer; const auto _ = MakeGuard([&] { + Reset(m_ExpiredStandaloneKeys); if (!Ctx.Settings.Verbose) { return; @@ -2384,6 +2392,10 @@ public: ExtendablePathBuilder<256> Path; for (const std::pair<IoHash, uint64_t>& ExpiredKey : m_ExpiredStandaloneKeys) { + if (Ctx.IsCancelledFlag.load()) + { + return; + } Path.Reset(); m_Bucket.BuildPath(Path, ExpiredKey.first); fs::path FilePath = Path.ToPath(); @@ -2543,6 +2555,11 @@ public: } m_Bucket.m_SlogFile.Append(MovedEntries); Stats.RemovedDisk += FreedDiskSpace; + if (Ctx.IsCancelledFlag.load()) + { + return false; + } + return true; }, ClaimDiskReserveCallback); } @@ -2558,7 +2575,6 @@ public: } } } - m_ExpiredStandaloneKeys.clear(); } private: @@ -2593,6 +2609,11 @@ ZenCacheDiskLayer::CacheBucket::RemoveExpiredData(GcCtx& Ctx, GcStats& Stats) uint64_t RemovedStandaloneSize = 0; { RwLock::ExclusiveLockScope IndexLock(m_IndexLock); + if (Ctx.IsCancelledFlag.load()) + { + return nullptr; + } + TotalEntries = m_Index.size(); // Find out expired keys @@ -2625,6 +2646,11 @@ ZenCacheDiskLayer::CacheBucket::RemoveExpiredData(GcCtx& Ctx, GcStats& Stats) Stats.CheckedCount += TotalEntries; Stats.FoundCount += ExpiredEntries.size(); + if (Ctx.IsCancelledFlag.load()) + { + return nullptr; + } + if (Ctx.Settings.IsDeleteMode) { for (const DiskIndexEntry& Entry : ExpiredEntries) @@ -2656,6 +2682,11 @@ ZenCacheDiskLayer::CacheBucket::RemoveExpiredData(GcCtx& Ctx, GcStats& Stats) } } + if (Ctx.IsCancelledFlag.load()) + { + return nullptr; + } + return new DiskBucketStoreCompactor(*this, std::move(ExpiredStandaloneKeys)); } @@ -2689,10 +2720,23 @@ public: }); m_IndexLock = std::make_unique<RwLock::SharedLockScope>(m_CacheBucket.m_IndexLock); + if (Ctx.IsCancelledFlag.load()) + { + m_UncachedReferences.clear(); + m_IndexLock.reset(); + return; + } // Rescan to see if any cache items needs refreshing since last pass when we had the lock for (const auto& Entry : m_CacheBucket.m_Index) { + if (Ctx.IsCancelledFlag.load()) + { + m_UncachedReferences.clear(); + m_IndexLock.reset(); + return; + } + size_t PayloadIndex = Entry.second; const ZenCacheDiskLayer::CacheBucket::BucketPayload& Payload = m_CacheBucket.m_Payloads[PayloadIndex]; const DiskLocation& Loc = Payload.Location; @@ -2782,6 +2826,11 @@ ZenCacheDiskLayer::CacheBucket::CreateReferenceCheckers(GcCtx& Ctx) RwLock::SharedLockScope IndexLock(m_IndexLock); for (const auto& Entry : m_Index) { + if (Ctx.IsCancelledFlag.load()) + { + return {}; + } + size_t PayloadIndex = Entry.second; const ZenCacheDiskLayer::CacheBucket::BucketPayload& Payload = m_Payloads[PayloadIndex]; const DiskLocation& Loc = Payload.Location; @@ -2821,6 +2870,11 @@ ZenCacheDiskLayer::CacheBucket::CreateReferenceCheckers(GcCtx& Ctx) { for (const IoHash& Key : StandaloneKeys) { + if (Ctx.IsCancelledFlag.load()) + { + return {}; + } + IoBuffer Buffer = GetStandaloneCacheValue(ZenContentType::kCbObject, Key); if (!Buffer) { @@ -3047,12 +3101,9 @@ void ZenCacheDiskLayer::CacheBucket::ClearReferenceCache() { RwLock::ExclusiveLockScope IndexLock(m_IndexLock); - m_FirstReferenceIndex.clear(); - m_FirstReferenceIndex.shrink_to_fit(); - m_ReferenceHashes.clear(); - m_ReferenceHashes.shrink_to_fit(); - m_NextReferenceHashesIndexes.clear(); - m_NextReferenceHashesIndexes.shrink_to_fit(); + Reset(m_FirstReferenceIndex); + Reset(m_ReferenceHashes); + Reset(m_NextReferenceHashesIndexes); m_ReferenceCount = 0; } @@ -3099,11 +3150,9 @@ ZenCacheDiskLayer::CacheBucket::CompactState(std::vector<BucketPayload>& Payloa m_Payloads.swap(Payloads); m_AccessTimes.swap(AccessTimes); m_MetaDatas.swap(MetaDatas); - m_FreeMetaDatas.clear(); - m_FreeMetaDatas.shrink_to_fit(); + Reset(m_FreeMetaDatas); m_MemCachedPayloads.swap(MemCachedPayloads); - m_FreeMemCachedPayloads.clear(); - m_FreeMetaDatas.shrink_to_fit(); + Reset(m_FreeMemCachedPayloads); if (m_Configuration.EnableReferenceCaching) { m_FirstReferenceIndex.swap(FirstReferenceIndex); |