diff options
| author | Dan Engelbrecht <[email protected]> | 2023-10-20 11:02:26 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-20 11:02:26 +0200 |
| commit | 57f054be2f4f68d0d52631838655a45855c33655 (patch) | |
| tree | 4a768d8eee548c1c4c002388e48da3d62850dc02 /src/zenstore | |
| parent | Add --skip-delete option to gc command (#484) (diff) | |
| download | zen-57f054be2f4f68d0d52631838655a45855c33655.tar.xz zen-57f054be2f4f68d0d52631838655a45855c33655.zip | |
clean up GcContributor and GcStorage to be pure interfaces (#485)
Diffstat (limited to 'src/zenstore')
| -rw-r--r-- | src/zenstore/compactcas.cpp | 4 | ||||
| -rw-r--r-- | src/zenstore/compactcas.h | 3 | ||||
| -rw-r--r-- | src/zenstore/filecas.cpp | 4 | ||||
| -rw-r--r-- | src/zenstore/filecas.h | 11 | ||||
| -rw-r--r-- | src/zenstore/gc.cpp | 24 | ||||
| -rw-r--r-- | src/zenstore/include/zenstore/gc.h | 12 |
6 files changed, 17 insertions, 41 deletions
diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp index a6bd71bd7..98ad20b98 100644 --- a/src/zenstore/compactcas.cpp +++ b/src/zenstore/compactcas.cpp @@ -114,12 +114,14 @@ namespace { ////////////////////////////////////////////////////////////////////////// -CasContainerStrategy::CasContainerStrategy(GcManager& Gc) : GcStorage(Gc), m_Log(logging::Get("containercas")) +CasContainerStrategy::CasContainerStrategy(GcManager& Gc) : m_Log(logging::Get("containercas")), m_Gc(Gc) { + m_Gc.AddGcStorage(this); } CasContainerStrategy::~CasContainerStrategy() { + m_Gc.RemoveGcStorage(this); } void diff --git a/src/zenstore/compactcas.h b/src/zenstore/compactcas.h index c0cbbac32..478a1f78e 100644 --- a/src/zenstore/compactcas.h +++ b/src/zenstore/compactcas.h @@ -81,8 +81,9 @@ private: spdlog::logger& Log() { return m_Log; } - std::filesystem::path m_RootDirectory; spdlog::logger& m_Log; + GcManager& m_Gc; + std::filesystem::path m_RootDirectory; uint64_t m_PayloadAlignment = 1u << 4; uint64_t m_MaxBlockSize = 1u << 28; bool m_IsInitialized = false; diff --git a/src/zenstore/filecas.cpp b/src/zenstore/filecas.cpp index fe568a487..d41f449d3 100644 --- a/src/zenstore/filecas.cpp +++ b/src/zenstore/filecas.cpp @@ -115,12 +115,14 @@ FileCasStrategy::ShardingHelper::ShardingHelper(const std::filesystem::path& Roo ////////////////////////////////////////////////////////////////////////// -FileCasStrategy::FileCasStrategy(GcManager& Gc) : GcStorage(Gc), m_Log(logging::Get("filecas")) +FileCasStrategy::FileCasStrategy(GcManager& Gc) : m_Log(logging::Get("filecas")), m_Gc(Gc) { + m_Gc.AddGcStorage(this); } FileCasStrategy::~FileCasStrategy() { + m_Gc.RemoveGcStorage(this); } void diff --git a/src/zenstore/filecas.h b/src/zenstore/filecas.h index 10c181c0b..ea7ff8e8c 100644 --- a/src/zenstore/filecas.h +++ b/src/zenstore/filecas.h @@ -45,9 +45,10 @@ struct FileCasStrategy final : public GcStorage virtual GcStorageSize StorageSize() const override; private: - void MakeIndexSnapshot(); - uint64_t ReadIndexFile(const std::filesystem::path& IndexPath, uint32_t& OutVersion); - uint64_t ReadLog(const std::filesystem::path& LogPath, uint64_t LogPosition); + void MakeIndexSnapshot(); + uint64_t ReadIndexFile(const std::filesystem::path& IndexPath, uint32_t& OutVersion); + uint64_t ReadLog(const std::filesystem::path& LogPath, uint64_t LogPosition); + spdlog::logger& Log() { return m_Log; } struct IndexEntry { @@ -57,12 +58,12 @@ private: CasStore::InsertResult InsertChunkData(const void* ChunkData, size_t ChunkSize, const IoHash& ChunkHash); + spdlog::logger& m_Log; + GcManager& m_Gc; std::filesystem::path m_RootDirectory; RwLock m_Lock; IndexMap m_Index; 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_uint64_t m_TotalSize{}; bool m_IsInitialized = false; diff --git a/src/zenstore/gc.cpp b/src/zenstore/gc.cpp index 3d8e66a8b..7396fcf65 100644 --- a/src/zenstore/gc.cpp +++ b/src/zenstore/gc.cpp @@ -318,30 +318,6 @@ GcContext::ClaimGCReserve() ////////////////////////////////////////////////////////////////////////// -GcContributor::GcContributor(GcManager& Gc) : m_Gc(Gc) -{ - m_Gc.AddGcContributor(this); -} - -GcContributor::~GcContributor() -{ - m_Gc.RemoveGcContributor(this); -} - -////////////////////////////////////////////////////////////////////////// - -GcStorage::GcStorage(GcManager& Gc) : m_Gc(Gc) -{ - m_Gc.AddGcStorage(this); -} - -GcStorage::~GcStorage() -{ - m_Gc.RemoveGcStorage(this); -} - -////////////////////////////////////////////////////////////////////////// - GcManager::GcManager() : m_Log(logging::Get("gc")) { } diff --git a/src/zenstore/include/zenstore/gc.h b/src/zenstore/include/zenstore/gc.h index 1c455abe5..ffdc8f066 100644 --- a/src/zenstore/include/zenstore/gc.h +++ b/src/zenstore/include/zenstore/gc.h @@ -100,13 +100,10 @@ private: class GcContributor { public: - GcContributor(GcManager& Gc); - ~GcContributor(); - virtual void GatherReferences(GcContext& GcCtx) = 0; protected: - GcManager& m_Gc; + virtual ~GcContributor() {} }; struct GcStorageSize @@ -120,15 +117,12 @@ struct GcStorageSize class GcStorage { public: - GcStorage(GcManager& Gc); - ~GcStorage(); - virtual void ScrubStorage(ScrubContext& ScrubCtx) = 0; virtual void CollectGarbage(GcContext& GcCtx) = 0; virtual GcStorageSize StorageSize() const = 0; -private: - GcManager& m_Gc; +protected: + virtual ~GcStorage() {} }; /** Interface for querying if we are running low on disk space, used to deny put/writes to disk |