diff options
| author | Stefan Boberg <[email protected]> | 2023-05-15 21:25:18 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-05-15 21:25:18 +0200 |
| commit | 51c57171d859f1893d181b68c5a2506f7909578c (patch) | |
| tree | 71694f1f03a86bbcf38f9f0a8253e96dea248ecf /src | |
| parent | added scrubbing related logging (diff) | |
| download | zen-51c57171d859f1893d181b68c5a2506f7909578c.tar.xz zen-51c57171d859f1893d181b68c5a2506f7909578c.zip | |
added ScrubStorage to GcStorage base class
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenserver/cache/structuredcache.h | 5 | ||||
| -rw-r--r-- | src/zenserver/projectstore/projectstore.h | 2 | ||||
| -rw-r--r-- | src/zenstore/compactcas.cpp | 16 | ||||
| -rw-r--r-- | src/zenstore/compactcas.h | 19 | ||||
| -rw-r--r-- | src/zenstore/filecas.cpp | 8 | ||||
| -rw-r--r-- | src/zenstore/filecas.h | 4 | ||||
| -rw-r--r-- | src/zenstore/include/zenstore/gc.h | 6 |
7 files changed, 42 insertions, 18 deletions
diff --git a/src/zenserver/cache/structuredcache.h b/src/zenserver/cache/structuredcache.h index add3eb281..4f03daae4 100644 --- a/src/zenserver/cache/structuredcache.h +++ b/src/zenserver/cache/structuredcache.h @@ -78,8 +78,9 @@ public: virtual const char* BaseUri() const override; virtual void HandleRequest(HttpServerRequest& Request) override; - void Flush(); - void ScrubStorage(ScrubContext& Ctx); + + void Flush(); + void ScrubStorage(ScrubContext& Ctx); private: struct CacheRef diff --git a/src/zenserver/projectstore/projectstore.h b/src/zenserver/projectstore/projectstore.h index 37093c0fb..27e06a495 100644 --- a/src/zenserver/projectstore/projectstore.h +++ b/src/zenserver/projectstore/projectstore.h @@ -253,7 +253,6 @@ public: bool DeleteProject(std::string_view ProjectId); bool Exists(std::string_view ProjectId); void Flush(); - void ScrubStorage(ScrubContext& Ctx); void DiscoverProjects(); void IterateProjects(std::function<void(Project& Prj)>&& Fn); @@ -261,6 +260,7 @@ public: const std::filesystem::path& BasePath() const { return m_ProjectBasePath; } virtual void GatherReferences(GcContext& GcCtx) override; + virtual void ScrubStorage(ScrubContext& Ctx) override; virtual void CollectGarbage(GcContext& GcCtx) override; virtual GcStorageSize StorageSize() const override; diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp index 47c31eb5a..e4c2c2ecf 100644 --- a/src/zenstore/compactcas.cpp +++ b/src/zenstore/compactcas.cpp @@ -101,8 +101,7 @@ namespace { fmt::format("Invalid content type {} for entry {}", static_cast<uint8_t>(Entry.ContentType), Entry.Key.ToHexString()); return false; } - uint64_t Size = Entry.Location.GetSize(); - if (Size == 0) + if (const uint64_t Size = Entry.Location.GetSize(); Size == 0) { OutReason = fmt::format("Invalid size {} for entry {}", Size, Entry.Key.ToHexString()); return false; @@ -235,6 +234,8 @@ CasContainerStrategy::Flush() void CasContainerStrategy::ScrubStorage(ScrubContext& Ctx) { + ZEN_INFO("scrubbing '{}'", m_BlocksBasePath); + std::vector<IoHash> BadKeys; uint64_t ChunkCount{0}, ChunkBytes{0}; std::vector<BlockStoreLocation> ChunkLocations; @@ -361,7 +362,10 @@ CasContainerStrategy::ScrubStorage(ScrubContext& Ctx) // Let whomever it concerns know about the bad chunks. This could // be used to invalidate higher level data structures more efficiently // than a full validation pass might be able to do - Ctx.ReportBadCidChunks(BadKeys); + if (!BadKeys.empty()) + { + Ctx.ReportBadCidChunks(BadKeys); + } ZEN_INFO("compact cas scrubbed: {} chunks ({})", ChunkCount, NiceBytes(ChunkBytes)); } @@ -500,6 +504,12 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) GcCtx.AddDeletedCids(DeletedChunks); } +GcStorageSize +CasContainerStrategy::StorageSize() const +{ + return {.DiskSize = m_BlockStore.TotalSize()}; +} + void CasContainerStrategy::MakeIndexSnapshot() { diff --git a/src/zenstore/compactcas.h b/src/zenstore/compactcas.h index eebe3e7d2..b149fd682 100644 --- a/src/zenstore/compactcas.h +++ b/src/zenstore/compactcas.h @@ -39,11 +39,11 @@ struct CasDiskIndexEntry static_assert(sizeof(CasDiskIndexEntry) == 32); /** This implements a storage strategy for small CAS values - * - * New chunks are simply appended to a small object file, and an index is - * maintained to allow chunks to be looked up within the active small object - * files - * + + New chunks are simply appended to a small object file, and an index is + maintained to allow chunks to be looked up within the active small object + files + */ struct CasContainerStrategy final : public GcStorage @@ -61,9 +61,12 @@ struct CasContainerStrategy final : public GcStorage uint64_t Alignment, bool IsNewStore); void Flush(); - void ScrubStorage(ScrubContext& Ctx); - virtual void CollectGarbage(GcContext& GcCtx) override; - virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_BlockStore.TotalSize()}; } + + // GcStorage + + virtual void ScrubStorage(ScrubContext& ScrubCtx) override; + virtual void CollectGarbage(GcContext& GcCtx) override; + virtual GcStorageSize StorageSize() const override; private: CasStore::InsertResult InsertChunk(const void* ChunkData, size_t ChunkSize, const IoHash& ChunkHash); diff --git a/src/zenstore/filecas.cpp b/src/zenstore/filecas.cpp index 30c6c2d4d..2b64bd202 100644 --- a/src/zenstore/filecas.cpp +++ b/src/zenstore/filecas.cpp @@ -834,6 +834,8 @@ FileCasStrategy::Flush() void FileCasStrategy::ScrubStorage(ScrubContext& Ctx) { + ZEN_INFO("scrubbing file CAS @ '{}'", m_RootDirectory); + ZEN_ASSERT(m_IsInitialized); std::vector<IoHash> BadHashes; @@ -1001,6 +1003,12 @@ FileCasStrategy::CollectGarbage(GcContext& GcCtx) GcCtx.AddDeletedCids(ChunksToDelete); } +GcStorageSize +FileCasStrategy::StorageSize() const +{ + return {.DiskSize = m_TotalSize.load(std::memory_order::relaxed)}; +} + bool FileCasStrategy::ValidateEntry(const FileCasIndexEntry& Entry, std::string& OutReason) { diff --git a/src/zenstore/filecas.h b/src/zenstore/filecas.h index 5dbf820e5..e4eab183a 100644 --- a/src/zenstore/filecas.h +++ b/src/zenstore/filecas.h @@ -40,9 +40,9 @@ struct FileCasStrategy final : public GcStorage bool HaveChunk(const IoHash& ChunkHash); void FilterChunks(HashKeySet& InOutChunks); void Flush(); - void ScrubStorage(ScrubContext& Ctx); + virtual void ScrubStorage(ScrubContext& ScrubCtx) override; virtual void CollectGarbage(GcContext& GcCtx) override; - virtual GcStorageSize StorageSize() const override { return {.DiskSize = m_TotalSize.load(std::memory_order::relaxed)}; } + virtual GcStorageSize StorageSize() const override; private: void MakeIndexSnapshot(); diff --git a/src/zenstore/include/zenstore/gc.h b/src/zenstore/include/zenstore/gc.h index 0e18315d9..0251aeb05 100644 --- a/src/zenstore/include/zenstore/gc.h +++ b/src/zenstore/include/zenstore/gc.h @@ -5,6 +5,7 @@ #include <zencore/iohash.h> #include <zencore/thread.h> #include <zenstore/caslog.h> +#include <zenstore/scrubcontext.h> #include <atomic> #include <chrono> @@ -115,8 +116,9 @@ public: GcStorage(GcManager& Gc); ~GcStorage(); - virtual void CollectGarbage(GcContext& GcCtx) = 0; - virtual GcStorageSize StorageSize() const = 0; + virtual void ScrubStorage(ScrubContext& ScrubCtx) = 0; + virtual void CollectGarbage(GcContext& GcCtx) = 0; + virtual GcStorageSize StorageSize() const = 0; private: GcManager& m_Gc; |