diff options
| author | Dan Engelbrecht <[email protected]> | 2022-11-24 13:20:59 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-11-24 04:20:59 -0800 |
| commit | 666a543ed82896c972526ef08476a41ccbfbd2c4 (patch) | |
| tree | 49a52941d9ced665431ebf320d0f7d0f4b6e5cfa /zenserver/projectstore.cpp | |
| parent | Don't resize block store block file to max size at creation (#193) (diff) | |
| download | zen-666a543ed82896c972526ef08476a41ccbfbd2c4.tar.xz zen-666a543ed82896c972526ef08476a41ccbfbd2c4.zip | |
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
Diffstat (limited to 'zenserver/projectstore.cpp')
| -rw-r--r-- | zenserver/projectstore.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
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<OplogEntry> m_Oplog; BasicFile m_OpBlobs; std::atomic<uint64_t> 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>& Project = Kv.second; + Result.DiskSize += Project->TotalSize(); + } + } + return Result; } Ref<ProjectStore::Project> |