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/gc.cpp | |
| 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/gc.cpp')
| -rw-r--r-- | zenstore/gc.cpp | 46 |
1 files changed, 44 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); |