diff options
| author | Stefan Boberg <[email protected]> | 2021-11-01 20:00:38 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-11-01 20:00:38 +0100 |
| commit | 4bd88d177958b10ed0b78b0379f039f95acb5ff1 (patch) | |
| tree | 1e90ced5d20da8ad2234ee7b0de001cafdcab85e /zenstore | |
| parent | cid: Added RemapCid() for use in GC (diff) | |
| download | zen-4bd88d177958b10ed0b78b0379f039f95acb5ff1.tar.xz zen-4bd88d177958b10ed0b78b0379f039f95acb5ff1.zip | |
gc: implemented CID remapping for GC
Diffstat (limited to 'zenstore')
| -rw-r--r-- | zenstore/gc.cpp | 46 | ||||
| -rw-r--r-- | zenstore/include/zenstore/gc.h | 6 |
2 files changed, 50 insertions, 2 deletions
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index c3cb77b69..278f09b0b 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -1,8 +1,11 @@ // Copyright Epic Games, Inc. All Rights Reserved. -#include <zenstore/CAS.h> #include <zenstore/gc.h> +#include <zenstore/CAS.h> +#include <zenstore/cidstore.h> +#include <zencore/logging.h> + namespace zen { ////////////////////////////////////////////////////////////////////////// @@ -35,6 +38,12 @@ GcContext::ContributeCas(std::span<const IoHash> Cas) } void +GcContext::IterateCids(std::function<void(const IoHash&)> Callback) +{ + m_State->m_CidChunks.IterateChunks([&](const IoHash& Hash) { Callback(Hash); }); +} + +void GcContext::FilterCids(std::span<const IoHash> Cid, std::function<void(const IoHash&)> KeepFunc) { m_State->m_CidChunks.FilterChunks(Cid, [&](const IoHash& Hash) { KeepFunc(Hash); }); @@ -51,7 +60,7 @@ GcContext::IsDeletionMode() const { return m_State->m_DeletionMode; } -void +void GcContext::SetDeletionMode(bool NewState) { m_State->m_DeletionMode = NewState; @@ -134,6 +143,33 @@ CasGc::CollectGarbage() Contributor->GatherReferences(GcCtx); } + if (CidStore* CidStore = m_CidStore) + { + std::vector<IoHash> CasHashes; + + int UnknownChunks = 0; + + GcCtx.IterateCids([&](const IoHash& Hash) { + IoHash Cas = CidStore->RemapCid(Hash); + + if (Cas == IoHash::Zero) + { + ++UnknownChunks; + } + else + { + CasHashes.push_back(Cas); + } + }); + + if (UnknownChunks) + { + ZEN_WARN("found {} unknown CIDs", UnknownChunks); + } + + GcCtx.ContributeCas(CasHashes); + } + // Then trim storage for (GcStorage* Storage : m_GcStorage) @@ -143,6 +179,12 @@ CasGc::CollectGarbage() } void +CasGc::SetCidStore(CidStore* Cids) +{ + m_CidStore = Cids; +} + +void CasGc::OnNewCidReferences(std::span<IoHash> Hashes) { ZEN_UNUSED(Hashes); diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h index 46b588570..560642803 100644 --- a/zenstore/include/zenstore/gc.h +++ b/zenstore/include/zenstore/gc.h @@ -6,6 +6,7 @@ #include <zencore/thread.h> #include <span> +#include <functional> #define ZEN_USE_REF_TRACKING 0 // This is not currently functional @@ -13,6 +14,7 @@ namespace zen { class CasStore; class CasGc; +class CidStore; struct IoHash; /** Garbage Collection context object @@ -27,6 +29,8 @@ public: void ContributeCids(std::span<const IoHash> Cid); void ContributeCas(std::span<const IoHash> Hash); + void IterateCids(std::function<void(const IoHash&)> Callback); + void FilterCids(std::span<const IoHash> Cid, std::function<void(const IoHash&)> KeepFunc); void FilterCas(std::span<const IoHash> Cas, std::function<void(const IoHash&)> KeepFunc); @@ -91,6 +95,7 @@ public: void CollectGarbage(); + void SetCidStore(CidStore* Cids); void OnNewCidReferences(std::span<IoHash> Hashes); void OnCommittedCidReferences(std::span<IoHash> Hashes); void OnDroppedCidReferences(std::span<IoHash> Hashes); @@ -99,6 +104,7 @@ private: RwLock m_Lock; std::vector<GcContributor*> m_GcContribs; std::vector<GcStorage*> m_GcStorage; + CidStore* m_CidStore; }; } // namespace zen |