aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-12-08 08:52:23 +0100
committerPer Larsson <[email protected]>2021-12-08 08:52:23 +0100
commit17fe85637a49acf38ea222edd161f2919b3558fa (patch)
treed924db4c7974661027fb29638c2fb9457710e63d
parentFirst pass of z$ garbage collection. (diff)
downloadzen-17fe85637a49acf38ea222edd161f2919b3558fa.tar.xz
zen-17fe85637a49acf38ea222edd161f2919b3558fa.zip
Added tombstone flag to file cas.
-rw-r--r--zenstore/filecas.cpp13
-rw-r--r--zenstore/filecas.h8
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);