diff options
| author | Stefan Boberg <[email protected]> | 2021-09-20 21:01:01 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-20 21:01:01 +0200 |
| commit | 961173f44df332cd17e1b9875e4ef5eb9cea1d3a (patch) | |
| tree | a76b3adcdebd479c70c57bf9fb0391a1237dd5f4 | |
| parent | Made use of mimalloc controlled by define (diff) | |
| download | zen-961173f44df332cd17e1b9875e4ef5eb9cea1d3a.tar.xz zen-961173f44df332cd17e1b9875e4ef5eb9cea1d3a.zip | |
Added more scrub stubs in higher level services
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 7 | ||||
| -rw-r--r-- | zenserver/cache/structuredcache.h | 1 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 36 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.h | 3 | ||||
| -rw-r--r-- | zenserver/projectstore.cpp | 17 | ||||
| -rw-r--r-- | zenserver/projectstore.h | 3 | ||||
| -rw-r--r-- | zenserver/zenserver.cpp | 9 | ||||
| -rw-r--r-- | zenstore/cidstore.cpp | 7 | ||||
| -rw-r--r-- | zenstore/include/zenstore/cidstore.h | 1 |
9 files changed, 80 insertions, 4 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 17f8e04ef..7f1fe7b44 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -9,6 +9,7 @@ #include <zencore/stream.h> #include <zencore/timer.h> #include <zenhttp/httpserver.h> +#include <zenstore/CAS.h> #include "structuredcache.h" #include "structuredcachestore.h" @@ -172,6 +173,12 @@ HttpStructuredCacheService::Flush() { } +void +HttpStructuredCacheService::Scrub(ScrubContext& Ctx) +{ + ZEN_UNUSED(Ctx); +} + void HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request) { diff --git a/zenserver/cache/structuredcache.h b/zenserver/cache/structuredcache.h index 8871094b3..bd163dd1d 100644 --- a/zenserver/cache/structuredcache.h +++ b/zenserver/cache/structuredcache.h @@ -60,6 +60,7 @@ public: virtual void HandleRequest(zen::HttpServerRequest& Request) override; void Flush(); + void Scrub(ScrubContext& Ctx); private: struct CacheRef diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 14f4531ab..502ca6605 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -105,6 +105,12 @@ ZenCacheStore::Flush() m_DiskLayer.Flush(); } +void +ZenCacheStore::Scrub(ScrubContext& Ctx) +{ + m_DiskLayer.Scrub(Ctx); + m_MemLayer.Scrub(Ctx); +} ////////////////////////////////////////////////////////////////////////// ZenCacheMemoryLayer::ZenCacheMemoryLayer() @@ -179,6 +185,12 @@ ZenCacheMemoryLayer::DropBucket(std::string_view Bucket) return !!m_Buckets.erase(std::string(Bucket)); } +void +ZenCacheMemoryLayer::Scrub(ScrubContext& Ctx) +{ + ZEN_UNUSED(Ctx); +} + bool ZenCacheMemoryLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutValue) { @@ -375,12 +387,16 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir) void ZenCacheDiskLayer::CacheBucket::BuildPath(WideStringBuilderBase& Path, const IoHash& HashKey) { - char hex[sizeof(HashKey.Hash) * 2]; - ToHexBytes(HashKey.Hash, sizeof HashKey.Hash, hex); + char HexString[sizeof(HashKey.Hash) * 2]; + ToHexBytes(HashKey.Hash, sizeof HashKey.Hash, HexString); Path.Append(m_BucketDir.c_str()); + Path.Append(L"/blob/"); + Path.AppendAsciiRange(HexString, HexString + 3); Path.Append(L"/"); - Path.AppendAsciiRange(hex, hex + sizeof(hex)); + Path.AppendAsciiRange(HexString + 3, HexString + 5); + Path.Append(L"/"); + Path.AppendAsciiRange(HexString + 5, HexString + sizeof(HexString)); } bool @@ -495,12 +511,22 @@ ZenCacheDiskLayer::CacheBucket::Flush() } void +ZenCacheDiskLayer::Scrub(ScrubContext& Ctx) +{ + ZEN_UNUSED(Ctx); +} + +void ZenCacheDiskLayer::CacheBucket::PutLargeObject(const IoHash& HashKey, const ZenCacheValue& Value) { WideStringBuilder<128> DataFilePath; BuildPath(DataFilePath, HashKey); - // TODO: replace this with a more efficient implementation with proper atomic rename + // TODO: replace this process with a more efficient implementation with proper atomic rename + // and also avoid creating directories if we can + + std::filesystem::path ParentPath = std::filesystem::path(DataFilePath.c_str()).parent_path(); + CreateDirectories(ParentPath); CAtlTemporaryFile DataFile; @@ -518,6 +544,8 @@ ZenCacheDiskLayer::CacheBucket::PutLargeObject(const IoHash& HashKey, const ZenC ThrowSystemException(hRes, "Failed to write payload ({} bytes) to file"_format(NiceBytes(Value.Value.Size()))); } + // Move file into place (note: not fully atomic!) + hRes = DataFile.Close(DataFilePath.c_str()); if (FAILED(hRes)) diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index c4fa20958..fdf4a8cfe 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -55,6 +55,7 @@ public: bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); bool DropBucket(std::string_view Bucket); + void Scrub(ScrubContext& Ctx); private: struct CacheBucket @@ -80,6 +81,7 @@ public: void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); bool DropBucket(std::string_view Bucket); void Flush(); + void Scrub(ScrubContext& Ctx); private: /** A cache bucket manages a single directory containing @@ -103,6 +105,7 @@ public: void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); bool DropBucket(std::string_view Bucket); void Flush(); + void Scrub(ScrubContext& Ctx); private: std::filesystem::path m_RootDir; diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index 404484edf..1f4239b23 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -780,6 +780,12 @@ ProjectStore::Project::Flush() // TODO } +void +ProjectStore::Project::Scrub(ScrubContext& Ctx) +{ + ZEN_UNUSED(Ctx); +} + ////////////////////////////////////////////////////////////////////////// ProjectStore::ProjectStore(CasStore& Store, std::filesystem::path BasePath) @@ -815,6 +821,17 @@ ProjectStore::Flush() } } +void +ProjectStore::Scrub(ScrubContext& Ctx) +{ + RwLock::SharedLockScope _(m_ProjectsLock); + + for (auto& Kv : m_Projects) + { + Kv.second.Scrub(Ctx); + } +} + ProjectStore::Project* ProjectStore::OpenProject(std::string_view ProjectId) { diff --git a/zenserver/projectstore.h b/zenserver/projectstore.h index 9cca825f0..e545d78b9 100644 --- a/zenserver/projectstore.h +++ b/zenserver/projectstore.h @@ -101,6 +101,7 @@ public: spdlog::logger& Log() { return m_OuterProject->Log(); } void Flush(); + void Scrub(ScrubContext& Ctx); std::size_t OplogCount() const { return m_LatestOpMap.size(); } @@ -154,6 +155,7 @@ public: void Write(); [[nodiscard]] static bool Exists(std::filesystem::path BasePath); void Flush(); + void Scrub(ScrubContext& Ctx); spdlog::logger& Log(); private: @@ -177,6 +179,7 @@ public: void DeleteProject(std::string_view ProjectId); bool Exists(std::string_view ProjectId); void Flush(); + void Scrub(ScrubContext& Ctx); spdlog::logger& Log() { return m_Log; } const std::filesystem::path& BasePath() const { return m_ProjectBasePath; } diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 98ca152fa..4ad793faa 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -396,6 +396,15 @@ public: } } + void Scrub() + { + ScrubContext Ctx; + m_CasStore->Scrub(Ctx); + m_CidStore->Scrub(Ctx); + m_ProjectStore->Scrub(Ctx); + m_StructuredCacheService->Scrub(Ctx); + } + void Flush() { if (m_CasStore) diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp index e1b7ac656..6dd33efb2 100644 --- a/zenstore/cidstore.cpp +++ b/zenstore/cidstore.cpp @@ -91,6 +91,7 @@ struct CidStore::CidState } void Flush() { m_LogFile.Flush(); } + void Scrub(ScrubContext& Ctx) { ZEN_UNUSED(Ctx); } }; ////////////////////////////////////////////////////////////////////////// @@ -134,4 +135,10 @@ CidStore::Flush() m_Impl->Flush(); } +void +CidStore::Scrub(ScrubContext& Ctx) +{ + m_Impl->Scrub(Ctx); +} + } // namespace zen diff --git a/zenstore/include/zenstore/cidstore.h b/zenstore/include/zenstore/cidstore.h index f023ada40..49f2bf99a 100644 --- a/zenstore/include/zenstore/cidstore.h +++ b/zenstore/include/zenstore/cidstore.h @@ -45,6 +45,7 @@ public: IoBuffer FindChunkByCid(const IoHash& DecompressedId); bool ContainsChunk(const IoHash& DecompressedId); void Flush(); + void Scrub(ScrubContext& Ctx); // TODO: add batch filter support |