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 /zenstore/blockstore.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 'zenstore/blockstore.cpp')
| -rw-r--r-- | zenstore/blockstore.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp index 682cc4472..c8bf482fa 100644 --- a/zenstore/blockstore.cpp +++ b/zenstore/blockstore.cpp @@ -95,12 +95,6 @@ BlockStoreFile::Write(const void* Data, uint64_t Size, uint64_t FileOffset) } void -BlockStoreFile::Truncate(uint64_t Size) -{ - m_File.SetFileSize(Size); -} - -void BlockStoreFile::Flush() { m_File.Flush(); @@ -130,6 +124,7 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, ZEN_ASSERT(MaxBlockCount > 0); ZEN_ASSERT(IsPow2(MaxBlockCount)); + m_TotalSize = 0; m_BlocksBasePath = BlocksBasePath; m_MaxBlockSize = MaxBlockSize; @@ -184,6 +179,7 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, } Ref<BlockStoreFile> BlockFile = new BlockStoreFile(Path); BlockFile->Open(); + m_TotalSize.fetch_add(BlockFile->FileSize(), std::memory_order::relaxed); m_ChunkBlocks[BlockIndex] = BlockFile; } } @@ -248,13 +244,15 @@ BlockStore::WriteChunk(const void* Data, uint64_t Size, uint64_t Alignment, cons m_WriteBlockIndex.store(WriteBlockIndex, std::memory_order_release); m_CurrentInsertOffset = 0; } - uint64_t InsertOffset = m_CurrentInsertOffset; - m_CurrentInsertOffset = RoundUp(InsertOffset + Size, Alignment); - Ref<BlockStoreFile> WriteBlock = m_WriteBlock; + uint64_t InsertOffset = m_CurrentInsertOffset; + m_CurrentInsertOffset = RoundUp(InsertOffset + Size, Alignment); + uint64_t AlignedWriteSize = m_CurrentInsertOffset - InsertOffset; + Ref<BlockStoreFile> WriteBlock = m_WriteBlock; m_ActiveWriteBlocks.push_back(WriteBlockIndex); InsertLock.ReleaseNow(); WriteBlock->Write(Data, Size, InsertOffset); + m_TotalSize.fetch_add(AlignedWriteSize, std::memory_order::relaxed); Callback({.BlockIndex = WriteBlockIndex, .Offset = InsertOffset, .Size = Size}); @@ -477,6 +475,7 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, }); m_ChunkBlocks[BlockIndex] = nullptr; ZEN_DEBUG("marking cas block store file '{}' for delete, block #{}", OldBlockFile->GetPath(), BlockIndex); + m_TotalSize.fetch_sub(OldBlockFile->FileSize(), std::memory_order::relaxed); OldBlockFile->MarkAsDeleteOnClose(); } continue; @@ -496,7 +495,6 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, if (NewBlockFile) { - NewBlockFile->Truncate(WriteOffset); NewBlockFile->Flush(); NewBlockFile = nullptr; } @@ -566,12 +564,13 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, NewBlockFile->Write(Chunk.data(), Chunk.size(), WriteOffset); MovedChunks.push_back({ChunkIndex, {.BlockIndex = NewBlockIndex, .Offset = WriteOffset, .Size = Chunk.size()}}); - WriteOffset = RoundUp(WriteOffset + Chunk.size(), PayloadAlignment); + uint64_t OldOffset = WriteOffset; + WriteOffset = RoundUp(WriteOffset + Chunk.size(), PayloadAlignment); + m_TotalSize.fetch_add(WriteOffset - OldOffset, std::memory_order::relaxed); } Chunk.clear(); if (NewBlockFile) { - NewBlockFile->Truncate(WriteOffset); NewBlockFile->Flush(); NewBlockFile = nullptr; } @@ -596,6 +595,7 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, }); m_ChunkBlocks[BlockIndex] = nullptr; ZEN_DEBUG("marking cas block store file '{}' for delete, block #{}", OldBlockFile->GetPath(), BlockIndex); + m_TotalSize.fetch_sub(OldBlockFile->FileSize(), std::memory_order::relaxed); OldBlockFile->MarkAsDeleteOnClose(); } } @@ -606,6 +606,7 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, if (NewBlockFile) { ZEN_DEBUG("dropping incomplete cas block store file '{}'", NewBlockFile->GetPath()); + m_TotalSize.fetch_sub(NewBlockFile->FileSize(), std::memory_order::relaxed); NewBlockFile->MarkAsDeleteOnClose(); } } |