From 17fe85637a49acf38ea222edd161f2919b3558fa Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Wed, 8 Dec 2021 08:52:23 +0100 Subject: Added tombstone flag to file cas. --- zenstore/filecas.cpp | 13 +++++++++++-- zenstore/filecas.h | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'zenstore') 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(FileSize)}); + m_CasLog.Append({.Key = ChunkHash, .Flags = FileCasIndexEntry::kTombStone, .Size = static_cast(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); -- cgit v1.2.3