From 666a543ed82896c972526ef08476a41ccbfbd2c4 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Thu, 24 Nov 2022 13:20:59 +0100 Subject: Fix disk usage stats (#194) * Improve tracking of used disk space for filecas and compactcas Add tracking of used disk space for project store Remove ZenCacheStore as GcStorage/GcContributor - underlying ZenCacheNamespace instances register themselves directly - removing this also fixes double reporting of GcStorageSize for namespaces * changelog --- zenserver/projectstore.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'zenserver/projectstore.cpp') diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index 2268b5caf..87118991e 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -111,6 +111,12 @@ struct ProjectStore::OplogStorage : public RefCounted static bool Delete(std::filesystem::path BasePath) { return DeleteDirectories(BasePath); } + uint64_t OpBlobsSize() const + { + RwLock::SharedLockScope _(m_RwLock); + return m_NextOpsOffset; + } + void Open(bool IsCreate) { using namespace std::literals; @@ -256,7 +262,7 @@ struct ProjectStore::OplogStorage : public RefCounted private: ProjectStore::Oplog* m_OwnerOplog; std::filesystem::path m_OplogStoragePath; - RwLock m_RwLock; + mutable RwLock m_RwLock; TCasLogFile m_Oplog; BasicFile m_OpBlobs; std::atomic m_NextOpsOffset{0}; @@ -329,6 +335,17 @@ ProjectStore::Oplog::GatherReferences(GcContext& GcCtx) GcCtx.AddRetainedCids(Hashes); } +uint64_t +ProjectStore::Oplog::TotalSize() const +{ + RwLock::SharedLockScope _(m_OplogLock); + if (m_Storage) + { + return m_Storage->OpBlobsSize(); + } + return 0; +} + std::filesystem::path ProjectStore::Oplog::PrepareForDelete(bool MoveFolder) { @@ -912,6 +929,20 @@ ProjectStore::Project::GatherReferences(GcContext& GcCtx) IterateOplogs([&](Oplog& Ops) { Ops.GatherReferences(GcCtx); }); } +uint64_t +ProjectStore::Project::TotalSize() const +{ + uint64_t Result = 0; + { + RwLock::SharedLockScope _(m_ProjectLock); + for (const auto& It : m_Oplogs) + { + Result += It.second->TotalSize(); + } + } + return Result; +} + bool ProjectStore::Project::PrepareForDelete(std::filesystem::path& OutDeletePath) { @@ -1160,7 +1191,16 @@ ProjectStore::CollectGarbage(GcContext& GcCtx) GcStorageSize ProjectStore::StorageSize() const { - return {0, 0}; + GcStorageSize Result; + { + RwLock::SharedLockScope _(m_ProjectsLock); + for (auto& Kv : m_Projects) + { + const Ref& Project = Kv.second; + Result.DiskSize += Project->TotalSize(); + } + } + return Result; } Ref -- cgit v1.2.3