diff options
| author | Per Larsson <[email protected]> | 2021-11-30 10:52:17 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-11-30 10:52:17 +0100 |
| commit | b4b599a1dd9f3b4da022c3729144f31550292f03 (patch) | |
| tree | 26889994acca6936002ebd0d91f8919eb0077f98 /zenstore/filecas.cpp | |
| parent | Added z$ memory/disk layer size. (diff) | |
| download | zen-b4b599a1dd9f3b4da022c3729144f31550292f03.tar.xz zen-b4b599a1dd9f3b4da022c3729144f31550292f03.zip | |
Added CAS total size.
Diffstat (limited to 'zenstore/filecas.cpp')
| -rw-r--r-- | zenstore/filecas.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 0efdc96f5..3c4add82a 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -90,7 +90,7 @@ FileCasStrategy::Initialize(bool IsNewStore) m_CasLog.Open(m_Config.RootDirectory / "cas.ulog", IsNewStore); - m_CasLog.Replay([&](const FileCasIndexEntry& Entry) { ZEN_UNUSED(Entry); }); + m_CasLog.Replay([&](const FileCasIndexEntry& Entry) { m_TotalSize.fetch_add(Entry.Size); }); } CasStore::InsertResult @@ -138,6 +138,16 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) // We do need to ensure the source file goes away on close, however + uint64_t FileSize = 0; + if (HRESULT hSizeRes = PayloadFile.GetSize(FileSize); SUCCEEDED(hSizeRes)) + { + m_TotalSize.fetch_add(static_cast<int64_t>(FileSize)); + } + else + { + ZEN_WARN("get file size FAILED, file cas '{}'", WideToUtf8(Name.ShardedPath)); + } + DeletePayloadFileOnClose(); return CasStore::InsertResult{.New = false}; @@ -229,7 +239,8 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) if (Success) { - m_CasLog.Append({.Key = ChunkHash, .Size = Chunk.Size()}); + m_TotalSize.fetch_add(static_cast<int64_t>(Chunk.Size())); + m_CasLog.Append({.Key = ChunkHash, .Size = static_cast<int64_t>(Chunk.Size())}); return CasStore::InsertResult{.New = true}; } @@ -272,6 +283,8 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize { // If we succeeded in opening the file then we don't need to do anything else because it already exists and should contain the // content we were about to insert + + m_TotalSize.fetch_add(static_cast<int64_t>(ChunkSize)); return CasStore::InsertResult{.New = false}; } @@ -287,6 +300,8 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize { // If we succeeded in opening the file then we don't need to do anything // else because someone else managed to create the file before we did. Just return. + + m_TotalSize.fetch_add(static_cast<int64_t>(ChunkSize)); return {.New = false}; } @@ -330,7 +345,8 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize // *after* the lock is released due to the initialization order PayloadFile.Close(); - m_CasLog.Append({.Key = ChunkHash, .Size = ChunkSize}); + m_TotalSize.fetch_add(static_cast<int64_t>(ChunkSize)); + m_CasLog.Append({.Key = ChunkHash, .Size = static_cast<int64_t>(ChunkSize)}); return {.New = true}; } @@ -370,13 +386,21 @@ FileCasStrategy::DeleteChunk(const IoHash& ChunkHash, std::error_code& Ec) { ShardingHelper Name(m_Config.RootDirectory.c_str(), ChunkHash); - ZEN_DEBUG("deleting CAS payload file '{}'", WideToUtf8(Name.ShardedPath)); + uint64_t FileSize = static_cast<uint64_t>(std::filesystem::file_size(Name.ShardedPath.c_str(), Ec)); + if (Ec) + { + ZEN_WARN("get file size FAILED, file cas '{}'", WideToUtf8(Name.ShardedPath)); + FileSize = 0; + } + + ZEN_DEBUG("deleting CAS payload file '{}' {}", WideToUtf8(Name.ShardedPath), NiceBytes(FileSize)); std::filesystem::remove(Name.ShardedPath.c_str(), Ec); if (!Ec) { - m_CasLog.Append({.Key = ChunkHash, .Size = ~(0ull)}); + m_TotalSize.fetch_sub(FileSize); + m_CasLog.Append({.Key = ChunkHash, .Size = -static_cast<int64_t>(FileSize)}); } } |