diff options
| author | Stefan Boberg <[email protected]> | 2021-09-15 13:18:34 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-15 13:18:34 +0200 |
| commit | ab95978c10258cab130ef7e6dc3f7cb7a1bf337d (patch) | |
| tree | a6e4ca55890f5b728f69ccf8878af98ba2e31bc9 /zenserver/cache | |
| parent | Added #ifdef condition around Windows-specific exception handling (diff) | |
| parent | Cross-platform zen::GetLastError() (diff) | |
| download | zen-ab95978c10258cab130ef7e6dc3f7cb7a1bf337d.tar.xz zen-ab95978c10258cab130ef7e6dc3f7cb7a1bf337d.zip | |
Merged from main
Diffstat (limited to 'zenserver/cache')
| -rw-r--r-- | zenserver/cache/cachestore.cpp | 18 | ||||
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 80 | ||||
| -rw-r--r-- | zenserver/cache/structuredcache.h | 7 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 8 |
4 files changed, 56 insertions, 57 deletions
diff --git a/zenserver/cache/cachestore.cpp b/zenserver/cache/cachestore.cpp index 9180835d9..2fc253a07 100644 --- a/zenserver/cache/cachestore.cpp +++ b/zenserver/cache/cachestore.cpp @@ -4,6 +4,7 @@ #include <zencore/crc32.h> #include <zencore/except.h> +#include <zencore/logging.h> #include <zencore/windows.h> #include <zencore/filesystem.h> @@ -16,7 +17,6 @@ #include <zenstore/caslog.h> #include <fmt/core.h> -#include <spdlog/spdlog.h> #include <concepts> #include <filesystem> #include <gsl/gsl-lite.hpp> @@ -85,7 +85,7 @@ FileCacheStore::FileCacheStore(const char* RootDir, const char* ReadRootDir) { // Ensure root directory exists - create if it doesn't exist already - spdlog::info("Initializing FileCacheStore at '{}'", std::string_view(RootDir)); + ZEN_INFO("Initializing FileCacheStore at '{}'", std::string_view(RootDir)); m_RootDir = RootDir; @@ -98,7 +98,7 @@ FileCacheStore::FileCacheStore(const char* RootDir, const char* ReadRootDir) ExtendableStringBuilder<256> Name; WideToUtf8(m_RootDir.c_str(), Name); - spdlog::error("Could not open file cache directory '{}' for writing ({})", Name.c_str(), ErrorCode.message()); + ZEN_ERROR("Could not open file cache directory '{}' for writing ({})", Name.c_str(), ErrorCode.message()); m_IsOk = false; } @@ -109,7 +109,7 @@ FileCacheStore::FileCacheStore(const char* RootDir, const char* ReadRootDir) if (std::filesystem::exists(m_ReadRootDir, ErrorCode)) { - spdlog::info("FileCacheStore will use additional read tree at '{}'", std::string_view(ReadRootDir)); + ZEN_INFO("FileCacheStore will use additional read tree at '{}'", std::string_view(ReadRootDir)); m_ReadRootIsValid = true; } @@ -145,7 +145,7 @@ FileCacheStore::Get(std::string_view Key, CacheValue& OutValue) if (FAILED(hRes)) { - spdlog::debug("GET MISS {}", Key); + ZEN_DEBUG("GET MISS {}", Key); return false; } @@ -162,7 +162,7 @@ FileCacheStore::Get(std::string_view Key, CacheValue& OutValue) OutValue.Value = IoBuffer(IoBuffer::File, File.Detach(), 0, FileSize); - spdlog::debug("GET HIT {}", Key); + ZEN_DEBUG("GET HIT {}", Key); return true; } @@ -180,7 +180,7 @@ FileCacheStore::Put(std::string_view Key, const CacheValue& Value) CAtlTemporaryFile File; - spdlog::debug("PUT {}", Key); + ZEN_DEBUG("PUT {}", Key); HRESULT hRes = File.Create(m_RootDir.c_str()); @@ -205,11 +205,11 @@ FileCacheStore::Put(std::string_view Key, const CacheValue& Value) if (FAILED(hRes)) { - spdlog::warn("Failed to rename temp file for key '{}' - deleting temporary file", Key); + ZEN_WARN("Failed to rename temp file for key '{}' - deleting temporary file", Key); if (!DeleteFile(File.TempFileName())) { - spdlog::warn("Temp file for key '{}' could not be deleted - no value persisted", Key); + ZEN_WARN("Temp file for key '{}' could not be deleted - no value persisted", Key); } } } diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index b2f8d191c..9600c5f8a 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -4,6 +4,7 @@ #include <zencore/compactbinaryvalidation.h> #include <zencore/compress.h> #include <zencore/fmtutils.h> +#include <zencore/logging.h> #include <zencore/timer.h> #include <zenhttp/httpserver.h> @@ -14,7 +15,6 @@ #include "upstream/zen.h" #include "zenstore/cidstore.h" -#include <spdlog/spdlog.h> #include <algorithm> #include <atomic> #include <filesystem> @@ -31,18 +31,18 @@ HttpStructuredCacheService::HttpStructuredCacheService(::ZenCacheStore& InC zen::CasStore& InStore, zen::CidStore& InCidStore, std::unique_ptr<UpstreamCache> UpstreamCache) -: m_Log("cache", begin(spdlog::default_logger()->sinks()), end(spdlog::default_logger()->sinks())) +: m_Log(zen::logging::Get("cache")) , m_CacheStore(InCacheStore) , m_CasStore(InStore) , m_CidStore(InCidStore) , m_UpstreamCache(std::move(UpstreamCache)) { - m_Log.set_level(spdlog::level::debug); + // m_Log.set_level(spdlog::level::debug); } HttpStructuredCacheService::~HttpStructuredCacheService() { - spdlog::info("closing structured cache"); + ZEN_INFO("closing structured cache"); } const char* @@ -173,7 +173,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req { Value.Value = IoBuffer(); Success = false; - m_Log.warn("Upstream cache record '{}/{}' failed validation", Ref.BucketSegment, Ref.HashKey); + ZEN_WARN("Upstream cache record '{}/{}' failed validation", Ref.BucketSegment, Ref.HashKey); } } @@ -186,7 +186,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req if (!Success) { - m_Log.debug("MISS - '{}/{}'", Ref.BucketSegment, Ref.HashKey); + ZEN_DEBUG("MISS - '{}/{}'", Ref.BucketSegment, Ref.HashKey); return Request.WriteResponse(zen::HttpResponseCode::NotFound); } @@ -196,12 +196,12 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req Request.SetSuppressResponseBody(); } - m_Log.debug("HIT - '{}/{}' ({} bytes {}) ({})", - Ref.BucketSegment, - Ref.HashKey, - Value.Value.Size(), - Value.Value.GetContentType(), - InUpstreamCache ? "upstream" : "local"); + ZEN_DEBUG("HIT - '{}/{}' ({} bytes {}) ({})", + Ref.BucketSegment, + Ref.HashKey, + Value.Value.Size(), + Value.Value.GetContentType(), + InUpstreamCache ? "upstream" : "local"); return Request.WriteResponse(zen::HttpResponseCode::OK, Value.Value.GetContentType(), Value.Value); } @@ -239,11 +239,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req { // TODO: create a cache record and put value in CAS? m_CacheStore.Put(Ref.BucketSegment, Ref.HashKey, {.Value = Body}); - m_Log.debug("PUT (binary) - '{}/{}' ({} bytes, {})", - Ref.BucketSegment, - Ref.HashKey, - Body.Size(), - Body.GetContentType()); + ZEN_DEBUG("PUT (binary) - '{}/{}' ({} bytes, {})", Ref.BucketSegment, Ref.HashKey, Body.Size(), Body.GetContentType()); if (m_UpstreamCache) { @@ -260,7 +256,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req if (ValidationResult != CbValidateError::None) { - m_Log.warn("Payload for key '{}/{}' ({} bytes) failed validation", Ref.BucketSegment, Ref.HashKey, Body.Size()); + ZEN_WARN("Payload for key '{}/{}' ({} bytes) failed validation", Ref.BucketSegment, Ref.HashKey, Body.Size()); // TODO: add details in response, kText || kCbObject? return Request.WriteResponse(HttpResponseCode::BadRequest, @@ -299,13 +295,13 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req m_CacheStore.Put(Ref.BucketSegment, Ref.HashKey, CacheValue); - m_Log.debug("PUT (cache record) - '{}/{}' ({} bytes, {}, ({}/{} refs/missing))", - Ref.BucketSegment, - Ref.HashKey, - CacheValue.Value.Size(), - CacheValue.Value.GetContentType(), - References.size(), - MissingRefs.size()); + ZEN_DEBUG("PUT (cache record) - '{}/{}' ({} bytes, {}, ({}/{} refs/missing))", + Ref.BucketSegment, + Ref.HashKey, + CacheValue.Value.Size(), + CacheValue.Value.GetContentType(), + References.size(), + MissingRefs.size()); if (MissingRefs.empty()) { @@ -327,7 +323,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req for (const IoHash& MissingRef : MissingRefs) { Response.AddHash(MissingRef); - m_Log.debug("cache record '{}/{}' is missing reference '{}'", Ref.BucketSegment, Ref.HashKey, MissingRef); + ZEN_DEBUG("cache record '{}/{}' is missing reference '{}'", Ref.BucketSegment, Ref.HashKey, MissingRef); } Response.EndArray(); @@ -380,24 +376,24 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re } else { - m_Log.warn("got uncompressed upstream cache payload"); + ZEN_WARN("got uncompressed upstream cache payload"); } } } if (!Payload) { - m_Log.debug("MISS - '{}/{}/{}'", Ref.BucketSegment, Ref.HashKey, Ref.PayloadId); + ZEN_DEBUG("MISS - '{}/{}/{}'", Ref.BucketSegment, Ref.HashKey, Ref.PayloadId); return Request.WriteResponse(zen::HttpResponseCode::NotFound); } - m_Log.debug("HIT - '{}/{}/{}' ({} bytes, {}) ({})", - Ref.BucketSegment, - Ref.HashKey, - Ref.PayloadId, - Payload.Size(), - Payload.GetContentType(), - InUpstreamCache ? "upstream" : "local"); + ZEN_DEBUG("HIT - '{}/{}/{}' ({} bytes, {}) ({})", + Ref.BucketSegment, + Ref.HashKey, + Ref.PayloadId, + Payload.Size(), + Payload.GetContentType(), + InUpstreamCache ? "upstream" : "local"); if (Verb == kHead) { @@ -442,13 +438,13 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re m_CidStore.AddCompressedCid(Ref.PayloadId, ChunkHash); - m_Log.debug("PUT ({}) - '{}/{}/{}' ({} bytes, {})", - Result.New ? "NEW" : "OLD", - Ref.BucketSegment, - Ref.HashKey, - Ref.PayloadId, - Body.Size(), - Body.GetContentType()); + ZEN_DEBUG("PUT ({}) - '{}/{}/{}' ({} bytes, {})", + Result.New ? "NEW" : "OLD", + Ref.BucketSegment, + Ref.HashKey, + Ref.PayloadId, + Body.Size(), + Body.GetContentType()); if (Result.New) { diff --git a/zenserver/cache/structuredcache.h b/zenserver/cache/structuredcache.h index d4bb94c52..c8c959569 100644 --- a/zenserver/cache/structuredcache.h +++ b/zenserver/cache/structuredcache.h @@ -4,9 +4,12 @@ #include <zenhttp/httpserver.h> -#include <spdlog/spdlog.h> #include <memory> +namespace spdlog { +class logger; +} + class ZenCacheStore; namespace zen { @@ -71,7 +74,7 @@ private: void HandleCachePayloadRequest(zen::HttpServerRequest& Request, CacheRef& Ref); void HandleCacheBucketRequest(zen::HttpServerRequest& Request, std::string_view Bucket); - spdlog::logger m_Log; + spdlog::logger& m_Log; ZenCacheStore& m_CacheStore; zen::CasStore& m_CasStore; zen::CidStore& m_CidStore; diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index a07fccf98..018955e65 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -9,6 +9,7 @@ #include <zencore/filesystem.h> #include <zencore/fmtutils.h> #include <zencore/iobuffer.h> +#include <zencore/logging.h> #include <zencore/string.h> #include <zencore/thread.h> #include <zenstore/basicfile.h> @@ -16,7 +17,6 @@ #include <zenstore/caslog.h> #include <fmt/core.h> -#include <spdlog/spdlog.h> #include <concepts> #include <filesystem> #include <gsl/gsl-lite.hpp> @@ -31,7 +31,7 @@ using namespace fmt::literals; ZenCacheStore::ZenCacheStore(zen::CasStore& Cas, const std::filesystem::path& RootDir) : m_DiskLayer{Cas, RootDir} { - spdlog::info("initializing structured cache at '{}'", RootDir); + ZEN_INFO("initializing structured cache at '{}'", RootDir); zen::CreateDirectories(RootDir); } @@ -85,7 +85,7 @@ ZenCacheStore::Put(std::string_view InBucket, const zen::IoHash& HashKey, const bool ZenCacheStore::DropBucket(std::string_view Bucket) { - spdlog::info("dropping bucket '{}'", Bucket); + ZEN_INFO("dropping bucket '{}'", Bucket); // TODO: should ensure this is done atomically across all layers @@ -93,7 +93,7 @@ ZenCacheStore::DropBucket(std::string_view Bucket) const bool DiskDropped = m_DiskLayer.DropBucket(Bucket); const bool AnyDropped = MemDropped || DiskDropped; - spdlog::info("bucket '{}' was {}", Bucket, AnyDropped ? "dropped" : "not found"); + ZEN_INFO("bucket '{}' was {}", Bucket, AnyDropped ? "dropped" : "not found"); return AnyDropped; } |