diff options
| author | Stefan Boberg <[email protected]> | 2021-10-18 09:10:07 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-18 09:10:07 +0200 |
| commit | 94efab8e5c00f4b552946d8c1bdc69453020f888 (patch) | |
| tree | df312c80719590c847253e952ea27322187b2d88 | |
| parent | structured cache: Implemented GarbageCollect() for disk and memory buckets (diff) | |
| download | zen-94efab8e5c00f4b552946d8c1bdc69453020f888.tar.xz zen-94efab8e5c00f4b552946d8c1bdc69453020f888.zip | |
gc: moved GcContect from CAS into gc files
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 8 | ||||
| -rw-r--r-- | zenstore/CAS.cpp | 28 | ||||
| -rw-r--r-- | zenstore/gc.cpp | 31 | ||||
| -rw-r--r-- | zenstore/include/zenstore/CAS.h | 20 | ||||
| -rw-r--r-- | zenstore/include/zenstore/gc.h | 21 |
5 files changed, 61 insertions, 47 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index e7b840ed8..15f7b5a7a 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -15,6 +15,7 @@ #include <zenstore/basicfile.h> #include <zenstore/cas.h> #include <zenstore/caslog.h> +#include <zenstore/gc.h> #include <concepts> #include <filesystem> @@ -1050,7 +1051,12 @@ ZenCacheDiskLayer::Scrub(ScrubContext& Ctx) void ZenCacheDiskLayer::GarbageCollect(GcContext& GcCtx) { - ZEN_UNUSED(GcCtx); + RwLock::SharedLockScope _(m_Lock); + + for (auto& Kv : m_Buckets) + { + Kv.second.GarbageCollect(GcCtx); + } } } // namespace zen diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp index a4bbfa340..807bba3b3 100644 --- a/zenstore/CAS.cpp +++ b/zenstore/CAS.cpp @@ -67,34 +67,6 @@ CasChunkSet::IterateChunks(std::function<void(const IoHash& ChunkHash)>&& Callba ////////////////////////////////////////////////////////////////////////// -struct GcContext::GcState -{ - CasChunkSet m_CasChunks; - CasChunkSet m_CidChunks; -}; - -GcContext::GcContext() : m_State(std::make_unique<GcState>()) -{ -} - -GcContext::~GcContext() -{ -} - -void -GcContext::ContributeCids(std::span<const IoHash> Cids) -{ - m_State->m_CidChunks.AddChunksToSet(Cids); -} - -void -GcContext::ContributeCas(std::span<const IoHash> Cas) -{ - m_State->m_CasChunks.AddChunksToSet(Cas); -} - -////////////////////////////////////////////////////////////////////////// - void ScrubContext::ReportBadCasChunks(std::span<IoHash> BadCasChunks) { diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index bfb8f015e..e7c8f3a1a 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -1,9 +1,40 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include <zenstore/gc.h> +#include <zenstore/CAS.h> namespace zen { +////////////////////////////////////////////////////////////////////////// + +struct GcContext::GcState +{ + CasChunkSet m_CasChunks; + CasChunkSet m_CidChunks; +}; + +GcContext::GcContext() : m_State(std::make_unique<GcState>()) +{ +} + +GcContext::~GcContext() +{ +} + +void +GcContext::ContributeCids(std::span<const IoHash> Cids) +{ + m_State->m_CidChunks.AddChunksToSet(Cids); +} + +void +GcContext::ContributeCas(std::span<const IoHash> Cas) +{ + m_State->m_CasChunks.AddChunksToSet(Cas); +} + +////////////////////////////////////////////////////////////////////////// + CasGc::CasGc(CasStore& Store) : m_CasStore(Store) { } diff --git a/zenstore/include/zenstore/CAS.h b/zenstore/include/zenstore/CAS.h index 86e7e78d9..dc7e260ab 100644 --- a/zenstore/include/zenstore/CAS.h +++ b/zenstore/include/zenstore/CAS.h @@ -19,6 +19,8 @@ namespace zen { +class GcContext; + struct CasStoreConfiguration { // Root directory for CAS store @@ -50,24 +52,6 @@ private: std::unordered_set<IoHash> m_ChunkSet; }; -/** Garbage Collection context object - */ - -class GcContext -{ -public: - GcContext(); - ~GcContext(); - - void ContributeCids(std::span<const IoHash> Cid); - void ContributeCas(std::span<const IoHash> Hash); - -private: - struct GcState; - - std::unique_ptr<GcState> m_State; -}; - /** Context object for data scrubbing * * Data scrubbing is when we traverse stored data to validate it and diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h index 055843547..33a43f4d2 100644 --- a/zenstore/include/zenstore/gc.h +++ b/zenstore/include/zenstore/gc.h @@ -11,6 +11,27 @@ namespace zen { class CasStore; struct IoHash; +/** Garbage Collection context object + */ + +class GcContext +{ +public: + GcContext(); + ~GcContext(); + + void ContributeCids(std::span<const IoHash> Cid); + void ContributeCas(std::span<const IoHash> Hash); + +private: + struct GcState; + + std::unique_ptr<GcState> m_State; +}; + +/** GC + */ + class CasGc { public: |