aboutsummaryrefslogtreecommitdiff
path: root/zenstore
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-12-10 15:29:18 +0100
committerPer Larsson <[email protected]>2021-12-10 15:29:18 +0100
commit370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe (patch)
tree7329dc070434ccc265be6a7651274366d8c9fc06 /zenstore
parentSet GC default enabled and interval set to zero (off). (diff)
downloadzen-370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe.tar.xz
zen-370d0134a7f755b1e39fbba5c9482ecc9ff3a0fe.zip
Added size to GcStorage.
Diffstat (limited to 'zenstore')
-rw-r--r--zenstore/CAS.cpp6
-rw-r--r--zenstore/compactcas.cpp4
-rw-r--r--zenstore/compactcas.h6
-rw-r--r--zenstore/filecas.cpp10
-rw-r--r--zenstore/filecas.h10
-rw-r--r--zenstore/include/zenstore/gc.h10
6 files changed, 26 insertions, 20 deletions
diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp
index 40846e368..18abd2cf5 100644
--- a/zenstore/CAS.cpp
+++ b/zenstore/CAS.cpp
@@ -324,9 +324,9 @@ CasImpl::GarbageCollect(GcContext& GcCtx)
CasStoreSize
CasImpl::TotalSize() const
{
- const uint64_t Tiny = m_TinyStrategy.TotalSize();
- const uint64_t Small = m_SmallStrategy.TotalSize();
- const uint64_t Large = m_LargeStrategy.TotalSize();
+ const uint64_t Tiny = m_TinyStrategy.StorageSize().DiskSize;
+ const uint64_t Small = m_SmallStrategy.StorageSize().DiskSize;
+ const uint64_t Large = m_LargeStrategy.StorageSize().DiskSize;
return {.TinySize = Tiny, .SmallSize = Small, .LargeSize = Large, .TotalSize = Tiny + Small + Large};
}
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index f3fcbca28..6149873ad 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -579,7 +579,7 @@ TEST_CASE("cas.compact.totalsize")
ZEN_ASSERT(InsertResult.New);
}
- const uint64_t TotalSize = Cas.TotalSize();
+ const uint64_t TotalSize = Cas.StorageSize().DiskSize;
CHECK_EQ(kChunkSize * kChunkCount, TotalSize);
}
@@ -588,7 +588,7 @@ TEST_CASE("cas.compact.totalsize")
CasContainerStrategy Cas(CasConfig, Gc);
Cas.Initialize("test", 16, false);
- const uint64_t TotalSize = Cas.TotalSize();
+ const uint64_t TotalSize = Cas.StorageSize().DiskSize;
CHECK_EQ(kChunkSize * kChunkCount, TotalSize);
}
}
diff --git a/zenstore/compactcas.h b/zenstore/compactcas.h
index 1d3a2beff..f3a933718 100644
--- a/zenstore/compactcas.h
+++ b/zenstore/compactcas.h
@@ -80,7 +80,7 @@ static_assert(sizeof(CasDiskIndexEntry) == 32);
*
*/
-struct CasContainerStrategy : public GcStorage
+struct CasContainerStrategy final : public GcStorage
{
CasContainerStrategy(const CasStoreConfiguration& Config, CasGc& Gc);
~CasContainerStrategy();
@@ -93,8 +93,8 @@ struct CasContainerStrategy : public GcStorage
void Initialize(const std::string_view ContainerBaseName, uint64_t Alignment, bool IsNewStore);
void Flush();
void Scrub(ScrubContext& Ctx);
- void CollectGarbage(GcContext& GcCtx);
- uint64_t TotalSize() const { return m_TotalSize; }
+ virtual void CollectGarbage(GcContext& GcCtx) override;
+ virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_TotalSize.load(std::memory_order::relaxed)}; }
private:
void OpenContainer(bool IsNewStore);
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp
index 62600eae6..bfad34c86 100644
--- a/zenstore/filecas.cpp
+++ b/zenstore/filecas.cpp
@@ -248,8 +248,8 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash)
if (Success)
{
- m_TotalSize.fetch_add(static_cast<int64_t>(Chunk.Size()));
- m_CasLog.Append({.Key = ChunkHash, .Size = static_cast<int64_t>(Chunk.Size())});
+ m_TotalSize.fetch_add(Chunk.Size(), std::memory_order::relaxed);
+ m_CasLog.Append({.Key = ChunkHash, .Size = Chunk.Size()});
return CasStore::InsertResult{.New = true};
}
@@ -354,8 +354,8 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize
// *after* the lock is released due to the initialization order
PayloadFile.Close();
- m_TotalSize.fetch_add(static_cast<int64_t>(ChunkSize));
- m_CasLog.Append({.Key = ChunkHash, .Size = static_cast<int64_t>(ChunkSize)});
+ m_TotalSize.fetch_add(ChunkSize, std::memory_order::relaxed);
+ m_CasLog.Append({.Key = ChunkHash, .Size = ChunkSize});
return {.New = true};
}
@@ -409,7 +409,7 @@ FileCasStrategy::DeleteChunk(const IoHash& ChunkHash, std::error_code& Ec)
if (!Ec)
{
m_TotalSize.fetch_sub(FileSize);
- m_CasLog.Append({.Key = ChunkHash, .Flags = FileCasIndexEntry::kTombStone, .Size = static_cast<int64_t>(FileSize)});
+ m_CasLog.Append({.Key = ChunkHash, .Flags = FileCasIndexEntry::kTombStone, .Size = FileSize});
}
}
diff --git a/zenstore/filecas.h b/zenstore/filecas.h
index f64c3061a..a229ba6f1 100644
--- a/zenstore/filecas.h
+++ b/zenstore/filecas.h
@@ -26,7 +26,7 @@ class BasicFile;
/** CAS storage strategy using a file-per-chunk storage strategy
*/
-struct FileCasStrategy : public GcStorage
+struct FileCasStrategy final : public GcStorage
{
FileCasStrategy(const CasStoreConfiguration& Config, CasGc& Gc);
~FileCasStrategy();
@@ -38,9 +38,9 @@ struct FileCasStrategy : public GcStorage
bool HaveChunk(const IoHash& ChunkHash);
void FilterChunks(CasChunkSet& InOutChunks);
void Flush();
- virtual void CollectGarbage(GcContext& GcCtx) override;
void Scrub(ScrubContext& Ctx);
- uint64_t TotalSize() const { return static_cast<uint64_t>(m_TotalSize); }
+ virtual void CollectGarbage(GcContext& GcCtx) override;
+ virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_TotalSize.load(std::memory_order::relaxed)}; }
private:
const CasStoreConfiguration& m_Config;
@@ -48,7 +48,7 @@ private:
RwLock m_ShardLocks[256]; // TODO: these should be spaced out so they don't share cache lines
spdlog::logger& m_Log;
spdlog::logger& Log() { return m_Log; }
- std::atomic_int64_t m_TotalSize{};
+ std::atomic_uint64_t m_TotalSize{};
bool m_IsInitialized = false;
struct FileCasIndexEntry
@@ -59,7 +59,7 @@ private:
IoHash Key;
uint32_t Flags = 0;
- int64_t Size = 0;
+ uint64_t Size = 0;
};
static_assert(sizeof(FileCasIndexEntry) == 32);
diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h
index 5a6afc8da..2ea35b131 100644
--- a/zenstore/include/zenstore/gc.h
+++ b/zenstore/include/zenstore/gc.h
@@ -96,16 +96,22 @@ protected:
CasGc& m_Gc;
};
+struct GcStorageSize
+{
+ uint64_t DiskSize{};
+ uint64_t MemorySize{};
+};
+
/** GC storage provider
*/
-
class GcStorage
{
public:
GcStorage(CasGc& Gc);
~GcStorage();
- virtual void CollectGarbage(GcContext& GcCtx) = 0;
+ virtual void CollectGarbage(GcContext& GcCtx) = 0;
+ virtual GcStorageSize StorageSize() const = 0;
private:
CasGc& m_Gc;