From e140ec960bec2a3c2b867361af35b312a5bbc53d Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 28 Oct 2021 13:58:28 +0200 Subject: gc: Implemented initial root gathering for projects/oplogs --- zenserver/projectstore.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'zenserver/projectstore.cpp') diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index 73d61c124..72d7284a0 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -298,6 +298,36 @@ ProjectStore::Oplog::Flush() m_Storage->Flush(); } +void +ProjectStore::Oplog::Scrub(ScrubContext& Ctx) const +{ + ZEN_UNUSED(Ctx); +} + +void +ProjectStore::Oplog::GatherReferences(GcContext& GcCtx) const +{ + RwLock::SharedLockScope _(m_OplogLock); + + std::vector Hashes; + + for (const auto& Kv : m_ChunkMap) + { + Hashes.push_back(Kv.second); + } + + GcCtx.ContributeCids(Hashes); + + Hashes.clear(); + + for (const auto& Kv : m_MetaMap) + { + Hashes.push_back(Kv.second); + } + + GcCtx.ContributeCids(Hashes); +} + bool ProjectStore::Oplog::ExistsAt(std::filesystem::path BasePath) { @@ -750,7 +780,7 @@ ProjectStore::Project::DeleteOplog(std::string_view OplogId) void ProjectStore::Project::IterateOplogs(std::function&& Fn) const { - // TODO: should iterate over oplogs which are present on disk but not yet loaded + // TODO: should also iterate over oplogs which are present on disk but not yet loaded RwLock::SharedLockScope _(m_ProjectLock); @@ -769,13 +799,20 @@ ProjectStore::Project::Flush() void ProjectStore::Project::Scrub(ScrubContext& Ctx) { - ZEN_UNUSED(Ctx); + IterateOplogs([&](const Oplog& Ops) { Ops.Scrub(Ctx); }); +} + +void +ProjectStore::Project::GatherReferences(GcContext& GcCtx) +{ + IterateOplogs([&](const Oplog& Ops) { Ops.GatherReferences(GcCtx); }); } ////////////////////////////////////////////////////////////////////////// -ProjectStore::ProjectStore(CidStore& Store, std::filesystem::path BasePath) -: m_Log(zen::logging::Get("project")) +ProjectStore::ProjectStore(CidStore& Store, std::filesystem::path BasePath, CasGc& Gc) +: GcContributor(Gc) +, m_Log(zen::logging::Get("project")) , m_ProjectBasePath(BasePath) , m_CidStore(Store) { @@ -818,6 +855,17 @@ ProjectStore::Scrub(ScrubContext& Ctx) } } +void +ProjectStore::GatherReferences(GcContext& GcCtx) +{ + RwLock::SharedLockScope _(m_ProjectsLock); + + for (auto& Kv : m_Projects) + { + Kv.second.GatherReferences(GcCtx); + } +} + ProjectStore::Project* ProjectStore::OpenProject(std::string_view ProjectId) { -- cgit v1.2.3