diff options
| author | Stefan Boberg <[email protected]> | 2023-05-12 14:13:00 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-12 14:13:00 +0200 |
| commit | 9b74445504fb20401c174241b93c99bf765b43ce (patch) | |
| tree | 9e9ce2abe0f17c9ec327fb8fe3ecba4bea35f1c0 /src/zenserver/cache/structuredcachestore.cpp | |
| parent | better logging/exception when reading file in IoBuffer::Materialize fails (#294) (diff) | |
| download | zen-9b74445504fb20401c174241b93c99bf765b43ce.tar.xz zen-9b74445504fb20401c174241b93c99bf765b43ce.zip | |
implemented structured cache logging (#296)
may be used as audit trail to help analyse potential cache pollution/corruption
* also added common header with timestamp to all known log targets
* made `Oid::operator bool` explicit to avoid logging/text format mishaps
* made `HttpClient::operator bool` explicit
Diffstat (limited to 'src/zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | src/zenserver/cache/structuredcachestore.cpp | 75 |
1 files changed, 73 insertions, 2 deletions
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp index 79f57019d..a95ae4ca2 100644 --- a/src/zenserver/cache/structuredcachestore.cpp +++ b/src/zenserver/cache/structuredcachestore.cpp @@ -2497,12 +2497,16 @@ ZenCacheDiskLayer::GetValueDetails(const std::string_view BucketFilter, const st //////////////////////////// ZenCacheStore -static constexpr std::string_view UE4DDCNamespaceName = "ue4.ddc"; +ZEN_DEFINE_LOG_CATEGORY_STATIC(LogCacheActivity, "z$"); + +static constinit std::string_view UE4DDCNamespaceName = "ue4.ddc"; ZenCacheStore::ZenCacheStore(GcManager& Gc, const Configuration& Configuration) : m_Gc(Gc), m_Configuration(Configuration) { CreateDirectories(m_Configuration.BasePath); + ZEN_INFO("Initializing at '{}'", m_Configuration.BasePath); + DirectoryContent DirContent; GetDirectoryContent(m_Configuration.BasePath, DirectoryContent::IncludeDirsFlag, DirContent); @@ -2546,7 +2550,45 @@ ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const Io { if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store) { - return Store->Get(Bucket, HashKey, OutValue); + bool Result = Store->Get(Bucket, HashKey, OutValue); + + if (m_Configuration.EnableAccessLog) + { + if (Result) + { + if (OutValue.Value.GetContentType() == ZenContentType::kCbObject) + { + const IoHash ObjectHash = IoHash::HashBuffer(OutValue.Value.GetView()); + const size_t ObjectSize = OutValue.Value.GetSize(); + + ZEN_LOG_INFO(LogCacheActivity, + "GET HIT {}/{}/{} -> {} {} {}", + Namespace, + Bucket, + HashKey, + ObjectHash, + ObjectSize, + ToString(OutValue.Value.GetContentType())) + } + else + { + ZEN_LOG_INFO(LogCacheActivity, + "GET HIT {}/{}/{} -> {} {} {}", + Namespace, + Bucket, + HashKey, + OutValue.RawHash, + OutValue.RawSize, + ToString(OutValue.Value.GetContentType())); + } + } + else + { + ZEN_LOG_INFO(LogCacheActivity, "GET MISS {}/{}/{}", Namespace, Bucket, HashKey); + } + } + + return Result; } ZEN_WARN("request for unknown namespace '{}' in ZenCacheStore::Get, bucket '{}', key '{}'", Namespace, Bucket, HashKey.ToHexString()); @@ -2556,6 +2598,35 @@ ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const Io void ZenCacheStore::Put(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value) { + if (m_Configuration.EnableWriteLog) + { + if (Value.Value.GetContentType() == ZenContentType::kCbObject) + { + const IoHash ObjectHash = IoHash::HashBuffer(Value.Value.GetView()); + const size_t ObjectSize = Value.Value.GetSize(); + + ZEN_LOG_INFO(LogCacheActivity, + "PUT {}/{}/{} -> {} {} {}", + Namespace, + Bucket, + HashKey, + ObjectHash, + ObjectSize, + ToString(Value.Value.GetContentType())); + } + else + { + ZEN_LOG_INFO(LogCacheActivity, + "PUT {}/{}/{} -> {} {} {}", + Namespace, + Bucket, + HashKey, + Value.RawHash, + Value.RawSize, + ToString(Value.Value.GetContentType())); + } + } + if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store) { return Store->Put(Bucket, HashKey, Value); |