diff options
| -rw-r--r-- | zenstore/filecas.cpp | 13 | ||||
| -rw-r--r-- | zenstore/filecas.h | 8 |
2 files changed, 17 insertions, 4 deletions
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 3c4add82a..62600eae6 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -90,7 +90,16 @@ FileCasStrategy::Initialize(bool IsNewStore) m_CasLog.Open(m_Config.RootDirectory / "cas.ulog", IsNewStore); - m_CasLog.Replay([&](const FileCasIndexEntry& Entry) { m_TotalSize.fetch_add(Entry.Size); }); + m_CasLog.Replay([&](const FileCasIndexEntry& Entry) { + if (Entry.IsFlagSet(FileCasIndexEntry::kTombStone)) + { + m_TotalSize.fetch_sub(Entry.Size, std::memory_order_relaxed); + } + else + { + m_TotalSize.fetch_add(Entry.Size, std::memory_order_relaxed); + } + }); } CasStore::InsertResult @@ -400,7 +409,7 @@ FileCasStrategy::DeleteChunk(const IoHash& ChunkHash, std::error_code& Ec) if (!Ec) { m_TotalSize.fetch_sub(FileSize); - m_CasLog.Append({.Key = ChunkHash, .Size = -static_cast<int64_t>(FileSize)}); + m_CasLog.Append({.Key = ChunkHash, .Flags = FileCasIndexEntry::kTombStone, .Size = static_cast<int64_t>(FileSize)}); } } diff --git a/zenstore/filecas.h b/zenstore/filecas.h index 06f35785b..f64c3061a 100644 --- a/zenstore/filecas.h +++ b/zenstore/filecas.h @@ -53,9 +53,13 @@ private: struct FileCasIndexEntry { + static const uint32_t kTombStone = 0x0000'0001; + + bool IsFlagSet(const uint32_t Flag) const { return (Flags & kTombStone) == Flag; } + IoHash Key; - uint32_t Pad = 0; - int64_t Size = 0; + uint32_t Flags = 0; + int64_t Size = 0; }; static_assert(sizeof(FileCasIndexEntry) == 32); |